Richfaces Datatable loses represented value of inputs on validation failure

I have two inputs, one inside "normal" h:dataTable

and one inside a. rich:dataTable

When I submit an invalid value, that is, no validation is performed, "normal" retains the value I submitted, and the other loses it. See the following code snippets (enter any value and click 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 behavior of Richfaces or some kind of bug? Is there a way to make it behave the same as a regular JSF DataTable? Using h:dataTable

this instead is not always an option, and losing the "I-was-just-about-to-correct-it" entry is pretty annoying.

Addition: I just checked the behavior of ui: repeat and a4j: repeat and they are the same thing: ui: repeat retains the passed value while a4j: repeat does not.

UPDATE: Reworked sample code to eliminate some of the possible issues mentioned in the comments (input fields now point to different values, just 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.

+3


source to share


1 answer


I just tried each of form

your pages separately with Richefaces 4.3.7 and Mojarra 2.2.6 and it works great! I didn't notice any abnormal behavior when the check failed, I didn't lose any values. This means that there are no validation issues with Richfaces components.



However, if I use two forms on the same page, I can notice that when we submit the first form of the inputText

second form, it loses its value, and if we submit form2

inputText

from the first form it did not lose its value, in my opinion, because JSF saved the state of its HTML components in javax.faces.ViewState

and does not do the same for Richfaces components, using Firebug

, you can easily verify that the only one common request parameter

between the two POST requests is javax.faces.ViewState

.

+2


source







All Articles