You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by "kishore.sadanandam" <ki...@gmail.com> on 2010/04/06 12:27:46 UTC
issue with setting backing bean values
Hi,
I have an issue using <tr:subform> component in my JSF page.
Issue:
When I have a submit button in my form outside all subforms, on clicking
this button components inside subform are not set with values in my backing
bean.
Reproduce steps:
1. Create a new JSF page, say SubformTest.jspx, as below.
<?xml version='1.0' encoding='windows-1252'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:tr="http://myfaces.apache.org/trinidad"
xmlns:trh="http://myfaces.apache.org/trinidad/html">
<jsp:output omit-xml-declaration="true" doctype-root-element="HTML"
doctype-system="http://www.w3.org/TR/html4/loose.dtd"
doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN"/>
<jsp:directive.page contentType="text/html;charset=windows-1252"/>
<f:view>
<trh:html>
<trh:head title="Subform test">
<meta http-equiv="Content-Type"
content="text/html; charset=windows-1252"/>
</trh:head>
<trh:body>
<tr:form id="MainForm1">
<tr:messages/>
<tr:subform id="SubForm1">
<tr:panelFormLayout>
<tr:inputText id="FirstNameInput" label="First Name"
required="true"
value="#{SubformPageBean.firstName}"/>
<tr:inputText id="MiddleNameInput" label="Middle Name"
value="#{SubformPageBean.middleName}"/>
<tr:inputText id="LastNameInput" label="Last Name"
required="true"
value="#{SubformPageBean.lastName}"/>
</tr:panelFormLayout>
<tr:commandButton text="Apply 1" id="ApplyButton1"
action="#{SubformPageBean.apply1}"/>
</tr:subform>
<tr:subform id="SubForm2">
<tr:panelFormLayout>
<tr:inputText id="Address" label="Address"
value="#{SubformPageBean.address}"/>
</tr:panelFormLayout>
<tr:commandButton text="Apply 2" id="ApplyButton2"
action="#{SubformPageBean.apply2}"/>
</tr:subform>
<tr:commandButton text="Apply" id="ApplyButton"
action="#{SubformPageBean.apply}"/>
</tr:form>
</trh:body>
</trh:html>
</f:view>
</jsp:root>
2. Create managed bean "SubformPageBean" in request scope with new class
apache.trinidad.test.SubformPageBean
3. Create managed bean "SubformPageBean" Java class as below:
public class SubformPageBean {
private String firstName;
private String middleName;
private String lastName;
private String address;
public SubformPageBean() {
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getFirstName() {
return firstName;
}
public void setMiddleName(String middleName) {
this.middleName = middleName;
}
public String getMiddleName() {
return middleName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getLastName() {
return lastName;
}
public void setAddress(String address) {
this.address = address;
}
public String getAddress() {
return address;
}
public String apply(){
System.out.println("Clicked: apply");
printValues();
return null;
}
public String apply1(){
System.out.println("Clicked: apply1");
printValues();
return null;
}
public String apply2(){
System.out.println("Clicked: apply2");
printValues();
return null;
}
public void printValues(){
System.out.println("First Name: "+firstName);
System.out.println("Middle Name: "+middleName);
System.out.println("Last Name: "+lastName);
System.out.println("Address: "+address);
}
}
4. Run created JSF page SubformTest.jspx after deploying it to server.
5. Clicking "Apply 1" button will print values like below in System.out:
[STDOUT] Clicked: apply1
[STDOUT] First Name: Kishore
[STDOUT] Middle Name: Katikala
[STDOUT] Last Name: Sadanandam
[STDOUT] Address: null
6. Clicking "Apply 2" button will print values like below in System.out:
[STDOUT] Clicked: apply2
[STDOUT] First Name: null
[STDOUT] Middle Name: null
[STDOUT] Last Name: null
[STDOUT] Address: Chennai
7. Clicking "Apply" button will print values like below in System.out:
[STDOUT] Clicked: apply
[STDOUT] First Name: null
[STDOUT] Middle Name: null
[STDOUT] Last Name: null
[STDOUT] Address: null
Questions:
In step 7, I am expecting all subform components value set properly since
the button exists in scope of the form.
This kind of behaviour is easily achieved using multiple <tr:form> instead.
Is this a bug with <tr:subform> that require fix? Is there any workaround to
this?
Regards,
Kishore K S
--
View this message in context: http://old.nabble.com/%3Ctr%3Asubform%3E-issue-with-setting-backing-bean-values-tp28149826p28149826.html
Sent from the MyFaces - Users mailing list archive at Nabble.com.