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

UI Components for JSF
Post Reply
KingdomHeart
Posts: 280
Joined: 25 Jun 2010, 01:18

06 Dec 2010, 23:06

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.

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

KingdomHeart
Posts: 280
Joined: 25 Jun 2010, 01:18

07 Dec 2010, 18:43


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

User avatar
kwintesencja
Posts: 316
Joined: 08 Feb 2010, 20:33
Location: Brazil

07 Dec 2010, 19:11

Hi KingdomHeart,

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

--

Rafael Mauricio Pestano


Primefaces 5.x + JavaEE7(Glassfish 4.x and Wildfly 8)
Conventions Framework
Blog
@realpestano

cbmyers
Posts: 53
Joined: 20 Oct 2010, 14:56

07 Dec 2010, 21:44

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

KingdomHeart
Posts: 280
Joined: 25 Jun 2010, 01:18

08 Dec 2010, 00:05

@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

rippal
Posts: 19
Joined: 26 Jan 2011, 15:59

26 Jan 2011, 20:51

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?

User avatar
bumble.bee
Posts: 723
Joined: 29 Sep 2010, 21:39
Location: United States

23 Feb 2011, 22:03

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/

voyagerx
Posts: 70
Joined: 10 Feb 2011, 03:52

23 Feb 2011, 22:34

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

User avatar
bumble.bee
Posts: 723
Joined: 29 Sep 2010, 21:39
Location: United States

01 Mar 2011, 15:11

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.



voyagerx
Posts: 70
Joined: 10 Feb 2011, 03:52

04 Mar 2011, 01:15

Nice! Good suggestion, thanks!

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 18 guests