【发布时间】:2014-02-25 08:13:14
【问题描述】:
我想使用 j_security_check 身份验证来验证用户凭据。
基本上我想要实现的是当用户按下提交时,如果他使用了错误的凭据,则会显示一条消息 (p:growl),如果成功,则对话框将关闭。
网络上有很多例子,但不幸的是我仍然无法理解如何完成这个难题:(
在我的项目中,我使用的是 primefaces 4.0 和 weblogic 10.3.2.0 (JAVA EE 5)。
一些代码示例:
<p:dialog id="dialog" widgetVar="dlg" resizable="false">
<h:form id="fLogin" prependId="false"
onsubmit="document.getElementById('fLogin').action = 'j_security_check';">
<h:panelGrid columns="2" cellpadding="5">
<h:outputLabel for="j_username" value="Username:" />
<p:inputText value="#{expBean.username}"
id="j_username" label="username"/>
<h:outputLabel for="j_password" value="Password:" />
<h:inputSecret value="#{expBean.password}"
id="j_password" label="password"/>
<p:commandButton id="submitButton"
value="Submit"
actionListener="#{expBean.run}" />
</h:panelGrid>
</h:form>
</p:dialog>
web.xml
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<security-constraint>
<web-resource-collection>
<web-resource-name>main</web-resource-name>
<description/>
<url-pattern>main.jsf</url-pattern>
<http-method>POST</http-method>
</web-resource-collection>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>my-realm</realm-name>
</login-config>
<security-role>
<description/>
<role-name>MyRole</role-name>
</security-role>
exeBean:
public void run() {
FacesContext facesContext = FacesContext.getCurrentInstance();
}
任何指南和有用的例子将不胜感激
谢谢
【问题讨论】:
-
您可以使用普通表单而不是使用 jsf 组件。改用 html 输入并使用 PF css 样式设置它们的样式。
标签: jsf-2 primefaces j-security-check