0

I am working on a web application that needs to be converted to follow a POST-redirect-GET pattern. In this, a view scoped managed bean needed to be passed on in the redirect so the page will still work the same. So to do this I added a navigation case to my faces-config that would pass the view-param in the redirect

<navigation-rule>
    <from-view-id>page1.xhtml</from-view-id>
    <navigation-case>
        <from-action>#{actionClass.Submit}</from-action>
        <from-outcome>submit</from-outcome>
        <to-view-id>page1.xhtml</to-view-id>
        <redirect>
            <view-param>
                <name>viewScopedBean</name>
                <value>#{actionClass.viewScopedBean}</value>
            </view-param>
        </redirect>
    </navigation-case>
</navigation-rule>

The action is what performs setting up viewScopedBean

And in my jsf page, I have

<f:metadata>
    <f:viewParam name="viewScopedBean" id="viewScopedBean" 
        value="#{actionClass.viewScopedBean}" converter="customConverter"/>
    <f:event type="preRenderView" listener="#{actionClass.initialize}" />
</f:metadata>

The converter looks to work (String returned by getAsString is passed to getAsObject converts it) all the time except when the redirect is done. The string coming in is the toString of the viewScopedBean and not what is done in the getAsString method of my custom converter class so I get an exception.

Should this be expected and am I missing something? How does the converter work in the flow of an application with view-params?

EDIT: After some searching, I discovered why the getAsObject was receiving the viewScopedBean's toString as its String argument after actionClass.submit is called instead of the getAsString conversion. It's happening because once my submit completes, the redirect happens and no HTML is rendered so the <f:viewParam> isn't rendered so the String rep of my viewScopedBean is its toString return value.

3
  • Does the view-param element not include that view param in the redirect?
    – cfreih
    Nov 5, 2015 at 17:12
  • That half worked. My Converter performed the getAsString on the view parameter, but the viewScopedBean that is created in the action was not what was passed.
    – cfreih
    Nov 5, 2015 at 17:28
  • Well, with how I had it originally, the viewScopedBean (just named that for this question) was being passed how I expected it to be, how it was created in the actionClass.submit. The issue was that in my Converter's getAsObject method (converting the string to object) was something that could not be converted because the format was incorrect. It has been coming in as viewScopedBean's toString and not as how it is converted in my Converter's getAsString. With your previous suggestion, it did do the getAsString, but the object was a brand new view.
    – cfreih
    Nov 5, 2015 at 17:39

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.