Primeface Wizard with Glassfish v3

UI Components for JSF
Post Reply
MichaelW86
Posts: 5
Joined: 08 Feb 2010, 18:49

08 Feb 2010, 19:23

1. I use the Primefaces Wizard for a JaveEE Web App. When i use a Tomcat 6.0.20 everything works fine. I only noticed that when the "speed" Attribut of <p:wizard> is low and you klick very fast in series on the green "next" button the wizard sometimes gets in a dialog where you should have the green "next" button but its missing - then you have to refresh the view.

2 But my real Problem is using the Wizard with Glassfish v3. Its not working with Glassfish v3. I only see the first dialog of the wizard. When i click on the green "next" button nothing happens. There are no error messages. When the same Wizard works in Tomcat with the same Managed Bean so what could be the Problem that the Wizard is not working in a Glassfish Container? I'm very new to JavaEE and JSF and things like that so maybe i've done something wrong ...

Here is the Wizard i'm using:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<ui:composition
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:p="http://primefaces.prime.com.tr/ui"
    template="/templates/masterlayout.xhtml"
    xmlns:f="http://java.sun.com/jsf/core" >

    <ui:define name="content">

        <h:form style="margin-top: 31px;">


            <p:wizard effect="toggle" id="wizard" widgetVar="wizard" height="400" width="600" speed="550">

                <p:tab title="Registration Wizard">
                    <p:panel header="#{msgs.Registration}">

                        <!-- Output Message -->
                        <h:messages errorClass="error" styleClass="error"
                                    style="color: red; font-style: italic;" />
                        <h:outputText id="validationError"
                                      value="#{UserWizard.validateError}"
                                      style="color: red; font-style: italic;"/>

                        <h:panelGrid columns="2" columnClasses="label, value" styleClass="grid">

                            <h:outputText value="#{msgs.FirstName}: *" />
                            <h:inputText value="#{UserWizard.user.name.firstName}" 
                                         required="true" label="Firstname" requiredMessage="#{vmsgs.RequireMoreInput}"
                                         valueChangeListener="#{UserWizard.validateName}" immediate="true">
                                <f:ajax event="blur" render="validationError"/>
                            </h:inputText>

                            <h:outputText value="#{msgs.LastName}: *" />
                            <h:inputText value="#{UserWizard.user.name.lastName}"
                                         required="true" label="Lastname" requiredMessage="#{vmsgs.RequireMoreInput}"
                                         valueChangeListener="#{UserWizard.validateName}" immediate="true">
                                <f:ajax event="blur" render="validationError" />
                            </h:inputText>

                            <h:outputText value="#{msgs.Title}: " />
                            <h:inputText value="#{UserWizard.user.name.title}">
                            </h:inputText>

                            <h:outputText value="#{msgs.Birthday}: *" />
                            <h:inputText value="#{UserWizard.user.birthday}" required="true" id="wmInput1"
                                         requiredMessage="#{vmsgs.RequireMoreInput}">
                                <f:convertDateTime pattern="#{fmsgs.DateFormat}" type="date"/>
                                <p:watermark value="#{fmsgs.DateFormat}" />
                            </h:inputText>

                            <h:outputText value="#{msgs.Username}: *" />
                            <h:inputText value="#{UserWizard.user.username}" required="true"
                                         requiredMessage="#{vmsgs.RequireMoreInput}" immediate="true"
                                         valueChangeListener="#{UserWizard.validateUsername}">
                                <f:ajax event="blur" render="validationError"/>
                            </h:inputText>

                        </h:panelGrid>

                    </p:panel>
                </p:tab>


                <p:tab title="Registration Wizard">
                    <p:panel header="#{msgs.AddressDetails}" >

                        <!-- Output Message -->
                        <h:messages errorClass="error" style="color: red; font-style: italic;"/>

                        <h:panelGrid columns="2" columnClasses="label, value">
                            <h:outputText value="#{msgs.Street}: *" />
                            <h:inputText value="#{UserWizard.street}" required="true"/>

                            <h:outputText value="#{msgs.PostalCode}: *" />
                            <h:inputText value="#{UserWizard.zip}" required="true"/>
                            <h:outputText value="#{msgs.Country}: *" />
                            <h:inputText value="#{UserWizard.country}" required="true"/>
                            <h:outputText value="#{msgs.City}: *" />
                            <h:inputText value="#{UserWizard.city}" required="true"/>
                        </h:panelGrid>
                    </p:panel>
                </p:tab>

                <p:tab title="Registration Wizard">
                    <p:panel header="#{msgs.ContactInfo}">

                        <!-- Output Message -->
                        <h:messages errorClass="error" style="color: red; font-style: italic;"/>

                        <h:panelGrid columns="2" columnClasses="label, value">

                            <h:outputText value="#{msgs.Email}: *" />
                            <h:inputText value="#{UserWizard.email}" required="true" label="Email"
                                         requiredMessage="#{vmsgs.RequireMoreInput}" immediate="true">
                                <f:validateRegex pattern="^\w+@[a-zA-Z_]+\.([a-zA-Z]{2,3})$"/>
                            </h:inputText>

                            <h:outputText value="#{msgs.PhoneNumber}: *" />
                            <h:inputText value="#{UserWizard.phone}" id="wmInput2" >
                                <f:validateRegex pattern="^[+]?\d{2,3}\D\d{3,5}\D\d{3,5}(\D\d{1,5})?"/>
                                <p:watermark value="z.B.: +49-123-12345" />
                            </h:inputText>

                        </h:panelGrid>
                    </p:panel>
                </p:tab>


                <p:tab title="Registration Wizard">
                    <p:panel header="#{msgs.Password}">

                        <!-- Output Message -->
                        <h:messages errorClass="error" style="color: red; font-style: italic;"/>

                        <h:panelGrid columns="2" columnClasses="label, value" styleClass="grid">
                            <h:outputText value="#{msgs.Password}: *" />
                            <p:password value="#{UserWizard.user.password}" minLength="5" goodLabel="#{msgs.GoodPW}"
                                        maxlength="20" required="true" weakLabel="#{msgs.WeakPW}" >
                                <f:validateLength maximum="20" minimum="5"/>
                            </p:password>
                        </h:panelGrid>

                    </p:panel>
                </p:tab>


                <p:tab title="Registration Wizard">
                    <p:panel header="#{msgs.Confirmation}">

                        <p:growl id="growl" sticky="true" showDetail="true"/>

                        <!-- Output Message -->
                        <h:messages errorClass="error" style="color: red; font-style: italic;"/>

                        <h:panelGrid id="confirmation" columns="2">
                            <h:outputText value="#{msgs.FirstName}: " styleClass="outputLabel"/>
                            <h:outputText value="#{UserWizard.user.name.firstName}" styleClass="outputLabel"/>
                            <h:outputText value="#{msgs.LastName}: " styleClass="outputLabel"/>
                            <h:outputText value="#{UserWizard.user.name.lastName}" styleClass="outputLabel"/>
                            <h:outputText value="#{msgs.Username}: " styleClass="outputLabel"/>
                            <h:outputText value="#{UserWizard.user.username}" styleClass="outputLabel"/>
                            <h:outputText value="#{msgs.Email}: " styleClass="outputLabel"/>
                            <h:outputText value="#{UserWizard.email}" styleClass="outputLabel"/>
                            <h:outputText value="#{msgs.PhoneNumber}: " styleClass="outputLabel"/>
                            <h:outputText value="#{UserWizard.phone}" styleClass="outputLabel"/>
                            <h:outputText value="#{msgs.Birthday}: " styleClass="outputLabel"/>
                            <h:outputText value="#{UserWizard.user.birthday}" styleClass="outputLabel">
                                <f:convertDateTime pattern="#{fmsgs.DateFormat}" type="date"/>
                            </h:outputText>
                            <h:outputText value="#{msgs.Title}: " styleClass="outputLabel"/>
                            <h:outputText value="#{UserWizard.user.name.title}" styleClass="outputLabel"/>
                        </h:panelGrid> 

                        <p:commandButton style="margin-top: 8px;" value="#{msgs.Submit}" actionListener="#{UserWizard.save}" update="messagepanel"/>

                    </p:panel>
                </p:tab>

            </p:wizard>

            <p:ajaxStatus>
                <f:facet name="start">
                    <h:graphicImage style="position: absolute; left: 0; top: 0px;" library="images" name="ajax_loading.gif" />
                </f:facet>

                <f:facet name="complete">
                    <h:outputText value="" />
                </f:facet>
            </p:ajaxStatus>

        </h:form>

    </ui:define>

</ui:composition>
Here the corresponding Managed Bean

Code: Select all

...
import javax.faces.bean.ManagedBean;
import javax.faces.event.ActionEvent;
import de.nextjack.utils.*;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.faces.bean.ViewScoped;
import javax.faces.component.UIInput;
import javax.faces.event.ValueChangeEvent;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

@ManagedBean(name = "UserWizard", eager = true)
@ViewScoped
public class UserWizard implements Serializable {

    private static Log logger = LogFactory.getLog(UserWizard.class);

    private UserEntity user = new UserEntity();
    private String street;
    private String zip;
    private String country;
    private String city;
    private String email;
    private String phone;
    private String validateError = "";

    public UserEntity getUser() {
        return user;
    }

    public void setUser(UserEntity user) {
        this.user = user;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getCountry() {
        return country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getStreet() {
        return street;
    }

    public void setStreet(String street) {
        this.street = street;
    }

    public String getValidateError() {
        return validateError;
    }

    public void setValidateError(String validateError) {
        this.validateError = validateError;
    }

    public String getZip() {
        return zip;
    }

    public void setZip(String zip) {
        this.zip = zip;
    }

    public void save(ActionEvent actionEvent) {
        logger.debug("UserWizard.save()");
        AddressEntity userAddress = new AddressEntity();
        EmailEntity userEmail = new EmailEntity();
        PhoneEntity userPhone = new PhoneEntity();

        userEmail.setEmail(this.email);
        userEmail.setType(0);       //TODO
        userAddress.setCity(this.city);
        userAddress.setCountry(this.country);
        userAddress.setStreet(this.street);
        userAddress.setZip(this.zip);
        userAddress.setType(0);     //TODO

        // Set Phone Address
        this.phone.trim();
        if (this.phone.startsWith("+")) {
            this.phone = this.phone.substring(1);
        }

        List<String> phoneParts = new ArrayList<String>();
        for (Matcher m = Pattern.compile("[0-9]+").matcher(this.phone); m.find();) {
            phoneParts.add(m.group());
        }

        for (int i = 0; i < phoneParts.size(); i++) {
            logger.debug(phoneParts.get(i));
        }

        if (phoneParts.size() == 4) {
            userPhone.setCountryCode(phoneParts.get(0));
            userPhone.setAreaCode(phoneParts.get(1));
            userPhone.setPhoneNumber(phoneParts.get(2));
            userPhone.setPhoneExtension(phoneParts.get(3));
        } else if (phoneParts.size() == 3) {
            userPhone.setCountryCode(phoneParts.get(0));
            userPhone.setAreaCode(phoneParts.get(1));
            userPhone.setPhoneNumber(phoneParts.get(2));
            userPhone.setPhoneExtension("");
        } else {
            FacesMessageUtil.createErrorException("Phonenumber invalid!");
        }
        userPhone.setType(0);   //TODO

        this.user.getEmailAddresses().add(userEmail);
        this.user.getAddresses().add(userAddress);
        this.user.getPhoneNumbers().add(userPhone);
        this.user.setSince(new Date());

        // Persist TODO


        // Show Info Message
        FacesMessageUtil.addInfoMessage("Welcome: " + this.user.getName().getFirstName());
    }

    public void validateName(ValueChangeEvent e) {
        UIInput nameInput = (UIInput) e.getComponent();
        String name = (String) nameInput.getValue();

        if (!name.trim().matches("[a-zA-Z]{2,20}")) {
            this.validateError = "Notation of the Name is wrong!";
        } else {
            this.validateError = "";
        }
    }

    public void validateUsername(ValueChangeEvent e) {
        UIInput nameInput = (UIInput) e.getComponent();
        String name = (String) nameInput.getValue();

        if (!name.trim().matches("\\D{5,20}")) {
            this.validateError = "Notation of the Username is wrong! (Minimal 5 Chars)";
        } else {
            this.validateError = "";
        }
    }
}

Regards, Michael

MichaelW86
Posts: 5
Joined: 08 Feb 2010, 18:49

08 Feb 2010, 21:03

Update:
Okay i found an error message in the Browser error console when i click on the green "next" button:

Code: Select all

Error: A is undefined
Source: http://localhost:8080/nextjack-web/primefaces_resource/2.0.0-SNAPSHOT/primefaces/core/core.js
Row: 1
Maybe that helps to figure out the real Problem...

MichaelW86
Posts: 5
Joined: 08 Feb 2010, 18:49

09 Feb 2010, 13:32

Update:
It has something todo with Cookies - when i disable Cookies in my web browser the wizard works as expected...

By the way: In my Application i do not see the sessionId in the URL when i disable Cookies, i thought Glassfish would do the encodeURL thing for me... How can I handle this in JSF 2.0?

MichaelW86
Posts: 5
Joined: 08 Feb 2010, 18:49

11 Feb 2010, 18:14

I don't know why but now it works... maybe the reason was that in the Primefaces 2.0.0-SNAPSHOT was temporary a fault or something...

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

12 Feb 2010, 00:24

Hi Michael,

It works even when cookies are enabled?

MichaelW86
Posts: 5
Joined: 08 Feb 2010, 18:49

05 Mar 2010, 21:43

I'm sorry for the late answer. Yes the Wizard works when cookies are enabled.

Regards, Michael

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

07 Mar 2010, 14:46

This is weird, as I know according to servlet spec, when cookies are disabled, server should append jsessionid to request uris.

Wizard will be revisited in upcoming version, probably a complete UI rewrite so, I'd suggest trying with new p:wizard when it is ready.

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 22 guests