How to implement j_security_check with Primefaces? Normally in JSP if you want to use JAAS for login, the login form generally is:
<form action="j_security_check" method="POST">
Username:<input type="text" name="j_username"><br>
Password:<input type="password" name="j_password">
<input type="submit" value="Login">
</form>
But how do we implement it in JSF or in Primefaces!
- What will be the action
- How do we get rid of id or name like
formId:componentId - Also the
p:commandButtonis ajaxified in Primefaces by default, so how does it
submit the form in non-ajax way
I had a requirement to implement the JAAS form authentication with Primefaces and I am sharing the solution here; it might come handy to someone.
The solution is pretty straightforward.
h:formwithprependId="false", so that it will not generate id or name of the component asformId:componentId.action="j_security_check"in theh:formasonsubmit="document.getElementById('login').action='j_security_check';"ajaxattribute of thep:commandButtontofalse, so that the form doesn’t get submitted in ajax way.That’s it. Here is the complete code of the login form which can be replaced by the aforesaid form:
Thanks.