質問

I am using Spring Webflow 2.4.0.M1 with Mojara JSF 2.1.21.

I have a very simple h:selectOneMenu like so:

<h:selectOneMenu id="title" value="#{person.title}" required="true" requiredMessage="Required title">
        <f:selectItem noSelectionOption="true" itemLabel="Please Select" itemValue="" />
        <f:selectItem itemLabel="Mr" itemValue="MR" />
        <f:selectItem itemLabel="Mrs" itemValue="MRS" />
    </h:selectOneMenu>
    <p:message for="title"/>

After submitting the form with the value left on Please Select, I get the required message displayed. If I then choose option 'Mr', and then submit again, but with other fields on the page having errors, then the page is reloaded, and the required message for title is gone and Mr is selected, as expected. If I then change it back to Please Select and submit again, I get the required message display again, but the selected option has gone back to being 'Mr' instead of 'Please Select'. The #{person.title} EL is binding to a String, which is defaulted to an empty string. So far, this only seems to be an issue on selectOneMenu, as doing the same kind of thing on a h:inputText works correctly.

Any ideas? Have also tried with webflow 2.3.2.RELEASE and same issue occurs.

Looks like it is the same issue as this: JAVASERVERFACES-932 which is about 4 years old, and has a resolution of fixed. It's definitely not fixed. I will try extending the MenuRenderer and overriding the renderOption method with the suggestion mentioned at the end of the Jira issue.

役に立ちましたか?

解決

I can confirm that extending MenuRenderer and overriding the renderOption method with the suggestion mentioned at the end of the Jira issue fixes the issue.

Don't forget to add your patched renderer to your faces-config.xml

<render-kit>
    <renderer>  
        <component-family>javax.faces.SelectOne</component-family>
        <renderer-type>javax.faces.Menu</renderer-type>
        <renderer-class>your.package.PatchedMenuRenderer</renderer-class>
    </renderer>
</render-kit>
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top