Tap*_*ose 4 java authentication jaas primefaces jsf-2
如何实现j_security_check与Primefaces?通常在JSP中如果要使用JAAS进行登录,则登录表单通常为:
<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>
Run Code Online (Sandbox Code Playgroud)
但是我们如何在JSF或Primefaces中实现它!
formId:componentIdp:commandButton,默认情况下,它在Primefaces中被ajaxified,因此它如何以非ajax方式提交表单我需要使用Primefaces实现JAAS表单身份验证,我在这里分享解决方案; 这对某人来说可能会派上用场.
Tap*_*ose 18
解决方案非常简单.
h:formwith prependId="false",以便它不会生成组件的id或名称formId:componentId.action="j_security_check"在h:formas中定义onsubmit="document.getElementById('login').action='j_security_check';"ajax属性,以便不以ajax方式提交表单.p:commandButtonfalse而已.以下是登录表单的完整代码,可由上述表格替换:
<h:form id="login" onsubmit="document.getElementById('login').action='j_security_check';" prependId="false">
<h:panelGrid columns="2">
<p:outputLabel for="j_username" value="Username" />
<p:inputText id="j_username" name="j_username" />
<p:outputLabel for="j_password" value="Password" />
<p:password id="j_password" name="j_password"/>
<p:commandButton id="submit" value="Login" ajax="false"/>
</h:panelGrid>
</h:form>
Run Code Online (Sandbox Code Playgroud)
谢谢.
| 归档时间: |
|
| 查看次数: |
8627 次 |
| 最近记录: |