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?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
user684434
  • 1,165
  • 2
  • 19
  • 39

1 Answers1

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:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • How to do the same from a h:commandLink ,from the action method in the first page's backing bean – user684434 Jan 05 '12 at 20:50
  • 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() + "&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? – BalusC Jan 05 '12 at 20:54
  • 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.... – user684434 Jan 05 '12 at 21:03
  • 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. – BalusC Jan 05 '12 at 21:04