1 Reply Latest reply on Sep 9, 2008 10:57 AM by Matthias Metzger

    modalPanel: Initialization problem - Backing Bean vs. UIComp

    Peter Henningsen Newbie

      Hi,

      last week we have encountered a strange Problem with Richfaces 3.1.3GA on JBoss 4.2.2.GA:

      We are maintaining personnel entries. The existing database rows are presented on a datatable. The user may click an Edit-icon to select one. A modalPanel opens and presents the person's fields for input. Some fields are tagged as mandatory. This works fine, as long as no validation error occurs.

      But say I enter a person1 without a name (field is blank) and hit "save". Validation spots the problem and renders the Errormessage in the modalPanel.
      Next, I cancel the modal panel. The panel disappears, the person1 is unchanged.
      Now I select person2 from the datatable and the error occurs:

      Fields, that held data for person1 still show the old data. Fields that were empty for person1 are filled with data from person2 (if person2 has data)!
      Debugging seems to show, that the backing bean is updated correctly with data from person2. But the panel is not.
      If I close the modalPanel via "Save" or "Cancel" without validation error, all is fine.

      Datatable:

      <rich:dataTable id="personOverviewMainTable" value="#{SessionBean.personEntries}" var="entry">
      
       <rich:column headerClass="overviewHeaderNname">
       <f:facet name="header"><h:outputText value="#{txt.person_overview_header_nname}" /></f:facet>
       <h:outputText value="#{entry.details.nachname}">
       </h:outputText>
       </rich:column>
      
       <rich:column headerClass="overviewHeaderVname">
       <f:facet name="header"><h:outputText value="#{txt.person_overview_header_vorname}" /></f:facet>
       <h:outputText value="#{entry.details.vorname}">
       </h:outputText>
       </rich:column>
      
       <rich:column headerClass="overviewHeaderUserid">
       <f:facet name="header"><h:outputText value="#{txt.person_overview_header_userid}" /></f:facet>
       <h:outputText value="#{entry.details.userid}" />
       </rich:column>
      
       <rich:column headerClass="overviewHeaderAdmin">
       <f:facet name="header"><h:outputText value="#{txt.person_overview_header_admin}" /></f:facet>
       <h:outputText value="#{entry.details.administrator}" />
       </rich:column>
      
       <rich:column headerClass="overviewHeaderIcons">
       <f:facet name="header">
       <a4j:commandButton id="newBut" image="../img/new16.png" title="#{txt.globallab_new}" actionListener="#{PersonDetailsForm.newEntry}" oncomplete="Richfaces.showModalPanel('personDetailsP')" reRender="PersonDetailsForm" />
       </f:facet>
      
       <a4j:commandButton id="editBut" image="../img/edit16.png" title="#{txt.globallab_edit}" actionListener="#{PersonDetailsForm.editEntry}" oncomplete="Richfaces.showModalPanel('personDetailsP')" reRender="PersonDetailsForm">
       <f:param name="workentry" value="#{entry}" />
       </a4j:commandButton>
      
       </rich:column>
       </rich:dataTable>



      ModalPanel:


      <rich:modalPanel id="personDetailsP" width="290" height="350"
       styleClass="entryDetails">
       <f:facet name="header">
       <h:outputText value="#{txt.personDetails_title}" />
       </f:facet>
       <a4j:form id="PersonDetailsForm" binding="#{PersonDetailsForm.form}" bypassUpdates="false">
       <rich:messages id="messages" errorClass="error" showDetail="true" showSummary="false" tooltip="false"/>
       <a4j:status layout="block" startStyleClass="statusBox">
       <f:facet name="start">
       <h:graphicImage value="../img/gears.gif" />
       </f:facet>
       </a4j:status>
       <h:panelGrid columns="2">
      
       <h:outputText value="#{txt.personDetails_lab_nname}" />
       <h:inputText id="nname" value="#{PersonDetailsForm.nachname}" required="true" requiredMessage="#{txt.personDetails_lab_nname_err}" maxlength="40"></h:inputText>
      
       <h:outputText value="#{txt.personDetails_lab_vname}" />
       <h:inputText id="vname" value="#{PersonDetailsForm.vorname}" required="true" requiredMessage="#{txt.personDetails_lab_vname_err}" maxlength="40"></h:inputText>
      
       <h:outputText value="#{txt.personDetails_lab_uid}" />
       <h:inputText id="uid" value="#{PersonDetailsForm.userid}" required="true" requiredMessage="#{txt.personDetails_lab_uid_err}" maxlength="20"></h:inputText>
      
       <h:outputText value="#{txt.personDetails_lab_personr}" />
       <h:inputText id="personr" value="#{PersonDetailsForm.personalnummer}" required="true" requiredMessage="#{txt.personDetails_lab_pnr_err}" maxlength="6" size="6"></h:inputText>
      
       <h:outputText value="#{txt.personDetails_lab_admin}" />
       <h:selectBooleanCheckbox id="admin" value="#{PersonDetailsForm.adminflag}"/>
      
       <h:outputText value="#{txt.personDetails_lab_language}" />
       <h:inputText id="lang" value="#{PersonDetailsForm.language}" maxlength="3" size="3"></h:inputText>
      
       <h:outputText value="#{txt.personDetails_lab_stdsort}" />
       <h:inputText id="stdsort" value="#{PersonDetailsForm.stdsort}" maxlength="2" size="2"></h:inputText>
      
       <h:outputText value="#{txt.personDetails_lab_kostenst}" />
       <h:inputText id="kst" value="#{PersonDetailsForm.kostenstelle}" required="true" requiredMessage="#{txt.personDetails_lab_kostenst_err}" maxlength="10" size="10"></h:inputText>
      
       <h:outputText value="#{txt.personDetails_lab_pwd}" />
       <h:inputSecret id="pwd_upd" value="#{PersonDetailsForm.password}" rendered="#{PersonDetailsForm.pkey!=null}" required="false" maxlength="15" size="15"></h:inputSecret>
       <h:inputSecret id="pwd_ins" value="#{PersonDetailsForm.password}" rendered="#{PersonDetailsForm.pkey==null}" required="true" requiredMessage="#{txt.personDetails_lab_pwd_err}" maxlength="15" size="15"></h:inputSecret>
      
       </h:panelGrid>
      
       <h:panelGroup>
       <a4j:commandButton id="saveButton" value="#{txt.globallab_save}" disabled="#{PersonDetailsForm.saveDisabled}" actionListener="#{PersonDetailsForm.saveEntry}" oncomplete="#{PersonDetailsForm.onComplete}" reRender="personOverviewMainTable" />
       <a4j:commandButton value="#{txt.globallab_cancel}" onclick="Richfaces.hideModalPanel('personDetailsP')" />
       </h:panelGroup>
       </a4j:form>
      
      
       </rich:modalPanel>


      Backing bean for Panel (extract):

       public synchronized void setOnComplete(String onComplete) {
       this.onComplete = onComplete;
       }
      
      
       public void editEntry(ActionEvent actionEvent) {
       fillFromWorkEntry(((PersonWorkEntry) FacesUtil.getComponentParameter(actionEvent.getComponent(), "workentry")).getDetails());
       }
      
       public void newEntry(ActionEvent actionEvent) {
       fillFromWorkEntry(null);
       }
      
      
       public void saveEntry(ActionEvent actionEvent) {
       // Validierungen:
       // alle Pflichtfelder
       final Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale();
      
       if (pkey== null || pkey.equals(0L)) {
      
       // check userid unique
      
      
      
       }
       if (!FacesContext.getCurrentInstance().getMessages().hasNext()) {
       // Save new/updated entry
       Person aPerson = fillWorkEntry();
      
       //System.out.println(">>> Person Kostenart: " + aPerson.getKostenart());
      
       sessionBean.getDaoFacade().saveEntity(aPerson);
       if (pkey == null || pkey.equals(0L)) {
       pkey = aPerson.getPkey();
       }
      
       sessionBean.setPersonEntries(null);
       onComplete=FacesUtil.getHideModalDlgStatement("personDetailsP");
       }
       }
      
       public boolean validate() {
       // any validations here?
       return true;
       }
      
      
       /**
       * @param workEntry
       */
       private void fillFromWorkEntry(Person workEntry) {
       if (workEntry != null) {
       pkey = workEntry.getPkey();
       setNachname(workEntry.getNachname());
       setOnComplete(null);
       setUserid(workEntry.getUserid());
       setVorname(workEntry.getVorname());
      ...
       } else {
       pkey = null;
       setOnComplete(null);
       setUserid(null);
       setVorname(null);
      ...
       }
      
       }
      
      
       private Person fillWorkEntry() {
      
       Person aPerson = new Person();
       aPerson.setNachname(getNachname());
       ...
      
       aPerson.setPkey(getPkey());
      
       return aPerson;
       }
      
      
       public String getOnComplete() {
       final String result = onComplete;
       onComplete = "";
       return result;
       }