Popup panel validation problem
sensationalist May 24, 2011 1:24 PMHi.
I have strange problem with form refreshing and validation. I used richfaces-showcase example (Data Iteration - rich:dataTable - Data Table Edit), but I wanted to use one popup panel for both editing and creating records. But I faced something like bug, so I made the example to show it.
I made popup panel and two links:
<h:form> Press "New" link or "Edit" link. They don't work. Enter some text to fields and they will begin to work. <a4j:commandLink oncomplete="#{rich:component('beanPanel')}.show()" action="#{testBean.cleanBean}" render="beanPanel" > New </a4j:commandLink> <a4j:commandLink oncomplete="#{rich:component('beanPanel')}.show()" action="#{testBean.editBean}" render="beanPanel" > Edit </a4j:commandLink> <rich:popupPanel header="Test bean form" id="beanPanel" autosized="true" domElementAttachment="parent"> <rich:messages ajaxRendered="true" globalOnly="true" /> <h:panelGrid columns="3" id="userGrid"> <h:outputText value="Field1:" /> <h:inputText id="field1" label="Field1" value="#{testBean.bean.field1}" required="true"> <f:validateLength minimum="3" /> </h:inputText> <rich:message for="field1" ajaxRendered="true" /> <h:outputText value="Field2:" /> <h:inputText id="field2" label="Field2" value="#{testBean.bean.field2}" required="true"> <f:validateLength minimum="3" /> </h:inputText> <rich:message for="b" ajaxRendered="true" /> <h:outputText value="Field3:" /> <h:inputText id="field3" label="Field3" value="#{testBean.bean.field3}" /> <rich:message for="field3" ajaxRendered="true" /> </h:panelGrid> <a4j:commandButton value="Cancel" onclick="#{rich:component('beanPanel')}.hide(); return false;" /> </rich:popupPanel> </h:form>
Also I made test bean:
@ManagedBean(name = "testBean") @ViewScoped public class TestBean { public void editBean() { bean = beanToEdit; } public void cleanBean() { bean = new Bean(); } Bean bean = new Bean(); Bean beanToEdit = new Bean("val_a", "val_b", "val_c"); public Bean getBean() { return bean; } public void setBean(Bean bean) { this.bean = bean; } } public class Bean { public Bean() { } public Bean(String a, String b, String c) { this.field1 = a; this.field2 = b; this.field3 = c; } String field1; String field2; String field3; public String getField1() { return field1; } public void setField1(String a) { this.field1 = a; } public String getField2() { return field2; } public void setField2(String b) { this.field2 = b; } public String getField3() { return field3; } public void setField3(String c) { this.field3 = c; } }
And what we have here? Edit button don't works at all. All buttons show panel with validation message on first field. BUT if we write something to the fields and press "Cancel" then the buttons will work! Edit will show the values, and New link will erase it. But only first time.What is more strange, that in my application the same example works in another way: "Edit" button works good (may be by <f:setPropertyActionListener target="#{testBean.bean}" value="#{anotherBean}" />) but if I press "New" button first, then panel shows validation messages and both buttons become useless
So all I want:
1. To see empty fields and no validation messages on "New" link click.
2. See filled fields on "Edit" link click.
What must I do to get it?