3

I have two inputs - one inside a "normal" h:dataTable and one inside a rich:dataTable When I submit a wrong value, i.e. validation fails, the "normal" one keeps the value I submitted while the second one loses it. See the following code snippets (enter any value an press the button):

ManagedBean

@ManagedBean
@ViewScoped
public class TestController implements Serializable {

    private static final long serialVersionUID = -484022507596298941L;

    private String[] stringArray1 = {"Element 1", "Element 2"}; // + Getter
    private String[] stringArray2 = {"Element A", "Element B"}; // + Getter
    private Map<String, String> inputValues = new HashMap<String, String>(4); // + Getter

    public TestController() {
        inputValues.put(stringArray1[0], "");
        inputValues.put(stringArray1[1], "");
        inputValues.put(stringArray2[0], "");
        inputValues.put(stringArray2[1], "");
    }

    public void doSomething() {
        System.out.println("Did something");
    }

    public void validate(FacesContext facesContext, UIComponent uiComponent, Object value) {
        throw new ValidatorException(new FacesMessage("This can never be valid."));
    }
}

View

<h:form>
    <h1>h:dataTable</h1>
    <h:dataTable id="table1" value="#{testController.stringArray1}" var="string" columnClasses="inactive">
        <h:column>
            <h:outputText value="#{string}:"/>
            <h:inputText id="someInput" value="#{testController.inputValues[string]}" validator="#{testController.validate}"/>
            <h:message for="someInput" id="msg" style="color: red;"/>
        </h:column>
    </h:dataTable>

    <h1>rich:dataTable</h1>
    <rich:dataTable id="table2" value="#{testController.stringArray2}" var="string">
        <rich:column>
            <h:outputText value="#{string}:"/>
            <h:inputText id="someInput" value="#{testController.inputValues[string]}" validator="#{testController.validate}"/>
            <h:message for="someInput" id="msg" style="color: red;"/>
        </rich:column>
    </rich:dataTable>

    <h:commandButton id="button" action="#{testController.doSomething}" value="do something"/>
</h:form>

Is this known Richfaces behaviour or a bug of some kind? Is there a way to make it behave the same way the normal JSF-DataTable does? Using h:dataTable instead is not always an option and losing your "I-was-just-about-to-correct-it" input is rather annoying.

ADDITION: I just checked the behaviour of ui:repeat and a4j:repeat and it's just the same: ui:repeat keeps the submitted value while a4j:repeat does not.

UPDATE: Re-worked example code to rule out some possible problems as mentioned in comments (input fields now point to different values; only one form element).

Tested on Mojarra 2.1.21 with RichFaces 4.3.7 and JBoss AS 7 plus on Mojarra 2.2.7 with RichFaces 4.5.0 Alpha3 and JBoss Wildlfy - same result.

Louise
  • 1,451
  • 1
  • 18
  • 40

1 Answers1

2

I just tried each form of your page separately with Richefaces 4.3.7 and Mojarra 2.2.6 and it's perfectly working! i didn't noticed any abnormal behavior, when validation fails i didn't lost any values. That means that there is no Validation issues with the Richfaces components.

However, When using the two forms in a single page, i can notice that when i submit the first form the inputText of the second form loses it's value, while if we submit the form2 the inputText of the first form don't lost it's value, in my guess its because JSF stored the state of it's HTML components in the javax.faces.ViewState and doesn't do the same for Richfaces components, using Firebug you can easily verify that the only common request parameter between those two POST requests is the javax.faces.ViewState.

Tarik
  • 4,961
  • 3
  • 36
  • 67
  • When reading this SO http://stackoverflow.com/questions/7371903/multiple-hform-in-a-jsf-page I get the impression that is should be OK to have two forms in parallel. Probably the problem is that both forms operate on the same value. – cheffe Feb 11 '15 at 11:35
  • @cheffe Yes, regarding BalusC's answer there is no problem on using parallel forms. But, the issue is not du to using the same value as I tested that with tow different values but I got the same behavior – Tarik Feb 11 '15 at 14:01
  • I tested this locally with one form at a time, same problem. I do not have your Mojarra version, I will check this next. – Louise Feb 12 '15 at 16:07
  • @Louise which version do you have ? – Tarik Feb 12 '15 at 16:14
  • From what I can tell 2.1.21. Comes with a JBoss AS 7 – Louise Feb 12 '15 at 16:54
  • Ok, i don't see any incompatibily reason, please let me know once you tried another Mojarra version – Tarik Feb 12 '15 at 17:37
  • See updates on question. I reduced the example to one form. We ran it in a different project with Mojarra 2.2.7 and saw the same behaviour. I currently stepping through some more under the hood code, but I'm still rather lost. – Louise Feb 13 '15 at 12:20
  • Wich browsers are you using to test that ? – Tarik Feb 13 '15 at 12:46
  • Usually Chrome. Just checked in Firefox and IE8 - same behaviour. – Louise Feb 16 '15 at 14:10
  • Don't know if that's how this is done around here, but I rewarded the bounty for your efforts before it expires. – Louise Feb 16 '15 at 14:11
  • @Louise me too I don't know how the bounties work. However, I still doubt some state saving issue, could you try adding ` javax.faces.STATE_SAVING_METHOD client ` to your `web.xml` – Tarik Feb 16 '15 at 22:25
  • @Louise so from Michal Petrov's answer seems I'm right on the state saving issue ;) and thanks that you tracked that issue and you updated us – Tarik Feb 25 '15 at 15:49