This is my first post to the forum.
I am really struggling to get my head around JSF2, things that worked suddenly will stop working because of a tiny change in some bean . Any ways, I am posting a test case that is not working as expected for some reason.
The following form
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.prime.com.tr/ui"
>
<f:view contentType="text/html">
<h:head>
</h:head>
<h:body>
<h:form id="simpleForm">
<!-- The id is prepended here-->
<h:panelGrid id="grid" columns="3">
Name:
<p:inputText id="name" value="#{testController.bean.name}" size="40"/>
<p:message for="name"/>
Value:
<p:inputText id="value" value="#{testController.bean.value}" size="40"/>
<p:message for="value"/>
</h:panelGrid>
<h:panelGrid id="controls" styleClass="controls" style="height:100%">
<h:panelGroup styleClass="controls" >
<p:commandButton
id="saveButton"
value="Save"
actionListener="#{testController.echoBean}"
update="simpleForm:grid"/>
</h:panelGroup>
</h:panelGrid>
</h:form>
<h:form>
<p:commandButton
id="cancelButton"
value="Resest"
actionListener="#{testController.resetBean}"
update="simpleForm:grid"/>
</h:form>
</h:body>
</f:view>
</html>
Code: Select all
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.event.ActionEvent;
/**
* User: fotis
* Date: 18/05/11
* Time: 01:40
*/
@ManagedBean
@ViewScoped
public class TestController {
private Bean bean;
public TestController() {
this.bean = new Bean();
}
public Bean getBean(){
return this.bean;
}
public void resetBean(ActionEvent event){
this.bean = new Bean();
}
public void echoBean(ActionEvent event){
System.out.println("Bean name: "+bean.getName());
System.out.println("Bean value: "+bean.getValue());
}
}
Code: Select all
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
public class Bean{
@NotNull
@Size(min=1)
private String name;
@NotNull
@Size(min=1)
private String value;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
2.) Enter the value for only 1 of the 2 fields and click "Save" the corresponding message shows up fine in my form
3.) After a failed validation in 1 of the 2 fields, click the "Reset" button, the action is called in the "TestController", the error messages are cleared from the form, the bean values are "null" but the p:inputText to which you have submitted any values for, still remains, and it is not cleared.
I would like to know if this is the expected behaviour, it seems to me that since the Bean values are null, then the p:inputText should not contain any data.
I am eagerly waiting for any replys.
Best Regards,
Fotis
My Configuration:
Mojarra 2.1.1-b04
Tomcat 7
Primefaces 2.2 (Maven)
java version "1.6.0_24"
Java(TM) SE Runtime Environment (build 1.6.0_24-b07-334-10M3326)
Java HotSpot(TM) 64-Bit Server VM (build 19.1-b02-334, mixed mode)