myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jan-Kees van Andel <>
Subject JSF2 view parameters lacking?
Date Mon, 19 Jul 2010 09:32:45 GMT

On my project, we had a strange issue, caused by the way view parameters are

We had a page like this: (simplified)
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns=""
    <f:viewParam name="param1" value="#{testViewParamsBean.param1}"
<!--        <f:convertDateTime pattern="dd-MM-yyyy"/>-->
<!--    </f:viewParam>-->
    <f:viewParam name="param2" value="#{testViewParamsBean.param2}"/>
    <f:event type="preRenderView" listener="#{testViewParamsBean.init}"/>
    <h:outputText value="#{testViewParamsBean.param1}"/><br/>
    <h:outputText value="#{testViewParamsBean.param2}"/><br/>

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:

What do you guys think? Is it me or is it JSF2?

BTW, both MyFaces and Mojarra behave in this way.


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