Thang Pham
Thang Pham

Reputation: 38705

The form component needs to have a UIForm in its ancestry. Suggestion: enclose the necessary components within <h:form>

Here is my form:

<form action="j_security_check">
    <h:panelGrid columns="2" bgcolor="#eff5fa" cellspacing="5" frame="box" styleClass="center">
        <h:outputLabel value="User ID:"/>
        <h:inputText id="j_username" tabindex="1" />
        <h:outputLabel value="Password:"/>
        <h:inputSecret id="j_password"/>
        <h:outputLabel value=""/>
        <h:commandButton id="login" value="Login"/>
    </h:panelGrid>
</form>

It work fine with Glassfish 3.0.1, but since Glassfish 3.1 b2 it shows this warning as a FacesMessage in the JSF page:

The form component needs to have a UIForm in its ancestry. Suggestion: enclose the necessary components within <h:form>

If I change the <form action="j_security_check"> to <h:form>, it does not fix it, I have to place the <h:form> inside the <h:panelGrid>.

Upvotes: 40

Views: 65491

Answers (6)

user4413257
user4413257

Reputation:

In my case, this warning message was displayed in p:messages which I've put in dialog to show validation errors, so I've just included severity="error"in p:messages and warning message was gone.

Upvotes: 0

Carlo Pacheco
Carlo Pacheco

Reputation: 41

It only shows if you are in JSF Development based on your web config.

<context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>

When you change it to Production it wont show anymore

Upvotes: 4

Harun
Harun

Reputation: 707

I'm using Mojarra 2.1.27 and find out that this is my mistakes. However its just very hard to find what the mistakes was. Hopefully someone from Mojarra could add component id to the warning messages. Here is what I did to found out the component: (which also posted to https://code.google.com/p/primefaces/issues/detail?id=1586#c48)

I trace it by downloading the Mojarra source code and adding break point to com.sun.faces.context.FacesContextImpl class in method: public void addMessage(String clientId, FacesMessage message). when the break point catch, open the Debugging window or call stack window to find out that it was called by class com.sun.faces.application.view.FormOmittedChecker in method private static void addFormOmittedMessage(FacesContext context) which is previously called by method

public static void check(FacesContext context).

inside the check method there is parameter variable component. You can get the component id from Watch or variable window and then trace it back to your html page and code.

Its a hard way, but hope you can find the root of the problems. It will be much more simpler if the warning message also display the problematic component id

Upvotes: 1

anotherUser
anotherUser

Reputation: 561

If anyone will find this usefull one day, i had same error and the problem was that i have primefaces component

<p:something ....

and that component was not inside <h:form> element

Upvotes: 3

BalusC
BalusC

Reputation: 1109072

This is just a Warning not an Error. Warnings are usually there to inform the developer about unforeseen situations/conditions which might not immediately cause technical errors/problems. Anything may just work flawlessly, but the behaviour/results may probably not be as the developer intented. A newbie developer may for example accidently have used <form> instead of <h:form>. Warnings like this are then helpful.

In your particular case, you are simply forced to use <form> because of the need to submit to a non-JSF service. You as a more experienced developer know that it's legitimately valid. You can just ignore this warning. This warning will only appear when javax.faces.PROJECT_STAGE is set to Development anyway and not appear when it is set to Production.

However, that it still displays the warning when there's another component like panelgrid in between the form and its input children, is a bug to me. I'd report it to the Mojarra guys. It look like as if it is checking the immediate parent only and not all of the parents. Update: it has been fixed as per Mojarra 2.1.3/2.2, see also issue 2147.

This is by the way not Glassfish specific. The newer GF version of course ships with a newer Mojarra version which has those warnings implemented. See also issue 1663.

Related questions:

Upvotes: 50

Oversteer
Oversteer

Reputation: 1828

This was suggested to me by Oleg from the PrimeFaces forum and works:

<h:form id="login" prependId="false"
                onsubmit="document.getElementById('login').action='j_security_check';">

Regards, Brendan.

Upvotes: 16

Related Questions