P
Piper707
Hi,
I have a situation like this:
A web page has 8 rows of input fields:
First 1: <inputText> Last 1: <inputText>
First 2: <inputText> Last 2: <inputText>
....
....
First 8: <inputText> Last 8: <inputText>
----------------------------------------
Rather than creating 8 different fields for first names and last names,
I want to be able to store all the first names in an Array/ArrayList
and all the last names in another Array/ArrayList.
My backing bean looks like this:
public class BackingBean {
private ArrayList firstNames;
private ArrayList lastNames;
public ArrayTestBean() {}
public ArrayList getFirstNames(){
return values;
}
public void setFirstNames(String firstName) {
firstNames.add(firstName);
}
//similarly for lastNames
}//end of class
How do I go about setting values from the jsf page? This does NOT
work:
<hutputText value="First 1"/>
<h:inputSecret id="first1" value="#{backingBean.firstName[0]"/>
presumably because an arraylist will not understand the [index] syntax.
But if I try to use a simple String array, the JSF shown above will
work, but then the problem is in the setFirstNames method of the
backing bean. How can I get it to set the value for the correct index?
i.e.
public void setFirstNames(String firstName) {
firstNames[how do i get the correct index?] = firstName;
}
Thanks for any help
Rohit.
I have a situation like this:
A web page has 8 rows of input fields:
First 1: <inputText> Last 1: <inputText>
First 2: <inputText> Last 2: <inputText>
....
....
First 8: <inputText> Last 8: <inputText>
----------------------------------------
Rather than creating 8 different fields for first names and last names,
I want to be able to store all the first names in an Array/ArrayList
and all the last names in another Array/ArrayList.
My backing bean looks like this:
public class BackingBean {
private ArrayList firstNames;
private ArrayList lastNames;
public ArrayTestBean() {}
public ArrayList getFirstNames(){
return values;
}
public void setFirstNames(String firstName) {
firstNames.add(firstName);
}
//similarly for lastNames
}//end of class
How do I go about setting values from the jsf page? This does NOT
work:
<hutputText value="First 1"/>
<h:inputSecret id="first1" value="#{backingBean.firstName[0]"/>
presumably because an arraylist will not understand the [index] syntax.
But if I try to use a simple String array, the JSF shown above will
work, but then the problem is in the setFirstNames method of the
backing bean. How can I get it to set the value for the correct index?
i.e.
public void setFirstNames(String firstName) {
firstNames[how do i get the correct index?] = firstName;
}
Thanks for any help
Rohit.