myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stephen Friedrich <trini...@eekboom.com>
Subject Re: [Trinidad] selectOneChoice, autoSubmit, immediate, and required fields
Date Tue, 02 Oct 2007 21:43:49 GMT
If I understand JSF correctly, immediate does not skip validation, but only
moves the processing of events from the "immediate component" to an earlier
phase in the life cycle.

If you don't do anything special, then after the value change event is
processed, the rest of the lifecycle, including any validations is performed.

To circumvent that and go directly from the value changed event to the rendered
response use this inside your selectionChange() method:
	FacesContext.getCurrentInstance().renderResponse();

Have not tried your example, but I think it should work.

Eric Fikus wrote:
> Hello,
> 
> I have two tr:selectOneChoice components, where the list of choices in the
> second depends on the selection made in the first.  The first selection is
> required.  I have other required fields in the same form.  So I have
> something that looks like this:
> 
>    <tr:messages />
> 
>    <tr:panelHorizontalLayout>
> 
>    	<tr:inputText label="Input:"
>    		required="true"
>    		value="#{testBean.input}" />
> 
>    	<tr:selectOneChoice label="Select one:"
>    		required="true"
>    		requiredMessageDetail="You must select one"
>    		unselectedLabel="Select one..."
>    		value="#{testBean.firstSelection}"
>    		readOnly="false"
>    		valueChangeListener="#{testBean.selectionChange}"
>    		autoSubmit="true"
>    		id="firstSelection"
>    		immediate="true">
>    		<f:selectItems value="#{testBean.firstList}" />
>    	</tr:selectOneChoice>
> 
>    	<tr:selectOneChoice label="Select:"
>    		unselectedLabel="Select another one..."
>    		value="#{testBean.secondSelection}"
>    		rendered="true"
>    		partialTriggers="firstSelection">
>    		<f:selectItems value="#{testBean.secondList}" />
>    	</tr:selectOneChoice>
> 
>    </tr:panelHorizontalLayout>
> 
> I've included the Java code at the end of the message.  It is not very
> interesting and seems to work, ie, the choices in the second list change
> each time the selection in the first changes.
> 
> The problem is that every time the first selection changes, a message is
> displayed indicating that the inputText is required ("Input:- Value
> Required").  If the first selection is changed back to the unselected label,
> a message is displayed to indicate that the selection is required. 
> Obviously I have the first selection set to immediate because I don't want
> validation to occur when this changes, I only want the second list to be
> updated.  If I do not use immediate="true", messages are not displayed in
> the tr:messages component but messages are displayed next to the required
> inputs that are missing.  It works the way I want it to if I used
> immediate="true" and do not have a messages component.
> 
> Questions:
> - Why is validation performed on an immediate form submission?  It seems to
> be skipping one stage of validation (and so not displaying the message next
> to the required component) but still validating and displaying a message.
> - How can I get the behavior I want and still have a tr:messages component
> on the page?
> 
> Regards,
> Eric Fikus
> 
> 
> Java code:
> 
> // imports not shown
> public class TestBean
> {
>    private String input;
>    private String firstSelection;
>    private String secondSelection;
>    private List<SelectItem> secondList;
> 
>    public List<SelectItem> getFirstList()
>    {
>       return Arrays.asList(new SelectItem("a"), new SelectItem("b"));
>    }
>    
>    public void selectionChange(ValueChangeEvent event)
>    {
>       String value = (String) event.getNewValue();
>       if (value.equals("a"))
>       {
>          secondList = Arrays.asList(new SelectItem("apple"));
>       }
>       else if (value.equals("b"))
>       {
>          secondList = Arrays.asList(new SelectItem("blue"));
>       }
>    }
> 
>    // getters and setters for all fields not shown
> }


Mime
View raw message