1 Reply Latest reply on Aug 30, 2007 3:00 PM by demetrio812

    RichFaces Gurus - Critique My Design/Code Please

    Casey Boyd Novice

      JBoss - 4.2.0
      Java - 1.6.0_02
      Seam 2.0.0 Beta 1

      I want a "New" button on a page to pop up a modalPanel. Within that panel, have the fields needed to create a new User. Hit a "Save" button on the panel, go through the validation on the Entity bean, if the validation fails, use the a4j:outputPanel to display the errors on the modalPanel that should stay open. If the validation succeeds, then create the user in the database and then close the modalPanel.



       <a4j:commandButton id="btnNewUser" value="New" oncomplete="javascript:Richfaces.showModalPanel('mplNewUser',{width:450, top:200})"></a4j:commandButton>


       <rich:modalPanel id="mplNewUser" minHeight="265" minWidth="475" height="265" width="475" zindex="2000">
       <f:facet name="header">
       <h:outputText value="Create New User" />
       <h:form id="frmNewUser">
       <h:panelGrid columns="2" cellpadding="3" width="255" columnClasses="leftlable, left" style="background-color:#F1F1F1">
       <h:outputText value="User555 Name" />
       <h:inputText required="true" value="#{usermanager.newUser.username}" id="iptNewusername" >
       <h:outputText value="Password" />
       <h:inputText required="true" value="#{usermanager.newUser.password}" id="iptNewpassword" >
       <a4j:outputPanel ajaxRendered="true">
       <h:messages id="errors" />
       <a4j:commandButton id="btnSaveUser" value="Save" actionListener="#{usermanager.saveUser}" oncomplete="javascript:Richfaces.hideModalPanel('mplNewUser')" reRender="errors" ></a4j:commandButton>
       <h:commandButton id="btnCancelNewUser" type="submit" value="Cancel" action="#{usermanager.cancelNewUser}"></h:commandButton>


      public class UserManager implements UserManagerInterface {
       private User user;
       private Session inetworkDatabase;
       Log log;
       FacesMessages facesMessages;
       private User newUser = new User();
       public void setNewUser(User newUser){ this.newUser = newUser; }
       public User getNewUser(){ return this.newUser; }
       public void saveUser(ActionEvent event){
       try {
       setNewUser(new User());
       }catch (Exception e){
       public void cancelNewUser(){
       setNewUser(new User());


      1) If the validation fails, the errors are displayed on the a4j:outputPanel, BUT the modalPanel closes anyway. I need that modalPanel to stay open if the validation fails.

      2) After going through the process once and a user is created, if the "New" button is clicked again, the modalPanel is pre-populated with the information of the user that was previously created. Basically, the code setNewUser(new User), is not re-setting the newUser object.

      I love RichFaces, but I am still a rookie...

      Any help would be very appreciated....