I believe that you will be able to help me with the below problem.
I'm starting my adventure with Java EE and Primefaces and need a bit of help to understand/fix the problem.
So I've created login module using Jaas and below configuration:
web.xml
<login-config>
<auth-method>FORM</auth-method>
<realm-name>authRealm</realm-name>
<form-login-config>
<form-login-page>/public/login.xhtml</form-login-page>
<form-error-page>/public/loginError.xhtml</form-error-page>
</form-login-config>
</login-config>
login_page_1.xhtml
<p:panel header="Login From">
<form method="POST" action="j_security_check">
Username: <input type="text" name="j_username" />
Password: <input type="password" name="j_password" />
<br />
<input type="submit" value="Login" />
<input type="reset" value="Reset" />
</form>
</p:panel>
This configuration work just great however as I'm using primefaces as front-end framework I would like to make my page look better. I found below resolution:
login_page_2.xhtml
<p:panel header="Login From">
<h:form id="loginForm" onsubmit="document.getElementById('loginForm').action='j_security_check';" prependId="false">
<p:panelGrid columns="2">
<p:outputLabel for="j_username" value="Email" />
<p:inputText id="j_username" />
<p:outputLabel for="j_password" value="Passwort" />
<p:password id="j_password"/>
<p:commandButton id="login" value="Login" ajax="false" />
</p:panelGrid>
</h:form>
</p:panel>
The problem is that when I use login_page_1.xhtml
and put wrong credentials (wrong username/password) I got redirected to errorLogin.xhtml
(this is desirable behavior) however when I use login_page_2.xhtml
I get below erorr
An Error Occurred:
Index: 0, Size: 0
Warning: WEB9102: Web Login Failed: com.sun.enterprise.security.auth.login.common.LoginException: Login failed: Security Exception
Warning: WEB9102: Web Login Failed: com.sun.enterprise.security.auth.login.common.LoginException: Login failed: Security Exception
FATAL: JSF1073: javax.faces.FacesException caught during processing of RESTORE_VIEW 1 : UIComponent-ClientId=, Message=Unexpected error restoring state for component with id j_idt6. Cause: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0.
FATAL: Unexpected error restoring state for component with id j_idt6. Cause: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0.
javax.faces.FacesException: Unexpected error restoring state for component with id j_idt6. Cause: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0.
I would be grateful for any help !
Thanks in advance.
Just remove the attribute onsubmit and prependId. Something like this should work..You need to implement a login method though.
<p:panel header="Login From">
<h:form id="loginForm" >
<p:panelGrid columns="2">
<p:outputLabel for="j_username" value="Email" />
<p:inputText id="j_username" />
<p:outputLabel for="j_password" value="Passwort" />
<p:password id="j_password"/>
<p:commandButton id="login" value="Login" action="#{aMethod}" />
</p:panelGrid>
</h:form>
</p:panel>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.