Hi Tonio,
My backing bean is in the session, and the way I populate the List is via in the
getter method for the property. The full class code is below. Note I use the
Spring framework, so alot of my dependencies are wired using Spring. For the
life of me, I cannot figure out why the selection does not get bound to the
property. Also, beneath the java code is my faces-config.xml entry for this
class.
public class SelectNewControlDeviceTypePage
{
/**
* Default no-args constructor
*/
public SelectNewControlDeviceTypePage() {}
// BUSINESS LOGIC
public String chooseDevice()
{
logger.info("Received a request from the JSF View to forward to
the view associated with the chosen licensed controller.");
if (this.getChosenDevice() == null)
{
logger.debug("#####################chosenDevice is
null");
}
if (this.getChosenDevice().equals(this.ILON100))
{
logger.info("Forwarding to view associated with Licensed
Controller: " + this.ILON100);
return this.CHOOSEILON100;
}
else if (this.getChosenDevice().equals(this.CARRIERDDE))
{
logger.info("Forwarding to view associated with Licensed
Controller: " + this.CARRIERDDE);
return this.CHOOSECARRIERDDE;
}
else if (this.getChosenDevice().equals(this.HONEYWELL))
{
logger.info("Forwarding to view associated with Licensed
Controller: " + this.HONEYWELL);
return this.CHOOSEHONEYWELL;
}
else
{
logger.info("Forwarding to error view, unknown Licensed
Controller chosen: " + this.getChosenDevice());
return this.ERROR;
}
}
// PROPERTY: controlDeviceEditDelegate
public ControlDeviceEditDelegate getControlDeviceEditDelegate() { return
this.controlDeviceEditDelegate; }
public void setControlDeviceEditDelegate(ControlDeviceEditDelegate
controlDeviceDelegate) { this.controlDeviceEditDelegate = controlDeviceDelegate;
}
// PROPERTY: chosenDevice
public String getChosenDevice() { return this.chosenDevice; }
public void setChosenDevice(String chosenDevice) { this.chosenDevice =
chosenDevice; }
// PROPERTY: licensedDevices
public List getLicensedDevices()
{
if (this.licensedDevices == null)
{
logger.debug("List of licensedDevices is NULL,
retrieving via delegate.");
try
{
this.licensedDevices =
this.controlDeviceEditDelegate.getLicensedControllerList();
}
catch (BaseViewException e)
{
logger.error(e);
this.licensedDevices = new LinkedList();
}
catch (Exception e)
{
logger.error(e);
this.licensedDevices = new LinkedList();
}
catch (Throwable e)
{
logger.error(e);
this.licensedDevices = new LinkedList();
}
logger.debug("Received a List of licensedDevice
SelectItem objects from delegate, list size = " + this.licensedDevices.size());
}
return this.licensedDevices;
}
public void setLicensedDevices(List licensedDevices) {
this.licensedDevices = licensedDevices; }
// Navigation strings
private final String ERROR = "error";
private final String CHOOSEILON100 = "chooseILON100";
private final String CHOOSEHONEYWELL = "chooseHoneywell";
private final String CHOOSECARRIERDDE = "chooseCarrierDDE";
// Device description strings
private final String ILON100 = "Echelon iLON100";
private final String HONEYWELL = "Honeywell";
private final String CARRIERDDE = "Carrier DDE";
// Associations
private ControlDeviceEditDelegate controlDeviceEditDelegate;
// View Properties
private List licensedDevices;
private String chosenDevice = "";
// Private constant member variables
private final Log logger = LogFactory.getLog(this.getClass());
}
<managed-bean>
<managed-bean-name>SelectNewControlDeviceTypePage</managed-bean-name>
<managed-bean-class>com.dv.ocs.jsf.bean.view.page.SelectNewControlDeviceTypePage
</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<managed-property>
<property-name>controlDeviceEditDelegate</property-name>
<value>#{controlDeviceEditDelegate}</value>
</managed-property>
</managed-bean>
-faisal
-----Original Message-----
From: Tonio Caputo [mailto:[EMAIL PROTECTED]
Sent: Monday, June 05, 2006 12:18 PM
To: MyFaces Discussion
Subject: Re: Problem with selectOneMenuItem
Hi Faisal,
I had the same problem, it was because my Backing Bean has request scope, and
my list was not initialized in the constructor method.
The problem was, that as the Backing Bean did not have the list initialized
the "value" of the component was not set.
An easy way to detect this problem is to be sure that your JSP page has
somewhere the tag h:messages.
<h:messages showDetail="table" layout="table"/>
Hope this helps
tonio
On Mon, 2006-06-05 at 11:48 -0700, Faisal Mahmoud wrote:
> Hi All,
>
> I am building a drop down list using the <h:selectOneMenu> tag and all
> the items in the List populate and show up correctly in the drop down
> list. But after the user selects an item in the list and submits the
> form, when I check the property that is specified in the tag's value
> attribute, I get a NullPointerException. My code is below:
>
>
> jsp page:
> <h:selectOneMenu id="selectFromExistingTenants" immediate="true"
> value="#{SelectNewControlDeviceTypePage.chosenDevice}">
> <f:selectItems
> value="#{SelectNewControlDeviceTypePage.licensedDevices}"/>
> </h:selectOneMenu>
>
> Code that builds the java.util.List of javax.faces.model.SelectItem
> objects in the <f:selectItems> value attribute:
> List list = this.licensedControllerDAO.getAllLicensedControllers();
> logger.debug("Retrieved List of LicensedController objects. List size
> = " + list.size()); Iterator iter = list.iterator(); while
> (iter.hasNext()) {
> LicensedController licensedController = (LicensedController)
> iter.next();
> String controllerLabel = licensedController.getLabel();
> SelectItem selectItem = new SelectItem(controllerLabel,
> controllerLabel);
> licensedDevices.add(selectItem);
> logger.debug("Added a SelectItem to the List with controllerLabel
> = " + controllerLabel); }
>
>
> Backing Bean code for the <h:selectOneMenu> tag's value attribute:
> //SelectNewControlDeviceTypePage.java
> private String chosenDevice;
> // PROPERTY: chosenDevice
> public String getChosenDevice() { return this.chosenDevice; } public
> void setChosenDevice(String chosenDevice) { this.chosenDevice =
> chosenDevice; }
>
>
> So what am I doing wrong in my code such that my backing bean property
> is not getting with the chosen item?
>
> Faisal Mahmoud
> www.quidprocode.com
>