I have a Spring + JSF 1.2 application which sends an email with a link to the user after subscription. The link contains a request parameter like:
www.myapp.com/register.jsf?var=1
How can I get this request parameter in my JSF backing bean?
It's not clear if you're using Spring or JSF to manage your beans, but in standard JSF 1.2, you need to register it as <managed-property> of the <managed-bean> with a value of #{param.var} where var is the exact request parameter name:
<managed-bean>
...
<managed-property>
<property-name>var</property-name>
<value>#{param.var}</value>
</managed-property>
</managed-bean>
So if your bean has a property
private String var; // +setter (getter is not mandatory)
then you can access and process it in a @PostConstruct method:
@PostConstruct
public void init() {
System.out.println("var is: " + var);
}
As a completely different alternative, you can also obtain it directly from the request parameter:
String var = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("var");
// ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With