How to pass a query string parameter?

We want to transfer the variable from the backup bean in the request area of ​​one page as a parameter to the query string to another bean in the viewing area of ​​the next page.

I tried using @ManagedParam but this signature was not found.

Is there any way to do this?

+4
source share
1 answer

You probably used @ManagedProperty . This is not applicable in the scope of the bean for setting the request parameter, since the view scope has a wider scope than the request scope.

The canonical JSF2 way to pass request parameters and call actions on them will look something like this:

view.xhtml :

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

edit.xhtml :

 <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 bean support:

 @ManagedBean @ViewScoped public class Edit { private Long id; public void init() { // This method will be invoked after the view parameter is set. } // ... } 

See also:

+5
source

Source: https://habr.com/ru/post/1389523/


All Articles