1

I have a big form with many input fields. User has to fill one input field (like a search input) and press command link that fetch data and fill the form. After form is filled programmatically, user can check data, edit it and submit it.

Everything works fine if user acts as described. But, if user tries to submit empty form he gets primefaces validation errors (required fields). And the problem is if he tries to make a search and enters something in inputText as described above and press Search command link there is a problem - only fields that are marked as required and readonly are filled. If I set readonly=true on field that was empty before, from now on it is filled like it should be from the start.

The problem is that I don't want to mark all fields as required or readonly, but I want that fields filled with data also.

xhtml:

<h:body style="vertical-align:middle;margin:auto">
<h:form enctype="multipart/form-data" id="form" >

    <p:outputLabel for="id" value="ID: " />  
    <p:inputText id="id" value="#{myClass.id}"/>

    <p:commandLink id="fill_form" actionListener="#{myClass.fillForm}"  process="@this id" update="num name storage"/>

    <p:outputLabel for="num" value="Quantity:"/>  
    <p:inputText id="num" value="#{myClass.num}" required="true"/>

    <p:outputLabel for="name" value="Product name:"/> 
    <p:inputText id="name" value="#{myClass.name}" readonly="true"/>

    <p:outputLabel for="storage" value="Storage:"/> 
    <p:inputText id="storage" value="#{myClass.storage}"/>

    <p:commandButton value="Submit" id="submit"  update="form" actionListener="#{myClass.saveData}" global="true" styleClass="button"/>

</h:form> 
</h:body>

Bean:

@ManagedBean
@ViewScoped
public class MyClass{

    private long id;
    private int num;
    private String name;
    private String storage;


    public void fillForm() {
    setID(558);
    setNum(10);
    setName("Chair");
    setStorage("XYZ");

    }

    public void saveData() {
        // do stuff
    }

    // getters and setters


}

So, to finish - everything works without problem until I intentionally cause validation error by trying to submit empty form.

And if I try to fill form after that, only required and readonly fields are filled, is that a bug in Primefaces?

If I remove all readonly and required attributes from fields, there is no fields that are filled .

Configuration:

Liferay 6.2 CE GA3, Primefaces 5.3, Liferay Faces 3.2.5-ga6

Marko P
  • 89
  • 1
  • 12
  • Search google for similar problems... like 'reset after validation' etc... – Kukeltje Oct 29 '15 at 11:46
  • Possible duplicate of [Input fields hold previous values only if validation failed](http://stackoverflow.com/questions/14371723/input-fields-hold-previous-values-only-if-validation-failed) – Kukeltje Oct 29 '15 at 11:46
  • Oh and always provide version info, certainly if you suspect bugs. See [ask] and http://www.stackoverflow.com/tags/jsf/info – Kukeltje Oct 29 '15 at 11:48
  • No no, this isn't a duplicate of that problem - my application holds correct data (not previous one or something else) but it isn't showed until I mark input field as required or readonly field. When I set it as required or readonly, it works without problem, but I don't want to have all fields required... – Marko P Oct 29 '15 at 12:02
  • Then try one of these: https://www.google.nl/search?q=stackoverflow+jsf+validation+failed+update+ajax – Kukeltje Oct 29 '15 at 14:26

0 Answers0