1
votes

I have to validate that a h:inputText has a value. There for I'm using the required="true" on that component. It does the job and it works, but then something strange happens.

When I leave it blank, the required="true" happens. When I type some text in the inputText, the required="true" does not happen. When I, after adding text, remove the text the required="true" happens, but the previously entered value reappears in the inputText.

I don't really have got an idea what this could be. Note that when I'm saying the "required="true"" happens, I mean that the border of the inputText gets red (see code).

Here is the code:

<h:form id="generateLetterForm">
    <h:panelGroup id="submitterPanel">
        <h:panelGrid styleClass="rSplitPanel1" columns="1">
            <e:inputText entityBB="#{entityBB}" type="#{type}"
                property="submitterFirstName" />

            <e:inputText entityBB="#{entityBB}" type="#{type}"
                property="submitterLastName" />
        </h:panelGrid>
        <h:panelGrid styleClass="rOnePanel" columns="1">
            <h:panelGroup>
                <h:outputText value="#{AppMessages[type.concat('.address')]}"
                    styleClass="Fieldname" />
                <h:panelGrid columns="3" cellpadding="2" cellspacing="0"
                    styleClass="Fieldcontent"
                    columnClasses="rAddressStreet, rAddressStreetNr, rAddressBoxNr">
                    <h:panelGroup>
                        <h:inputText id="submitterStreetName"
                            value="#{entityBB.entity.address.street}" required="true" styleClass="#{component.valid ? '' : 'addressError'}" />
                        <rich:tooltip target="submitterStreetName">
                            <h:outputText
                                value="#{AppMessages[type.concat('.submitterStreetName')]}" />
                        </rich:tooltip>
                    </h:panelGroup>

"2 other similar columns" (would make code to complex for the problem) 

                </h:panelGrid>
            </h:panelGroup>
        </h:panelGrid>
    </h:panelGroup>

    <a4j:commandButton value="#{AppMessages['general.action.save']}"
    actionListener="#{entityBB.createStandardLetter()}"
    render="generateLetterForm messages letterExistsPanel"
    status="ajaxStatus" styleClass="floatRight"/>


</h:form>

EDIT: The first 2 input text fields (e:inputText) are my own components. Nothing goes wrong there.

The backing bean is ViewScoped

2

2 Answers

1
votes

When you enter the form properly the value is stored in the attribute in the ViewScoped bean. When you then enter the form incorrectly, the 'Process Validations' phase will throw up an error which means the 'Update Model Values' phase is not executed, so the value in the ViewScoped bean remains the original one that was entered when you entered the form correctly and it is this value that is redisplayed when the view is rendered.

0
votes

The problem is located, though not fixed because the possible fix (setting the context-param to false) may not happen. I'm guessing this behaviour can be seen as a bug in JSF?

In the web xml:

<context-param> 
    <param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-n‌​ame> 
    <param-value>false</param-value> 
</context-param>