Board index JavaServer Faces General p:commandButton does not work in <form>. Possible Bug

p:commandButton does not work in <form>. Possible Bug

Components, Ajax Framework, Utilities and More.


Posts: 280
I use form authentication with jdbc_security_realm setup in Glassfish, for my login. Here is my code
                 <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.
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.

Mojarra 2.1.10, Glassfish 3.1, Tomcat 7, Primeface 3.3.1
IE 6-8, FireFox 10-13
MAC OSX Lion, Windows XP, 7


Posts: 280

Mojarra 2.1.10, Glassfish 3.1, Tomcat 7, Primeface 3.3.1
IE 6-8, FireFox 10-13
MAC OSX Lion, Windows XP, 7


Posts: 315
Location: Brazil
Hi KingdomHeart,

Have you tried p:commandButton with ajax=false?
Att,

--

Rafael Mauricio Pestano
Graduando em Ciência da Computação - UFRGS


Primefaces 4.x, PF-Ext 1.x, Glassfish 4.x, JBossAS 7.1.2, Tomee, Mojarra: 2.1.x, CODI 1.0.5 on Ubuntu 12.04
Conventions Framework
Blog
@realpestano


Posts: 53
hi,

change your <form> to be <h:form>. that should do it.

Chris
- Chris
PrimeFaces 3.0M1
Eclipse Indigo (with Tomcat 7.0.14)
Java 1.6
JSF 2.0 (Mojarra 2.0.4)
hibernate 3.5.5


Posts: 280
@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".

Mojarra 2.1.10, Glassfish 3.1, Tomcat 7, Primeface 3.3.1
IE 6-8, FireFox 10-13
MAC OSX Lion, Windows XP, 7


Posts: 19
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?


Posts: 723
Location: United States
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-programmatic-authentication-api/comment-page-1/


Posts: 70
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


Posts: 723
Location: United States
Another solution was discussed by Oleg on an unrelated issue post here:

http://code.google.com/p/primefaces/issues/detail?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.





Posts: 70
Nice! Good suggestion, thanks!


Return to General