You are not using JSF expression in the correct way. #{locationAndActivities.locations()}
will tell JSF to look for a method called locations()
which you do not have in the bean. When using parentheses you need to use the full name of the method getLocations()
. If you removed the parentheses JSF will look for a getter or a setter of that expression. e.g, locationAndActivities.location
will look for either getLocation()
method if it requires to returns an object, or setLocation(Location location)
if it requires to set an object.
So instead of:
locationAndActivities.locations()
use:
locationAndActivities.locations
or
locationAndActivities.getLocations()
In addition, always avoid doing processes in bean getters and setters. The best practice is to populate the arraylist in the bean right after constructing it (@PostConstruct
).
public class LocationsAndActivities implements Serializable
{
private ArrayList<Location> locations;
private Location location;
@PostConstruct
private void init(){
//fill locations arraylist with data
}
public ArrayList<Location> getLocations(){
return locations;
}
public Location getLocation(){
return location;
}
public void setLocation(Location location){
this.location = location;
}
}
<h:selectOneMenu value="locationAndActivities.location">
<f:selectItem itemLabel="---Select Location---" noSelectionOption="true">
<f:selectItems value="locationAndActivities.locations" var="var" itemValue="var">
</h:selectOneMenu>
Note: Due to HTML Structure, you need to use converter when passing selected Location objects to the bean. Converters are necessary for data types that are not of String types or not of those types that JSF has a built-in converter for (such as int, Integer, Long, long, Double, double... etc). Otherwise you need to use a converter to pass your object back to the bean.
See also: