5

I have a p:wizard with some tabs. In the first tab, the user selects a value (t:selectOneRadio - I'm using Tomahawk). That's a required value.

If the user doesn't select a value, it won't go to the next tab, but no validation error is displayed. Hm.

If the user has chosen a value, goes to the next tab, goes back to the first tab and chooses a different value, it will behave as if no value was chosen this time. (No validation error either, but the second tab can't be invoked).

And even worse: The user chooses a value in the first tab, goes to the second tab, tries invoke an action from there... a validation message appears; it acts as if no value was chosen in the first tab.

Is there any explanation for this?

UPDATE

The solution suggested in the PrimeFaces forum worked for me. (Adding process="@this" to the commandButton.)

Manuel M
  • 809
  • 1
  • 10
  • 25
geeehhdaa
  • 822
  • 5
  • 17
  • 30

5 Answers5

4

Another thing you might want to consider..

If you are having trouble with required fields across tabs, you can manually perform your own validations between steps by implementing a flow event in your wizard component.

    public String onFlowProcess(FlowEvent event) {  
    //First perform check to see if the user is attempting to remove the last visitor
    if ("confirm".equals(event.getNewStep()) && (visitors == null || visitors.isEmpty())) {
        log.debug("Validation failed for empty visitors");
        FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Visit must have at least one visitor.", null);
        FacesContext.getCurrentInstance().addMessage(null, msg);
        return event.getOldStep();
    }

    return event.getNewStep();  
}

And the .xhtml file I declare the flowListener event. Try this and see if the validation messages go away.

<p:wizard showNavBar="true" widgetVar="scheduler" flowListener="#{scheduleVisit.onFlowProcess}" showStepStatus="true">
maple_shaft
  • 10,435
  • 6
  • 46
  • 74
  • The value was always present using this technique. I think I have fixed it. I found this: http://primefaces.prime.com.tr/forum/viewtopic.php?f=3&t=1724&start=0 I added process="@this" to the commandButton and it works. I have no idea *why*, though. And I hope it has no side effects. Hm. Thank you very much for helping, maple_shift! – geeehhdaa May 31 '11 at 13:25
  • Good! Please post your solution as an Answer please for the benefit of people searching for this problem in the future. – maple_shaft May 31 '11 at 13:32
4

UPDATE

The solution suggested in the PrimeFaces forum worked for me. (Adding process="@this" to the commandButton.) No idea why, though!

Subodh Joshi
  • 12,717
  • 29
  • 108
  • 202
geeehhdaa
  • 822
  • 5
  • 17
  • 30
2

This sounds like it could be one of a couple possible issues. You may be getting a validation error however you may not have declared your messages component correctly, or it is not getting updated. If this is the case their may be validation errors that you just don't see rendered on the page.

From the Primefaces Guide 2.2 for the Wizard component:

AJAX and Partial Validations - Switching between steps is based on ajax, meaning each step is loaded dynamically with ajax. Partial validation is also built-in, by this way when you click next, only the current step is validated, if the current step is valid, next tab’s contents are loaded with ajax. Validations are not executed when flow goes back.

The other problem may be that your property is not getting set properly in the managed bean and this is causing validation problems. This seems more likely.

I am having trouble thinking why one would need validation other than 'Required' for a selectOneRadio? You have a limited number of choices and one must be picked, therefore an incorrect value or invalid value should not be possible.

maple_shaft
  • 10,435
  • 6
  • 46
  • 74
  • Thanks for taking the time! "required" is the only validation I have for that selectOneRadio. But the wizard seems to "forget" the value after calling the next tab. This seems a common problem: http://stackoverflow.com/questions/3854439/primefaces-wizard-component-resets-values-in-hselect-components-when-form-i – geeehhdaa May 31 '11 at 12:02
  • Thats.... strange! I use a p:wizard in my application and I do not have this problem at all. Further I don't see what you are doing wrong. What version of Primefaces and Mojarra are you currently using? – maple_shaft May 31 '11 at 12:22
  • I'm using PrimeFaces 2.2.1 and I don't use Mojarra, I use MyFaces. Besides that, PrimeFaces is working great for me. I've read a workaround somewhere in the PrimeFaces forum (I can't find the link right now) that said, using a inputHidden on the following tabs would work to preserve the value. However, it won't work for me. – geeehhdaa May 31 '11 at 12:37
  • I have to make a correction I guess (even though I'm sure I've seen the behavior from my original posting!): The required message comes when I try to invoke a action from the second tab (p:commandButton). And the back button won't work anymore then. – geeehhdaa May 31 '11 at 12:52
  • This is the same version of Primefaces that I am currently using as it seems the most stable overall. A couple of things I would try would be to use the selectOneMenu and other select components without a converter or SelectItem values and see if this makes a difference. Use a String instead just to see if bean properties stay persisted (cont...) – maple_shaft May 31 '11 at 12:56
  • You are getting the required message because the bean properties aren't staying persisted across tabs. I don't know much about MyFaces vs. Mojarra, how easy would it be to import Mojarra and test your wizard page with Mojarra and without MyFaces? – maple_shaft May 31 '11 at 12:59
  • I probably have to corrent myself once again. I just did a outputText on the bean property on the following tabs and the value is still there. (I'm sure it hasn't been earlier - I might have accidentely fixed that somehow.) But if I try to invoke an action from one of the tabs, it says that no value was chosen. (I couldn't have gotten far the first tab if I had chosen none - even though there is no required message if I try to!). – geeehhdaa May 31 '11 at 13:05
  • See my other answer. I think their is strangeness with required field validation accross wizard tabs. Try manually implementing your required field validation using this method and see if this resolves your problems. – maple_shaft May 31 '11 at 13:17
1

You just need to put the attribute required true on your radio button.

ex:

<p:selectOneRadio required="true" requiredMessage="you must put it">
    <f:selectItem itemLabel="Días Laborales" itemValue="diasLab" />
    <f:selectItem itemLabel="Días Ticados" itemValue="diasTic" />
</p:selectOneRadio>
Smern
  • 18,746
  • 21
  • 72
  • 90
Constanza
  • 11
  • 1
-1

PrimeFaces' p:wizard validation problem

Step :1 customerInformation.xhtml

<?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">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:p="http://primefaces.org/ui">


 <p:wizard flowListener="#{customerForm.onFlowProcess}">  

       <p:tab id="information" title="Information">  
     <p:panel header="Customer Information"> 

        <h:outputLabel value="First Name" for="fName"/>
            <h:inputText id="fname" value="#{customer.fname}"/>                                                                                                                                             

            <h:outputLabel value="Last Name" for="lName"/>
            <h:inputText id="lname" value="#{customer.lname}"/>                                                             

         </panel>
       </p:tab>

         <p:tab id="details" title="Details">  
       <p:panel header="Customer Details">  

              <h:outputLabel value="Address Line 1" for="addressOne"/>
            <h:inputText id="addressOne" value="#{customer.addressOne}"/>                                                                                                                                               

            <h:outputLabel value="Address Line 2" for="addressTwo"/>
            <h:inputText id="addressTwo" value="#{customer.addressTwo}"/>   

           </panel>
       </p:tab>
  </p:wizard>
</html>

Step:2 Create bean class CustomerForm.java

public class CustomerForm implements Serializable {

    private static final long serialVersionUID = 1L;

    private String fName;
    private String lName;
    private String addressOne;
    private String addressTwo;

    private static Logger logger = Logger.getLogger(CustomerForm.class.getName());                                         

    /**
     * Call this method in p:wizard tag
     * 
     */  
    public String onFlowProcess(FlowEvent event) {  
    logger.info("Current wizard step:" + event.getOldStep());  
    logger.info("Next step:" + event.getNewStep());  
        return event.getNewStep();  
    }

    /**
     * @return the fName
     */
    public String getfName() {
        return fName;
    }
    /**
     * @param fName the fName to set
     */
    public void setfName(String fName) {
        this.fName = fName;
    }
    /**
     * @return the lName
     */
    public String getlName() {
        return lName;
    }
    /**
     * @param lName the lName to set
     */
    public void setlName(String lName) {
        this.lName = lName;
    }
    /**
     * @return the addressOne
     */
    public String getAddressOne() {
        return addressOne;
    }
    /**
     * @param addressOne the addressOne to set
     */
    public void setAddressOne(String addressOne) {
        this.addressOne = addressOne;
    }
    /**
     * @return the addressTwo
     */
    public String getAddressTwo() {
        return addressTwo;
    }
    /**
     * @param addressTwo the addressTwo to set
     */
    public void setAddressTwo(String addressTwo) {
        this.addressTwo = addressTwo;
    }

}

Note: don't put required="true" in xhtml file

Pravin
  • 103
  • 1
  • 14