2012-01-24 89 views
1

我正试图实现PrimeFaces website上显示的一些功能。我的p:dataTable标题中的p:commandButton显示一个包含一系列标签/文本输出的p:对话框。作为exepected以下作品中的例子:h:inputText呈现空白

数据表:

<h:form id="form"> 
     <p:dataTable id="table" 
        value="#{locationStockList.getDataModel(cc.attrs.collection)}"  
        var="item" 
        selection="#{locationStockList.selected}" 
        selectionMode="single"> 

      <p:ajax event="rowSelect" listener="#{locationStockList.onRowSelect}"/> 

      <f:facet name="header"> 
       <p:commandButton id="btnView" value="View" 
           update=":form:panel" 
           oncomplete="dialog.show()"/> 
      </f:facet> 
      <p:column> 
       <f:facet name="header">Stock Item</f:facet> 
       <h:outputText value="#{item.stockItem.name}"/> 
      </p:column> 
      <p:column> 
       <f:facet name="header">Location</f:facet> 
       <h:outputText value="#{item.location.name}"/> 
      </p:column> 
      <p:column> 
       <f:facet name="header">Quantity</f:facet> 
       <h:outputText value="#{item.quantity}"/> 
      </p:column> 
      <p:column> 
       <f:facet name="header">Price</f:facet> 
       <h:outputText value="#{item.price}"/> 
      </p:column> 
     </p:dataTable> 

对话框

 <p:dialog id="dialog" widgetVar="dialog" header="Location Stock Form" width="700" 
        resizable="false" draggable="false" closable="false" modal="true"> 
      <h:panelGrid id="panel" columns="3"> 
       <h:outputLabel id="lblStockItem" for="stockItem" value="Stock Item"/> 
       <h:outputText id="stockItem" value="#{locationStockList.selected.stockItem.name}"/> 
       <p:message id="msgStockItem" for="stockItem"/> 

       <h:outputLabel id="lblLocation" for="location" value="Location"/> 
       <h:outputText id="location" value="#{locationStockList.selected.location.name}"/> 
       <p:message id="msgLocation" for="location"/> 

       <h:outputLabel id="lblPrice" for="price" value="Price"/> 
       <h:outputText id="price" value="#{locationStockList.selected.price}"/> 
       <p:message id="msgPrice" for="price"/> 

       <h:outputLabel id="lblQuantity" for="quantity" value="Quantity"/> 
       <h:outputText id="quantity" value="#{locationStockList.selected.quantity}"/> 
       <p:message id="msgQuantity" for="quantity"/> 
      </h:panelGrid> 

      <f:facet name="footer"> 
       <p:commandButton value="Save" /> 
       <p:commandButton value="Cancel" oncomplete="dialog.hide()" /> 
      </f:facet> 
     </p:dialog> 
    </h:form> 

我遇到的问题是,当我尝试实现同样的对话框编辑/更新面板。然后将p:对话框中的h:outputText更改为h:inputText,将文本框呈现为空白。我发现这个问题的唯一解决方案是将h:inputText设置为disabled =“true”或readonly =“true”,其中值可见但不可编辑。具体而言:

这些都显示了值,但不允许modificaion:

<h:outputText id="price" value="#{locationStockList.selected.price}"/> 
<h:inputText id="price" value="#{locationStockList.selected.price}" readonly="true"/> 

虽然这使得空:

<h:inputText id="price" value="#{locationStockList.selected.price}"/> 

回答

2

如表和对话都是里面的相同窗体,当您单击表中的按钮时,您实际上也在提交对话框的内容。你看到的实际上是对话框的提交值。当设置了readonlydisabled时,输入值将不会被提交,因此不会覆盖模型值。

您需要要么是在更具体的按钮应该怎样处理(即只@this

<p:commandButton value="View" process="@this" update=":form:dialog" oncomplete="dialog.show()"/> 

分割表和对话框超过2种形式

<h:form> 
    <p:dataTable> 
     ... 
    </p:dataTable> 
</h:form> 
<p:dialog> 
    <h:form> 
     ... 
    </h:form> 
</p:dialog>