JSF: using Arrays/ArrayList in the backing bean?

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:

<h:eek:utputText 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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,740
Latest member
AdolphBig6

Latest Threads

Top