I have a commandButton that I will use to navigate and send a parameter to another page (the id of the selected object so I will be able to load the entire object in the other page after retrieving it from the database). I know that commandButtons use POST as request method and that it isn't a good practice for navigation, but in my tests I was close to the expected results using it instead of any other methods.
The code of my commandButton is something like this:
<p:commandButton value="Start" action="#{startBean.goToNextPage()}">
<f:param name="objectId" value="#{startBean.object.Id}"/>
</p:commandButton>
The problem happens on page load (specifically when the commandButton is rendered), because executes before the object be set, when the navigation occurs the parameter is sent to the other with 'null' value.
So, I'd like to know how I can set the 'value' only when click on the commandButton, or other ways to navigate to the other page sending parameters, in this specific case it might be using GET or POST.
Thanks in advance!
UPDATE
I'll detail what I'm really trying to do.
I'm trying to send a simple parameter (an object id) as POST or GET while navigating to another page. I tried first with <p:commandButton />
for stylish reasons. The action attribute of the commandButton calls a method from managedBean that returns the url which it should navigate to. The goToNextPage()
looks like:
public String goToNextPage(){
String url = "nextPage.xhtml?" + "faces-redirect=true&objectId=" + this.object.getId();
return url;
}
After the gotToNextPage()
method the @PostConstruct
of the nextPageBean runs and I'm able to read the parameter sent using FacesContext#getRequestParameterMap()
, the navigation doesn't complete, and the page just refresh.
So I'd like to know how I should send parameters to another page and navigating to it using GET or POST.