This example demonstrates an overview table with all persions and a detail view for person details.
Click on a person name in the table to go to the corresponding detail view. This detail view has three input fields: Name (required), Tax Class (only number allowed), Birth Date (only date allowed).
Type a wrong data, e.g. Tax Class as string instead of number, and push "Save" button. You will see a validation error.
Both "cancel" buttons force a back navigation to the overview table. Try to click on the first "Regular Cancel" button and select another person in the table.
You will see partially last shown data from the last selected person and not data from the current selected person.
If Tax Class would not pass validation, Name and Birth Date from the last selected person would be shown. The second button with attached pe:resetInput solves this problem.
Source
<h:panelGroup id="personsGroup">
<p:messages/>
<p:dataTable id="persons" value="#{advancedResetInputController.persons}" var="person"
rendered="#{empty advancedResetInputController.selectedPerson}">
<p:column headerText="Name">
<p:commandLink value="#{person.name}"
action="#{advancedResetInputController.showPersonDetails(person)}"
process=":mainForm:personsGroup" update=":mainForm:personsGroup"/>
</p:column>
<p:column headerText="Tax Class">
<h:outputText value="#{person.taxClass}"/>
</p:column>
<p:column headerText="Birth Date">
<h:outputText value="#{person.birthDate}">
<f:convertDateTime pattern="dd.MM.yyyy"/>
</h:outputText>
</p:column>
</p:dataTable>
<h:panelGroup rendered="#{not empty advancedResetInputController.selectedPerson}">
<h:panelGrid id="personDetail" columns="2" columnClasses="formColumn1,formColumn2">
<h:outputText value="Name (string)"/>
<h:inputText value="#{advancedResetInputController.selectedPerson.name}"
required="true" label="Name"/>
<h:outputText value="Tax Class (number)"/>
<h:inputText value="#{advancedResetInputController.selectedPerson.taxClass}"
required="true" label="Tax Class">
<f:validateLength maximum="1"/>
</h:inputText>
<h:outputText value="Birth Date (date dd.MM.yyyy)"/>
<h:inputText value="#{advancedResetInputController.selectedPerson.birthDate}"
required="true" label="Birth Date">
<f:convertDateTime pattern="dd.MM.yyyy"/>
</h:inputText>
</h:panelGrid>
<p:commandButton value="Save" action="#{advancedResetInputController.updatePersonDetails}"
process="personsGroup" update="personsGroup"
style="margin-top: 10px;" icon="ui-icon-disk"/>
<p:commandButton value="Regular Cancel" action="#{advancedResetInputController.cancelPersonDetails}"
update="personsGroup" immediate="true" icon="ui-icon-close"/>
<p:commandButton value="Cancel with pe:resetInput"
action="#{advancedResetInputController.cancelPersonDetails}"
update="personsGroup" immediate="true" icon="ui-icon-close">
<pe:resetInput for="personDetail"/>
</p:commandButton>
</h:panelGroup>
</h:panelGroup>
public class Person implements Serializable {
private static final long serialVersionUID = 20111128L;
private String id;
private String name;
private int taxClass;
private Date birthDate;
private Set<String> languageSkills = new HashSet<String>();
public Person(String id, String name, int taxClass, Date birthDate) {
this.id = id;
this.name = name;
this.taxClass = taxClass;
this.birthDate = birthDate;
}
public String getId() {
return id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getTaxClass() {
return taxClass;
}
public void setTaxClass(int taxClass) {
this.taxClass = taxClass;
}
public Date getBirthDate() {
return birthDate;
}
public void setBirthDate(Date birthDate) {
this.birthDate = birthDate;
}
public String[] getLanguageSkills() {
return languageSkills.toArray(new String[languageSkills.size()]);
}
public void addLanguageSkill(String languageSkill) {
languageSkills.add(languageSkill);
}
}