How to pass parameters via URL to a bean class using JSF?
java, jsf
Solution
You should pass it as POST parameter which is what JSF does by default , You can google for a quick example of a Login page with JSF , however if you want to read the request parameters from URL then you can do like
<a href="name.jsf?id=#{testBean.id}" />
You need something like this in your bean
@ManagedBean
@RequestScoped
public class TestBean {
@ManagedProperty(value = "#{param.id}")
private String id;
.....
}
You can also do this in your xhtml to get the same outcome, this will work with JSF 2.x as viewParam is not available in JSF 1.2
<f:metadata>
<f:viewParam name="id" value="#{testBean.id}" />
</f:metadata>
Above line will set the parameter id in bean from the request parameter id when your bean is created.
Problem
I have created a login page for my JSF application. I want to pass the username and password as parameters via the URL to later receive them as fields in a bean class. How can I do this?