1

I have some weird issue with datatable selection (most likely i'm doing something wrong). Idea is simple - datatable with selection and a dialog to edit the records. The problem is that if i use <h:inputText> tag (or <p:inputText>) it appears to be blank, though the object in the backing bean (indicatorBean.indicator.code) contains data. Interestingly if i put <h:outputText> instead of input the data is shown.

here are contents of my body

<!-- language: xml -->
<h:body>
    <h:form id="form">
        <p:growl id="messages" showDetail="true"/>
        <p:dataTable id="indicatorsTable" var="ind" 
                     value="#{indicatorBean.indicators}"
                     selectionMode="single" 
                     selection="#{indicatorBean.indicator}" 
                     rowKey="#{ind.id}">
            <p:column headerText="Name" style="width:125px">
                #{ind.name}
            </p:column>
            <p:column headerText="Code" style="width:125px">
                #{ind.code}
            </p:column>
            <f:facet name="footer">
                <p:commandButton id="viewButton" value="View" 
                                 icon="ui-icon-search" update=":form:display" 
                                 oncomplete="indDialog.show()"/>
            </f:facet>
        </p:dataTable>


        <p:dialog id="dialog" header="Indicator Detail" 
                  widgetVar="indDialog" resizable="false"
                  width="400" showEffect="fade" hideEffect="fade">

            <h:panelGrid id="display" columns="2" cellpadding="4">
                     <h:outputText value="Code:"/>
                     <!-- PROBLEM IS HERE --> 
                     <h:inputText value="#{indicatorBean.indicator.code}"/>

                     <h:outputText value="Name:"/>
                     <h:outputText value="#{indicatorBean.indicator.name}"/>
            </h:panelGrid>
            
            <p:commandButton value="Save" onclick="indDialog.hide()"/>
            <p:commandButton value="Cancel" onclick="indDialog.hide()"/>
        </p:dialog>
    </h:form>

</h:body>

Backing bean is nothing other that accessors.

Another thing i spotted is if i replace el expression in <h:inputtext> with a static text (like <h:inputText value="static text"/>), it is shown. Here are some pictures:

Dialog with inputtext

inputtext

Dialog with outputtext

outputtext

Dialog with static text

static text

primefaces 3.4

Community
  • 1
  • 1
demoth
  • 79
  • 1
  • 6

1 Answers1

1

The problem as you seem to have already figured out is that you are placing the dialog itself inside of a form. This is an issue because of the way the jQuery dialog control works, which is the client side foundation of the Primefaces dialog. Essentially it will move DOM elements associated with the dialog elsewhere, possibly outside of the form that you intend to enclose it.

This problem can be easily solved by putting the dialog outside of the form, and putting a form inside of the dialog body instead.

<p:dialog id="dialogId" ...>
  <h:form id="dlgForm">
     ....
  </h:form>
</p:dialog>

In this way when jQuery UI moves the dialog control elsewhere in the DOM, the contents of that DOM, including the form come with it.

maple_shaft
  • 10,435
  • 6
  • 46
  • 74