Sure you can. Most JSF requests are POST
s anyway, so if you use the path to the JSF page you're intending to handle the POST
request, you can then get the parameter within a managed bean that is backed by that page OR get the parameter within the page itself.
Within a managed bean:
@PostConstruct
public void initMyBean(){
/**This map contains all the params you submitted from the html form */
Map<String,String> requestParams = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
requestParams.get("reportKey");
}
OR
within the managed bean have
@ManagedProperty(value="#{param.reportKey}")
String reportKey;
//getter and setter of course!
The method you've annotated with @PostConstruct
will be executed after the managed bean has been instantiated. The above will give you access within your managed bean.
If you need the value within your page first however, you can have this in your page (preferably at the top)
<f:metadata>
<f:viewParam name="reportKey" value="#{backingBean.reportKey}" required="true"/>
</f:metadata>
Notice how you can perform validations on the parameter from within your view. Pretty cool feature.
Just be sure and set your html form action
attribute to the path of the JSF view.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…