I have an JSF 2.0 application that has a bean that holds a list of Strings.
I want to add the String from an <h:inputText>/> to my List and display my list.
The following code just put references in my List. So every element from my List is set to the last input.
@ManagedBean
@ApplicationScoped
public class Bean {
private String name;
private ArrayList<String> test = new ArrayList<String>();
public Bean() {
}
public Bean(String name) {
this.name = name;
}
public String addtoList(String _name){
test.add(_name);
return "./index.xhtml";
}
/***************GETTER/SETTER/HASHCODE/EQUALS**************************/
...
}
here a part of my index.xhtml:
<h:inputText id="name"
value="#{bean.name}"
required="true">
</h:inputText>
<h:commandButton value="Post"
action="#{bean.addtoList(name)}"/>
<br/>
<h:dataTable var="bean"
value="#{bean.test}">
<h:column>
<h:outputText value="#{bean.name}"/>
</h:column>
</h:dataTable>

public void addtoList(String _name){ test.add(_name); return "./index.xhtml"; }This shouldn't compile... what's your exception?