dataTable select issue

UI Components for JSF
Post Reply
Jeyaraman G
Posts: 6
Joined: 02 Aug 2010, 06:09

02 Aug 2010, 09:42

Hi

I am trying a CRUD with dataTable to list the rows and a dialog to display the details. On clicking a row, a dialog is popped up with input fields to add/modify the data. Some of the input fields in the dialog (<h:inputText>) contain required=true and <f:validateLength>.

What works...

1. Clicking the row in the dataTable pops the dialog with the selected row's values in the input fields.
2. Changing the value in the input fields and saving them using hibernate works fine.
3. Adding a new row to the table using the dialog works fine.

What doesn't work...

1. If there is a validation error in any of the fields (required/length), the error messages are displayed in <p:messages>. After this, clicking on any other row in the dataTable pops up the dialog with the wrong values in the input fields. The input fields show the correct value (from the currently selected row) for only those fields where the validation had failed. The other fields show the value from previously selected row.

Meaning, if I select row 1, if the validation fails on field 1, if I exit the dialog and select row 2 from the dataTable, the dialog now shows the value of field 1 properly from row 2 but the other fields in the dialog show the values from row 1.

2. If I add new rows using the dialog, updating the dataTable (using update="<dataTable id>" does not show the newly added record at the bottom of the dataTable even when there are fewer rows than "rows" attribute. If I close the page and start again, the dataTable shows the newly added row. How do I make the dataTable to display the newly added row?

Code related to dataTable

Code: Select all

    <p:panel header="LCL Maintenance">
        <p:messages/>
        <p:dataTable id="idTblLCL"
                     widgetVar="wvTblLCL" var="lcl"
                     value="#{lclView.lcls}"
                     dynamic="true"
                     emptyMessage="There are no records"
                     errorMessage="There was an error while loading data"
                     loadingMessage="Loading data. Please wait.."
                     paginator="true"
                     paginatorPosition="bottom"
                     rows="6"
                     selection="#{lclView.selectedLCL}"
                     selectionMode="single"
                     update="frmLCLDetails"

                     onselectComplete="wvLCLDetails.show()"
                     >
            <p:column sortBy="#{lcl.id}">
                <f:facet name="header">
                    <h:outputText value="Id"/>
                </f:facet>
                <h:outputText value="#{lcl.id}"/>
            </p:column>

            <p:column sortBy="#{lcl.lclname}" filterBy="#{lcl.lclname}">
                <f:facet name="header">
                    <h:outputText value="LCL name"/>
                </f:facet>
                <h:outputText value="#{lcl.lclname}"/>
            </p:column>
            <p:column sortBy="#{lcl.centreName}" filterBy="#{lcl.centreName}">
                <f:facet name="header">
                    <h:outputText value="Centre name"/>
                </f:facet>
                <h:outputText value="#{lcl.centreName}"/>
            </p:column>

        </p:dataTable>

    </p:panel>
    <p:panel id="idPnlControlPanel">
        <p:commandButton actionListener="#{lclView.createNew}"
                         update="frmLCLDetails"
                         oncomplete="wvLCLDetails.show()"
                         value="New"
                         >
        </p:commandButton>

        <p:menuButton value="Export Data"  >
            <p:menuitem value="xls" ajax="false">
                <p:dataExporter fileName="lcl" target="idTblLCL" type="xls"/>
            </p:menuitem>
            <p:menuitem value="pdf" ajax="false">
                <p:dataExporter fileName="lcl" target="idTblLCL" type="pdf"/>
            </p:menuitem>
            <p:menuitem value="csv" ajax="false">
                <p:dataExporter fileName="lcl" target="idTblLCL" type="csv"/>
            </p:menuitem>
            <p:menuitem value="xml" ajax="false">
                <p:dataExporter fileName="lcl" target="idTblLCL" type="xml"/>
            </p:menuitem>
        </p:menuButton>
    </p:panel>

Code related to the dialog

Code: Select all

    <p:dialog id="idLCLDetails"
              widgetVar="wvLCLDetails"
              modal="false"
              draggable="true"
              resizable="true"
              header="Details"
              width="700"
              height="400"
              position="center"
              showEffect="slide"
              hideEffect="slide"
              closeListener="#{lclView.handleClose}"
              >
        <p:growl id="idGrowlMessage"/>
            <p:tooltip showEffect="slide"
                       showEvent="focus"
                       hideEvent="blur"
                       position="top" />

        <h:form id="frmLCLDetails"
                prependId="false"
                style="font-family: sans-serif;font-size: 10pt"
                >

            <p:messages id="idMessage"/>

            <p:focus/>
            <h:panelGrid columns="2">
                <h:outputText value="Id" rendered="#{lclView.selectedLCL.id != null}" />
                <h:outputText value="#{lclView.selectedLCL.id}" rendered="#{lclView.selectedLCL.id != null}"/>

                <h:outputText value="#{msg.Name}" />
                <h:inputText id="txtLclName" value="#{lclView.selectedLCL.lclname}"
                             size="45"
                             required="true"
                             requiredMessage="LCL name is Mandatory field"
                             title="Enter LCL name"
                             >
                    <f:validateLength minimum="2" maximum="20" />
                </h:inputText>

                <h:outputText value="Centre name"/>
                <h:inputText id="idCentreName"
                             value="#{lclView.selectedLCL.centreName}"
                             required="true"
                             requiredMessage="Center name should be filled"
                             size="45"
                             title="Enter Center name">
                </h:inputText>

                <h:outputText value="#{msg.Address1}"/>
                <h:inputText id="idAddress1" value="#{lclView.selectedLCL.address1}"
                             required="true"
                             requiredMessage="Address1 should be filled"
                             size="45"
                             title="Enter address1"/>

                <h:outputText value="Address 2"/>
                <h:inputText id="idAddress2" value="#{lclView.selectedLCL.address2}"
                             required="true"
                             validator="#{lclView.checkMandatory}"
                             size="45"
                             title="Enter address2"/>

                <h:outputText value="Address3"/>
                <h:inputText id="txtAddress3"
                             maxlength="45"
                             value="#{lclView.selectedLCL.address3}"/>

                <h:outputText value="State"/>
                <h:inputText value="#{lclView.selectedLCL.state}"/>

                <h:outputText value="City"/>
                <h:inputText value="#{lclView.selectedLCL.city}"/>

                <h:outputText value="PIN"/>
                <h:inputText value="#{lclView.selectedLCL.pin}"
                             required="true"
                             requiredMessage="PIN code should be filled"
                             maxlength="6">
                    <f:validateLength  minimum="6" maximum="6"/>
                </h:inputText>
                <h:outputText value="Phone"/>
                <h:inputText value="#{lclView.selectedLCL.phone}"
                             >
                    <f:validateLength minimum="0" maximum="10"/>
                </h:inputText>
                <h:outputText value="Cell number"/>
                <h:inputText id="cellNumber" value="#{lclView.selectedLCL.cellPhone}"
                             required="true"
                             requiredMessage="Please enter the cell number">
                    <f:validateLength  maximum="10" minimum="10"
                                       />
                </h:inputText>
            </h:panelGrid>

            <!-- control panel -->
            <h:panelGrid columns="5" border="0" >
                <p:commandButton actionListener="#{lclView.save}"
                                 value="Save"
                                 update="frmLCLDetails,idCenterForm"
                                 title="Click to save the current record"
                                 >
                </p:commandButton>
                <p:commandButton value="Delete" actionListener="#{lclView.delete}"
                                 oncomplete="wvLCLDetails.hide()"
                                 update="idGrowlMessage"
                                 title="Click to delete the current record"
                                 immediate="true"/>
                <p:commandButton value="Exit"
                                 actionListener="#{lclView.handleClose}"
                                 immediate="true"
                                 update="@none"
                                 oncomplete="wvLCLDetails.hide()" />
                <p:ajaxStatus>
                    <f:facet name="start">
                        <h:graphicImage url="img/ajaxloading.gif"/>
                    </f:facet>
                    <f:facet name="complete">
                        <h:outputText value=""/>
                    </f:facet>
                </p:ajaxStatus>
            </h:panelGrid>

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

Thanks in advance.

Regards
PrimeFaces 2.1
Mojarra 2.0.2
Tomcat 6.0.20

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 30 guests