java - How to pass parameters between Request-Scoped Controllers? -
java - How to pass parameters between Request-Scoped Controllers? -
i have simple jsf-page , want pass parameter page1 page2. every page has own controller in request scope.
the 2 controllers this: controller1:
@component("requestcontroller1") @scope("request") public class requestcontroller1 { private list<product> products; private product selectedproduct; @postconstruct public void init() { //load products db } public void setproducts(list<product> products) { this.products = products; } public list<product> getproducts() { homecoming products; } public void setselectedproduct(product selectedproduct) { this.selectedproduct = selectedproduct; } public product getselectedproduct() { homecoming selectedproduct; } controller2:
@component("requestcontroller2") @scope("request") public class requestcontroller2 { private long selectedproductid; @postconstruct public void init() { selectedproductid = (long) facescontext.getcurrentinstance().getexternalcontext().getrequestmap().get("selectedproductid"); } public void setselectedproductid(long selectedproductid) { this.selectedproductid = selectedproductid; } public long getselectedproductid() { homecoming selectedproductid; } } now want navigate page1 page2 passing selectedproductid controller2. please note both controllers in request-scope , want utilize commandbutton navigation.
<h:commandbutton value="continue" action="requestparam2.jsf?faces-redirect=true"> <f:param name="selectedproductid" value="#{requestcontroller1.selectedproduct.id}"></f:param> </h:commandbutton> it seems f:param not work here. how can accomplish this?
try this: <h:commandbutton value="continue" action="requestparam2.jsf?faces-redirect=true&selectedproductid=#{requestcontroller1.selectedproduct.id}"/>
in jsf1 h:commandbutton didn't supported f:param tags - if remember correctly. can utilize h:commandlink , utilize css styling.
also, need phone call getrequestparametermap() read request parameters. getrequestmap() gets entries servlet request scope - not want.
java jsf jsf-2
Comments
Post a Comment