myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jakob Korherr <jakob.korh...@gmail.com>
Subject Re: JSF2 view parameters lacking?
Date Mon, 19 Jul 2010 09:44:31 GMT
Hi,

If you only provide param2, both params will be null in the bean, because
param1 is required and if you don't provide it, validation will fail, and if
validation fails, no value updates will occur. Thus this is the expected
behavior.

Regards,
Jakob

2010/7/19 Jan-Kees van Andel <jankeesvanandel@gmail.com>

> Hi,
>
> On my project, we had a strange issue, caused by the way view parameters
> are
> handled.
>
> We had a page like this: (simplified)
> <?xml version="1.0" encoding="UTF-8"?>
> <html xmlns="http://www.w3.org/1999/xhtml"
>      xmlns:f="http://java.sun.com/jsf/core"
>      xmlns:h="http://java.sun.com/jsf/html">
> <f:metadata>
>    <f:viewParam name="param1" value="#{testViewParamsBean.param1}"
> required="true"/>
> <!--        <f:convertDateTime pattern="dd-MM-yyyy"/>-->
> <!--    </f:viewParam>-->
>    <f:viewParam name="param2" value="#{testViewParamsBean.param2}"/>
>    <f:event type="preRenderView" listener="#{testViewParamsBean.init}"/>
> </f:metadata>
> <h:body>
>    <h:outputText value="#{testViewParamsBean.param1}"/><br/>
>    <h:outputText value="#{testViewParamsBean.param2}"/><br/>
> </h:body>
> </html>
>
> And a bean like this:
> @ManagedBean @RequestScoped
> public class TestViewParamsBean {
>    private String param1, param2;
>
>    public void init() {
>        System.out.println("param1 = " + param1);
>        System.out.println("param2 = " + param2);
>    }
>    // Getters and setters...
> }
>
> Note the required="true" attribute on the first viewParam tag in the page.
> This caused the issue.
>
> When I invoke the page with only param2 in the URL (like:
> /viewParams.xhtml?param2=hello ), the init() method is invoked and the
> param1 and param2 properties are both null!
> When I invoke the page with both parameters present (like:
> /viewParams.xhtml?param2=hello&param1=test ), both properties in the bean
> are populated.
> When I remove the required="true" attribute from the tag, everything works
> as expected
>
> I think this is strange behavior to say the least, but it also makes this
> mechanism less useful for handling GET requests, because you don't get the
> benefits of the UIViewParam, like required/validators/converters.
> For example, when I add a converter to param1 (by uncommenting the tags in
> the example above), I get the same behavior.
>
> My current workaround is a state-check in the init() method, where I check
> the maxSeverity of the FacesContext and redirect to an error page, but I
> think this is the responsibility of the JSF lifecycle.
> Maybe I'm doing something wrong, but this is the recommended behavior,
> according to several JSF blogs, like:
>
> http://andyschwartz.wordpress.com/2009/07/31/whats-new-in-jsf-2/#get-prerenderview-event
>
> What do you guys think? Is it me or is it JSF2?
>
> BTW, both MyFaces and Mojarra behave in this way.
>
> Regards,
> Jan-Kees
>



-- 
Jakob Korherr

blog: http://www.jakobk.com
twitter: http://twitter.com/jakobkorherr
work: http://www.irian.at

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message