• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Integration problems using h:selectOneMenu

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using JSF 1.1_01 (MyFaces 1.1), Spring 1.2, Ajax4Jsf.
The JSF application has h:selectOneMenu .

On change event of h:selectOneMenu sets "selectedValue" in backing bean as shown below:

------------------
page.jsp
-------------------

<h:selectOneMenu value="#{test.selectedDevice}" >

<f:selectItem itemValue="0" itemLabel="--New--"/>
<f:selectItem itemValue="1" itemLabel="WorkStation"/>
<f:selectItem itemValue="2" itemLabel="Router"/>
<f:selectItem itemValue="3" itemLabel="Switch"/>
<ajax:support action="#{test.loadDevice}" event="onchange" reRender="t2,t3,t4,t5"/>
</h:selectOneMenu>

-----------------------
TestBean.java (Backing Bean)
-----------------------

public String getSelectedDevice() {
logger.info(" *** In getSelectedDevice *** ");
if (selectedDevice == null) {

selectedDevice = "0"; // This will be the default selected item.
}
return selectedDevice;
}


public void setSelectedDevice(String selectedDevice) {
logger.info(" *** In setSelectedDevice *** ");
this.selectedDevice = selectedDevice;
}

Here are the configuration files for integrating JSF Spring
-------------
web.xml
-------------
<listener>
<listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
</listener>

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>

---------------------------
faces-config.xml
---------------------------
<application>
<variable-resolver>org.springframework.web.jsf.DelegatingVariableResolver</variable-resolver>
</application>

<managed-bean>
<managed-bean-name>test</managed-bean-name>
<managed-bean-class>test.TestBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
<managed-property>
<property-name>deviceManager</property-name>
<property-class> test.DeviceTypeManager </property-class>
<value>#{deviceManager}</value>
</managed-property>
</managed-bean>

The above code results in the following error

javax.faces.FacesException: Cannot get value for expression '#{test.selectedDevice}'

The error occurs only if i include <managed-property> inside the <managed-bean> in faces-config.xml.
The moment i remove <managed-property> from face-config.xml the error disappears & page gets rendered properly.

The purpose in using <managed-property> is to integrate JSF with Spring i.e. calling deviceManager

Any pointers/suggestions in resolving the error will be highly appreciated

Regards
Bansi
 
Bansilal Haudakari
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The TestBean do have a property for DeviceManager along with setter/getter methods as shown below. Sorry for not including in earlier posting

--------------
TestBean.java (Backing Bean)
---------------
private DeviceTypeManager deviceManager;
public DeviceTypeManager getDeviceManager() {
return deviceManager;
}


public void setDeviceManager(DeviceTypeManager deviceManager) {
this.deviceManager = deviceManager;
}


Here are the two scenarios

Scenario 1 : without <managed-property> the code works fine

Scenario 2 : with <managed-property> the code results in following error

javax.faces.FacesException: Cannot get value for expression '#{test.selectedDevice}'


Scenario 1 has only JSF whereas Scenario 2 has JSF-Spring integration

The Scenario 1 works absolutely fine as the expression '#{test.selectedDevice}' gets its value from setter/getter method in the backing bean(TestBean.java) . This is expected behaviour & wondering why it doesn't work similarly in Scenario 2 instead complains
Cannot get value for expression '#{test.selectedDevice}'

I am willing to upload the war file. Any pointers/suggestions in resolving the error will be highly appreciated

Regards
Bansi
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
I am using the bean name to get the value in h:selectOneMenu.
Here is my code, which is working fine.....
In JSf page,

<h:selectOneMenu id="usage" value="#{registrationBean.usage}" styleClass="labelTextBlack"
<f:selectItems value="#{registrationBean.usageList}"/>
<a4j:support event="onchange" action="#{registrationBean.changeUsage}" reRender="plateType,plateClass,expiration,issueYear1"></a4j:support>
</h:selectOneMenu>

The Backing Bean has....

public class RegistrationBean extends BaseManagedBean implements Serializable {
private RegistrationService registrationService;

private ActivityInfoBean activityInfoBean;

public RegistrationService getRegistrationService() {
return registrationService;
}

public void setRegistrationService(RegistrationService registrationService) {
this.registrationService = registrationService;
}

public ActivityInfoBean getActivityInfoBean() {
return activityInfoBean;
}

public void setActivityInfoBean(ActivityInfoBean activityInfoBean) {
this.activityInfoBean = activityInfoBean;
}

public String getUsage() {
return usage;
}

public void setUsage(String usage) {
this.usage = usage;
}

}

In faces-config....

<managed-bean>
<managed-bean-name>registrationBean</managed-bean-name>
<managed-bean-class>us.tn.state.trust.presentation.beans.RegistrationBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
<managed-property>
<property-name>activityInfoBean</property-name>
<value>#{activityInfoBean}</value>
</managed-property>
<managed-property>
<property-name>registrationService</property-name>
<value>#{registrationService}</value>
</managed-property>
</managed-bean>


cheers
Rajani
 
rajani varma
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry, I forgot to include the web.xml and applicationContext.xml contents...

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">


<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext.xml
</param-value>
</context-param>

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>

</web-app>

and you have to include the spring bean in applicationContext.xml as...

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>

<bean id="registrationService" class="us.tn.state.trust.service.RegistrationServiceImpl">
</bean>

</beans>

Cheers,
Rajani
 
rajani varma
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In web.xml, you have to define the listener so that Spring initializes itself on application startup:


and


for defining the faces-config.xml

Cheers,
Rajani
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic