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

Thang Pham picture Thang Pham · Nov 3, 2010 · Viewed 60.5k times · Source

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>.

Answer

BalusC picture BalusC · Nov 3, 2010

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: