views:

263

answers:

2

I have a problem with using primeface's wizard component and the core selectOneRadio. My signup page looks like this

<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>

And the signUpBean like this:

@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
}

I know it is a bad signup method and it will be changed later. When i reach the last tab and submit I get this error:

alt text

When I debug I see that the join variable is either true or false not null. What is it complaining about?

+1  A: 

Change the variable declaration to:

private Boolean join;

instead of

private boolean join;

Make sure that you have appropriate getter and setter!

Odelya
This gives the same error.
AnAmuser
I edited my question . you have to change it to String. By mistake I wrote Boolean.
Odelya
`Boolean` is fine. You only have yet to update the getter/setter accordingly (take and return `Boolean` instead of `boolean`). Don't use `String`, you can't use it nicely in boolean conditions in bean code.
BalusC
@BalusC - thanks - since he is not a newbe I don't think that he does not have getter and setter's for EL expressions
Odelya
Join is set to null when I push the Submit button. Doesn't matter what type the variable is
AnAmuser
@Odelya: truly he do have getter/setter :) I didn't mean that. You suggested to only change `boolean` **property** to `Boolean`. Due to autoboxing, the original getter/setter don't give compile error after change. This is very easily overlooked. The error message basically tells that the setter doesn't accept `null`. This can only happen when the setter still accepts `boolean` instead of `Boolean`.
BalusC
@BalusC you are right. BTW, Shall I tag this question only as JSF-2.0 question? I saw in many questions that many people are using JSf and JSF2-0 tags although they are using JSF2!
Odelya
@Odelya: No `jsf` is the general tag. Both are fine. IMO `jsf-2.0` doesn't belong there because this problem is not specific to JSF 2.0. It would occur as good in JSF 1.x.
BalusC
A: 

I solved the problem by adding a

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

Inside the confirmation tab. This works:)

AnAmuser
This should be a bug in PrimeFaces.Please open a JIRA issue here:http://code.google.com/p/primefaces/issues/list
Odelya