4

We want to pass a variable from a backing bean in request scope of one page as query string parameter to other backing bean in view scope of the next page.

I tried to use @ManagedParam, but this signature is not found.

Is there any way to do this?

1 Answer 1

5

You probably meant to use @ManagedProperty. This isn't useable on a view scoped bean to set a request parameter, because the view scope is of a broader scope than the request scope.

The canonical JSF2 way of passing request parameters and invoking actions on them would be something like the following:

view.xhtml view:

<h:link value="Edit" outcome="edit">
    <f:param name="id" value="#{item.id}" />
</h:link>

edit.xhtml view:

<f:metadata>
    <f:viewParam name="id" value="#{edit.id}" />
    <!-- You would normally also convert/validate it here. -->
    <f:event type="preRenderView" listener="#{edit.init}" />
</f:metadata>

Edit backing bean:

@ManagedBean
@ViewScoped
public class Edit {

    private Long id;

    public void init() {
        // This method will be invoked after the view parameter is set.
    }

    // ...
}

See also:

Sign up to request clarification or add additional context in comments.

4 Comments

How to do the same from a h:commandLink ,from the action method in the first page's backing bean
That fires by default a POST request without a query string. You would need to send a redirect as outcome. E.g. return "/edit.xhtml?id=" + item.getId() + "&amp;faces-redirect=true"; I only don't see how that makes sense while having your initial question in mind. What exactly is the functional requirement?
Thanks for the reply....I have one requirement ,it can be a h:link so we can f:viewparam , in the second we have to call action method so used the h:commandlink , then we need to redirect to the common page with different values for the query String....
Ah OK. In the future please ask a new question for that instead of posting it as a comment on an existing but unrelated question.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.