我希望使用j_security_check进行用户凭证验证。
基本上,我要实现的是,当用户按下提交按钮时,如果他使用的是错误的凭据,则会显示一条消息(p:growl),如果成功,则对话框将关闭。
网络上有很多例子,但不幸的是我仍然无法理解如何完成这个难题 :(
在我的项目中,我正在使用primefaces 4.0和weblogic 10.3.2.0(JAVA EE 5)。
一些代码示例:
任何指南和有用的示例将不胜感激。
谢谢。
基本上,我要实现的是,当用户按下提交按钮时,如果他使用的是错误的凭据,则会显示一条消息(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();
}
任何指南和有用的示例将不胜感激。
谢谢。