Page 1 of 1
p:commandButton does not work in <form>. Possible Bug
Posted: 06 Dec 2010, 23:06
by KingdomHeart
I use form authentication with jdbc_security_realm setup in Glassfish, for my login. Here is my code
Code: Select all
<form action="j_security_check">
<h:outputLabel value="Login Email:"/>
<h:inputText id="j_username" size="28"/> <br/><br/>
<h:outputLabel value="Password:"/>
<h:inputSecret id="j_password" size="28"/> <br/><br/>
<h:commandButton id="login" value="Login"/>
</form>
Now the above will successfully login me into the system. However, I want to use p:commandButton instead of h:commandButton, since the skinning look better. If I change from h:commandButton to p:commandButton, I get this error.
Code: Select all
javax.faces.FacesException: CommandButton : "login" must be inside a form element
p:commandButton requires to have h:form. I feel like this is a bug, since h:commandButton perform perfectly but I got error with p:commandButton.
Re: p:commandButton does not work in <form>. Possible Bug
Posted: 07 Dec 2010, 18:43
by KingdomHeart
Re: p:commandButton does not work in <form>. Possible Bug
Posted: 07 Dec 2010, 19:11
by kwintesencja
Hi KingdomHeart,
Have you tried p:commandButton with ajax=false?
Re: p:commandButton does not work in <form>. Possible Bug
Posted: 07 Dec 2010, 21:44
by cbmyers
hi,
change your <form> to be <h:form>. that should do it.
Chris
Re: p:commandButton does not work in <form>. Possible Bug
Posted: 08 Dec 2010, 00:05
by KingdomHeart
@kwintesencja: yeah it does not work with ajax=false
@cbmyers: If you take a look at my code above, in this particular case, I am simply forced to use <form> because of the need to submit to a non-JSF service "j_security_check".
Re: p:commandButton does not work in <form>. Possible Bug
Posted: 26 Jan 2011, 20:51
by rippal
hy. this topic is very old.. but i have the same problem now..
is there already a solution or will it be improved in the new primefaces 3 version?
Re: p:commandButton does not work in <form>. Possible Bug
Posted: 23 Feb 2011, 22:03
by bumble.bee
If you want to use JAAS form-based authentication without being restricted to a specific HTML structure you can use the new Servlet 3.0 API and design your own login form. See this page for more information:
http://it-result.me/servlet-3-programma ... nt-page-1/
Re: p:commandButton does not work in <form>. Possible Bug
Posted: 23 Feb 2011, 22:34
by voyagerx
Answer 6 of this also has a pretty nice way to do it, look at update 2. Same idea as above.
http://stackoverflow.com/questions/2206 ... ng-jsf-2-0
Re: p:commandButton does not work in <form>. Possible Bug
Posted: 01 Mar 2011, 15:11
by bumble.bee
Another solution was discussed by Oleg on an unrelated issue post here:
http://code.google.com/p/primefaces/iss ... il?id=1586
He said:
Hi,
You can solve your problem with j_security_check as follows
<h:form id="login" onsubmit="document.login.action = j_security_check;">
or better (if you not sure about client id of your form)
<h:form id="login" onsubmit="document.#{p:component('login')}.action='j_security_check';">
Best regards. Oleg.
Re: p:commandButton does not work in <form>. Possible Bug
Posted: 04 Mar 2011, 01:15
by voyagerx
Nice! Good suggestion, thanks!