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