Reputation: 1523
I am working on a project and I am not too familiar with JSF so please correct any gaps in this question.
I have a property file that holds the value of the domain...so for example
domain=.com
domain=.net
In my Bean I have this
private String domain;
private String[] domainSelection;
public void initProp(){
try {
Configuration config = new PropertiesConfiguration("prop.properties");
domainSelection = config.getStringArray("domain");
} catch (ConfigurationException e) {
Log.error("Error");
}
}
In the .jsp
page with the JSF I have
<rich:select id="domain" value="#{Bean.domain}"
required="true">
<f:selectItems itemValue="#{Bean.domainSelection}" />
</rich:select>
When I debug this, I get two value in domainSelection but I need to get them over to the JSF and I can't figure out how to do that.
Upvotes: 0
Views: 137
Reputation: 14943
Sorry for the initial answer I missed the question completely.
private List<SelectItem> domains = new ArrayList<SelectItem>();
//for each domain
domains.add("com",firstFromDomainSelection);
domains.add("net",secondFromDomainSelection);
<f:selectItems value="#{Bean.domains}" />
So this requires getDomains
to retrieve them.
Edit:
It is doable I believe as long as you read the properties file again. one thing to keep in mind is that file might be in a .war
already, so you are going to have to figure a way to re-add or just add it to the deployed folder.
Everytime the view wants to get the list it will call getDomains()
that means we should have the logic there to pull the propetries evertime it is called. Might be a slight performance hit because of File IO.
private List<SelectItem> domains;
private Configuration config = new PropertiesConfiguration("prop.properties"); // with accessors
public List<SelectItem> getDomains(){
domains = new ArrayList<SelectItem>();
String[] domainSelection = getConfig().getStringArray("domain");
for(String domain : domainSelection ){
//Define desired logic for the value if its the same (.com) pass the same as value
domains.add( new SelectItem(domain ,domain)); // SelectItem(value, label);
}
return domains;
}
What I would do
Instead of using the properties file I would use a table for the domains and just dynamically add those records to the table and they will be retrieved accordingly. When there are many requests on that view it will probably slow things down-- at least slightly. The other issue to keep in mind is if apache caches those files. Just keep that in mind. Using a db table is safer IMO.
Upvotes: 1