Reputation: 2691
I am having below command button in generalPage.xhtml which having GeneralPageMB backing bean.
<p:commandButton value="#{facility.facilityName}" ajax="false"
action="facilityHome.xhtml?faces-redirect=true&includeViewParams=true">
<f:param name="fid" value="#{facility.id}" />
</p:commandButton>
And I have second page facilityHome.xhtml which having the following code:
<div style="width: 400px; height: 250px;" class="loginContainerBg">
<h:form id="f" prependId="false">
<f:metadata>
<f:viewParam name="fid" value="#{facilityHomeMB.facilityId}"
converter="com.ot.common.utility.FacilityIdConverter" />
</f:metadata>
</div>
facilityHome.xhtml having backing bean as FacilityHomeMB. So I am trying to get view Parameter and set to facilityId property in FacilityHomeMB bean. My problem is facilityId not getting set. What is wrong with the code ?. Any help will be appreciated.
I am using tomcat 7, Primefaces 4.0, Mojarra 2.1.
Upvotes: 2
Views: 585
Reputation: 1108537
The <p:commandButton>
is the wrong tool for the job. It's intented to perform a POST request whereby the data of the enclosing form is being submitted. It's not intented for page-to-page navigation. Your concrete problem is caused because you're explicitly sending a redirect afterwards, causing the initial request with the parameter to be lost.
Better just use <p:button>
. This way you also don't need a whole <h:form>
anymore and you also don't need to mess with faces-redirect
, etc.
<p:button value="#{facility.facilityName}" outcome="facilityHome">
<f:param name="fid" value="#{facility.id}" />
</p:button>
That's all.
In the target page just keep the <f:metadata>
, but it shouldn't be nested in a form or so. See also When using <ui:composition> templating, where should I declare the <f:metadata>? Further, you should absolutely also not use prependId="false"
. This is not related to the current problem, but it will make a complete mess of the JSF ajax works (can't find components to render, etc).
Upvotes: 1