The form component needs to have a UIForm in its a

2020-01-29 05:21发布

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

标签: forms jsf jsf-2
6条回答
够拽才男人
2楼-- · 2020-01-29 05:33

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

查看更多
smile是对你的礼貌
3楼-- · 2020-01-29 05:34

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

查看更多
聊天终结者
4楼-- · 2020-01-29 05:38

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

查看更多
做个烂人
5楼-- · 2020-01-29 05:46

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:

查看更多
啃猪蹄的小仙女
6楼-- · 2020-01-29 05:49

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.

查看更多
Anthone
7楼-- · 2020-01-29 05:54

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.

查看更多
登录 后发表回答