2010-08-18 72 views
0

我有使用primeface的嚮導組件和核心selectOneRadio的問題。我的註冊頁面看起來像這樣Primefaces嚮導和selectOneRadio

<ui:define name="content"> 
      <f:view>    
      <h:form id="signUpForm"> 

       <p:wizard widgetVar="wiz" flowListener="#{SignUpBean.onFlowProcess}"> 
        <p:tab id="personalTab" title=""> 
         <p:panel header="Personal"> 
          <h:messages/> 
          <h:panelGrid id="panel1" columns="2"> 
           <h:outputLabel for="firstName" value="First Name"/> 
           <h:inputText id="firstName" value="#{SignUpBean.firstName}" required="true"/> 
           <h:outputLabel for="lastName" value="Last Name"/> 
           <h:inputText id="lastName" value="#{SignUpBean.lastName}" required="true"/> 
           <h:outputLabel for="email" value="Email"/> 
           <h:inputText id="email" value="#{SignUpBean.email}" required="true"> 
            <f:validator validatorId="emailValidator"/> 
           </h:inputText> 
          </h:panelGrid> 
         </p:panel> 
        </p:tab> 
        <p:tab id="passwordTab" title=""> 
         <p:panel header="Password"> 
          <h:messages/> 
          <h:panelGrid id="panel2" columns="2"> 
            <h:outputLabel for="password" value="Password"/> 
            <h:inputSecret id="password" value="#{SignUpBean.password}" required="true"/> 
            <h:outputLabel for="retypePass" value="Retype Password"/> 
            <h:inputSecret id="retypePass" value="#{SignUpBean.retypePassword}" required="true"/> 
          </h:panelGrid> 
         </p:panel> 
        </p:tab> 
        <p:tab id="groupTab" title=""> 
         <p:panel header="Group"> 
          <h:messages/> 
          <h:panelGrid id="panel3" columns="2"> 
           <h:outputLabel for="radioGroup" value=""/> 
           <h:selectOneRadio id="radioGroup" value="#{SignUpBean.join}"> 
            <f:selectItem itemValue="true" itemLabel="Join existing group"/> 
            <f:selectItem itemValue="false" itemLabel="Create new group"/> 
           </h:selectOneRadio> 
           Group Name 
           <h:inputText id="group" value="#{SignUpBean.group}" required="true"/> 
           Group Password 
           <h:inputSecret id="groupPass" value="#{SignUpBean.groupPass}" required="true"/> 
          </h:panelGrid> 
         </p:panel> 
        </p:tab> 
        <p:tab id="confirmTab" title=""> 
         <p:panel header="Confirm"> 
          <h:messages/> 
          <p:growl id="signUpGrowl" sticky="false" life="1000" showDetail="true" /> 
          <h:panelGrid id="panel4" columns="4" cellpadding="5"> 
           Firstname: 
           <h:outputText value="#{SignUpBean.firstName}"/> 
           Lastname: 
           <h:outputText value="#{SignUpBean.lastName}"/> 
           Email: 
           <h:outputText value="#{SignUpBean.email}"/> 
           Groupname: 
           <h:outputText value="#{SignUpBean.group}"/> 
            <h:panelGroup style="display:block; text-align:center"> 
             <p:commandButton value="Submit" action="#{SignUpBean.signUp}" update="signUpGrowl"/> 
            </h:panelGroup> 
          </h:panelGrid> 
         </p:panel> 
        </p:tab> 
       </p:wizard> 
      </h:form> 
      </f:view> 
     </ui:define> 

而且signUpBean這樣的:

@ManagedBean(name="SignUpBean") 
@SessionScoped 
public class SignUpBean { 

    private String groupName, groupPass, firstName, lastName, 
      email, password, retypePassword; 
    private boolean join; 
    private boolean skip; 
    @EJB 
    private MessageBeanRemote messageBean2; 

    /** Creates a new instance of SignUpBean */ 
    public SignUpBean() { 
     this.skip = false; 
     this.join = true; 
    } 

    /** 
    * Signs up a user with all the data given on the signUp.jsf page. 
    * If everything is ok then a confirmation email is generated and send 
    * to the new user. 
    * @return Either signUpSucces or signUpFailure 
    */ 
    public void signUp() { 
     Session session = HibernateUtil.getSessionFactory().getCurrentSession(); 
     Transaction tx = session.beginTransaction(); 
     // Boolean to decide if the data should be commited or not. 
     boolean commitOK = true; 

     UserHelper uh = new UserHelper(); 
     BasicUser user = uh.getByEmail(this.email); 
     GroupHelper gh = new GroupHelper(); 
     Group group = gh.getByName(this.groupName); 

     // If email does not already exist 
     if(user == null) { 
      user = new BasicUser(); 
      user.setEmail(this.email); 
      user.setFirstName(this.firstName); 
      user.setLastName(this.lastName); 
      if(this.password.equals(this.retypePassword)) { 
       user.setPassword(password); 
      } 
      else { 
       commitOK = false; 
       FacesMessage fm = new FacesMessage("Passwords does not match"); 
       FacesContext.getCurrentInstance().addMessage(null, fm); 
      } 
     } 
     else { 
      commitOK = false; 
      FacesMessage fm = new FacesMessage("Email does already exist"); 
      FacesContext.getCurrentInstance().addMessage(null, fm); 
     } 

     // If it's a joiner to a group 
     if(this.join) { 
      // Is it the right groupPassword and groupName 
      if(group != null && group.getGroupPassword().equals(this.groupPass)) { 
       user.setGroup(group); 
      } 
      else { 
       commitOK = false; 
       FacesMessage fm = new FacesMessage("Wrong group name or password"); 
       FacesContext.getCurrentInstance().addMessage(null, fm); 
      } 
     } 
     else { 
      if(group == null) { 
       group = new Group(); 
       group.setGroupName(this.groupName); 
       group.setGroupPassword(this.groupPass); 
       user.setGroup(group); 
      } 
      else { 
       commitOK = false; 
       FacesMessage fm = new FacesMessage("Group does already exist"); 
       FacesContext.getCurrentInstance().addMessage(null, fm); 
      } 
     } 

     //--- IF EVERYTHING OK THEN UPDATE THE DB ---// 
     if(commitOK) { 

      session.save(group); 
      session.save(user); 
      tx.commit(); 

      session = HibernateUtil.getSessionFactory().getCurrentSession(); 
      tx = session.beginTransaction(); 

      BasicUser newUser = uh.getByEmail(email); 
      int id = newUser.getId(); 

      MobileUser mobile = new MobileUser(); 
      mobile.setId(id); 
      mobile.setUseWhen("Lost"); 

      StatUser stats = new StatUser(); 
      stats.setId(id); 
      stats.setRating(""); 

      DateUser dates = new DateUser(); 
      dates.setId(id); 
      Calendar calendar = Calendar.getInstance(); 
      Date date = calendar.getTime(); 
      dates.setMemberSince(date); 
      dates.setLastLogin(date); 

      session.save(stats); 
      session.save(mobile); 
      session.save(dates); 
      tx.commit(); 

      //----- SEND CONFIRMATION EMAIL ----------// 
      BasicUser emailUser = uh.getByEmail(email); 
      MailGenerator mailGenerator = new ConfirmationMailGenerator(emailUser); 
      try { 
       StringWriter plain = mailGenerator.generatePlain(); 
       StringWriter html = mailGenerator.generateHTML(); 
       messageBean2.sendMixedMail(email, "WMC: Account Info", plain.toString(), 
         html.toString()); 
      } 
      catch (Exception ex) { 
       Logger.getLogger(SignUpBean.class.getName()).log(Level.SEVERE, null, ex); 
      } 

      FacesMessage msg = new FacesMessage("Successful", "Welcome :" + this.getFirstName()); 
      FacesContext.getCurrentInstance().addMessage(null, msg); 
     } 

     //---- DO NOTHING ----// 

    } 

    public String onFlowProcess(FlowEvent event) { 
     if (skip) { 
      skip = false; //reset in case user goes back 
      return "confirm"; 
     } else { 
      return event.getNewStep(); 
     } 
    } 
... getters and setters 
} 

我知道這是一個壞的註冊方法,它會在以後進行修改。當我到了最後一個選項卡並提交我得到這個錯誤:

alt text

當我調試我看到加入變量或者是真還是假不爲空。它在抱怨什麼?

+0

它甚至沒有進入方法註冊() – AnAmuser 2010-08-18 17:13:05

回答

0

我加入了

<h:inputHidden value="#{SignUpBean.join}"/> 

內確認標籤解決了這個問題。這工作:)

+1

這應該是PrimeFaces中的一個錯誤。 請在此處打開JIRA問題: http://code.google.com/p/primefaces/issues/list – Dejell 2010-08-18 18:41:09

2

更改變量聲明:

private Boolean join; 

,而不是

private boolean join; 

確保你有適當的getter和setter!

+0

這給出了相同的錯誤。 – AnAmuser 2010-08-18 17:26:25

+0

我編輯了我的問題。你必須將它改爲String。我錯誤地寫了布爾。 – Dejell 2010-08-18 17:39:44

+0

'布爾'是好的。您只需要相應地更新getter/setter(取回布爾值而不是布爾值)。不要使用'String',你不能在bean代碼的布爾條件中很好地使用它。 – BalusC 2010-08-18 18:20:59