Hi,
I am using navigation to load another JSP according to what was selected in the drop down. However in the getPageToDisplay method below, the selectedItem is null and there is a null pointer exception. So I get an error "Error calling action method of component...".
Does anyone have any idea how to fix this?
Thanks.
The Form bean is below:
import java.util.ArrayList;
import java.util.List;
import javax.faces.model.SelectItem;
public class TableForm {
private List<SelectItem> tables = new ArrayList<SelectItem>();
public TableForm() {
tables.add(new SelectItem("Table 1", "1"));
tables.add(new SelectItem("Table 2", "2"));
}
private SelectItem selectedTable = null;
public SelectItem getSelectedTable() {
return selectedTable;
}
public void setSelectedTable(SelectItem selectedTable) {
this.selectedTable = selectedTable;
}
public List getTables() {
return tables;
}
public String getPagetoDisplay() {
if (selectedTable.getLabel().equals("1")) {
// Null pointer exception here
System.out.println("Inside 1");
return "displaytable1";
}
else if (selectedTable.getLabel().equals("2")) {
return "displaytable2";
}
else return "";
}
}
The JSP file is:
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<f:view>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD><TITLE>Plain Table</TITLE>
<LINK REL="STYLESHEET"
HREF=""> TYPE="text/css">
</HEAD>
<BODY>
<CENTER>
<TABLE BORDER=5>
<TR><TH CLASS="TITLE">Plain Table Demo</TH></TR>
</TABLE>
<P>
<h:form>
<h:selectOneMenu required="true">
<f:selectItems value="#{tableform.tables}"/>
</h:selectOneMenu>
<h:commandButton value="Submit" immediate="true" action=""
}"/>
</h:form>
</CENTER></BODY></HTML>
</f:view>
- selectOneMenu and selectItem sample Aneesha Govil
- Re: selectOneMenu and selectItem sample Stefan Puchmann
- Re: selectOneMenu and selectItem sample Aneesha Govil
- Re: selectOneMenu and selectItem sample Stefan Puchmann
- Re: selectOneMenu and selectItem sample Aneesha Govil
- RE: selectOneMenu and selectItem sam... Sanoop Kuniel
- Re: selectOneMenu and selectItem... Stefan Puchmann
- Re: selectOneMenu and select... Aneesha Govil
- Re: selectOneMenu and selectItem... Aneesha Govil
- Re: selectOneMenu and select... Gerald Müllan
- Re: selectOneMenu and select... Aneesha Govil
- Re: selectOneMenu and select... Aneesha Govil
- Re: selectOneMenu and select... Aneesha Govil
- Re: selectOneMenu and select... Gerald Müllan
- Re: selectOneMenu and select... Aneesha Govil

