I\'m using JSF and Primefaces and my question is:
I have a page (page1.jsf) that recive a view param with a list of strings (space delimited):
A command button does not use an attribute or parameter to construct the URL to which redirection happens.
For this you normally use the h:commandLink
or optionally the h:outputLink
, but you need to be aware that these will render the parameters as they were at the time the page was requested. If the user makes changes to the selection after that, those won't be reflected in the link.
An alternative that would give you the latest selection, is using an action method and construct the redirect URL there.
E.g.
<p:commandButton action="#{bean2.navigateWithSelection}" />
And then in your bean:
public String navigateWithSelection() {
return "page1?faces-redirect=true&" + convertSelectedItemsToString();
}
As per the comments, if bean2
is a generic bean that has no knowledge about the page, you can pass in the target page as a parameter:
<p:commandButton action="#{bean2.navigateWithSelection('page1')}" />
And then in your bean again:
public String navigateWithSelection(String target) {
return target + "?faces-redirect=true&" + convertSelectedItemsToString();
}