I have a string variable (sqlQuery) whose value I want to change based upon the selection made in a dropdown control (a selectone menu, whose selected item is wired to the searchType property). The menu is like so:
<h:selectOneMenu value=”#{BarChartSelectionsBean.searchType}” >
<f:selectItems value=”#{BarChartSelectionsBean.searchTypeItems}” />
</h:selectOneMenu>
In the managed bean, I have the following code that is supposed to evaluate searchType, and set and get a particular string for sqlQuery based upon the searchType selection. It always returns a null pointer exception (even though I know the searchType variable is resolving, as I’m printing it out to the browser):
public void setSqlQuery()
{
if (this.searchType.equals(“consumption”))
{
sqlQuery = “this”;
}
else
{
sqlQuery = “that”;
}
}
public String getSqlQuery()
{
return sqlQuery;
}
I’m baffled. How do I go about modifying the value of the sqlQuery variable based upon the searchType selection made by the user?