Win a copy of Spring Boot in Practice this week in the Spring forum!

Bansilal Haudakari

Greenhorn
+ Follow
since Jun 28, 2004
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Bansilal Haudakari

I have a h:selectOneMenu dropdown which performs CRUD operation.
The dropdown list has a value "New" which allows the users to enter new values into other form fields thereby performing Create/Insert operation
When users pick other values from the dropdown list it dynamically populates other fields in the form thereby facilitating Update/Delete operation. The problem is whenever i pick a different value from the dropdown list the database call happens twice.

Here is the dropdown
Code:


<h:selectOneMenu id="manufList" value="#{manufacturerBean.selectedManufacturer}" >
<f:selectItem itemLabel="New" itemValue="New" />
<f:selectItems value="#{manufacturerBean.manufacturerList}" />
<a4j:support action="#{manufacturerBean.loadManufacturerDetails}" event="onchange" reRender="manufName,manufDescription,manufSource,btnSave,btnDelete" />
</h:selectOneMenu>
</h:panelGrid>




Here is the sequence of method calls whenever i pick a value from the dropdown list
- First time the method in f:selectItems gets called which results in a database call
<f:selectItems value="#{manufacturerBean.manufacturerList}" />
- Second time Ajax4JSF onchange event action method gets called .
<a4j:support action="#{manufacturerBean.loadManufacturerDetails}" event="onchange" reRender="manufName,manufDescription,manufSource,btnSave,btnDelete" />
- Third time again the method in f:selectItems gets called which results in a database call
<f:selectItems value="#{manufacturerBean.manufacturerList}" />

Here are my concerns
- Just picking a value from the dropdown shouldn't result in a call to database especially when there are no changes made to database

- I expect the calls to database happens ONLY in case of users click Save/Update/Delete buttons i.e. dropdown dynamically refreshes with database values

Here are the snippets from log file which substantiates that whenever i pick a value from dropdown
database call occurs twice
Code:

********** FIRST METHOD CALL ***************************
2007-05-07 16:46:46,002 INFO [com.boeing.nmt.nams.view.bean.ManufacturerBean] - < *** In getManufacturerList Backing Bean*** >
2007-05-07 16:46:46,002 INFO [com.boeing.nmt.nams.service.impl.ManufacturerManagerImpl] - < *** In getManufacturerList Spring*** >
Hibernate: select namsmanufa0_.ID as ID60_, namsmanufa0_.CHANGE_USER as CHANGE2_60_, namsmanufa0_.NA
ME as NAME60_, namsmanufa0_.DESCRIPTION as DESCRIPT4_60_, namsmanufa0_.SOURCE as SOURCE60_, namsmanu
fa0_.STATUS as STATUS60_, namsmanufa0_.CHANGE_DATE as CHANGE7_60_ from NAMS_MANUFACTURER namsmanufa0
_

********** SECOND METHOD CALL ***************************
2007-05-07 16:46:46,237 INFO [com.boeing.nmt.nams.view.bean.ManufacturerBean] - < *** In loadManufacturerDetails method *** >
Hibernate: select namsmanufa0_.ID as ID60_0_, namsmanufa0_.CHANGE_USER as CHANGE2_60_0_, namsmanufa0
_.NAME as NAME60_0_, namsmanufa0_.DESCRIPTION as DESCRIPT4_60_0_, namsmanufa0_.SOURCE as SOURCE60_0_
, namsmanufa0_.STATUS as STATUS60_0_, namsmanufa0_.CHANGE_DATE as CHANGE7_60_0_ from NAMS_MANUFACTUR
ER namsmanufa0_ where namsmanufa0_.ID=?

********** THIRD METHOD CALL ***************************
2007-05-07 16:46:46,565 INFO [com.boeing.nmt.nams.view.bean.ManufacturerBean] - < *** In getManufacturerList Backing Bean*** >
2007-05-07 16:46:46,565 INFO [com.boeing.nmt.nams.service.impl.ManufacturerManagerImpl] - < *** In getManufacturerList Spring*** >
Hibernate: select namsmanufa0_.ID as ID60_, namsmanufa0_.CHANGE_USER as CHANGE2_60_, namsmanufa0_.NA
ME as NAME60_, namsmanufa0_.DESCRIPTION as DESCRIPT4_60_, namsmanufa0_.SOURCE as SOURCE60_, namsmanu
fa0_.STATUS as STATUS60_, namsmanufa0_.CHANGE_DATE as CHANGE7_60_ from NAMS_MANUFACTURER namsmanufa0
_



I do have Managed Bean in Session scope

Regards
Bansi
15 years ago
JSF
Here is my requirement

The user creates new record by selecting "New" value from the dropdown. Then user enters values on form fields and clicks the Submit button. The result is new Record gets created in the database and also gets populated in the dropdown. But the dropdown still shows the "New" value whereas I want the drop down to dynamically change from "New" to newly created value in the drop down

The dropdown is populated from the database as shown below

<h:outputText value="Manufacturer" /> <h:selectOneMenu id="manufList" value="#{manufacturerBean.selectedManufacturer}" > <f:selectItem itemLabel="New" itemValue="New" /> <f:selectItems value="#{manufacturerBean.manufacturerList}" /> <a4j:support action="#{manufacturerBean.loadManufacturerDetails}" event="onchange" reRender="t3,t4,t5,t6,t7,t8,t9,t10" /> </h:selectOneMenu>




Here is the backing bean

public List getManufacturerList(){ logger.info(" *** In getManufacturerList Backing Bean*** "); List<Manufacturer> models = new ArrayList<Manufacturer>(); List<SelectItem> manufacturers = new ArrayList<SelectItem>(); models = manufManager.getManufacturerList(); logger.info(" *** manufManager List Size=*** "+models.size()); for (Iterator it = models.iterator(); it.hasNext();) { Object[] row = (Object[]) it.next(); manufacturers.add(new SelectItem(row[0]+"",row[1]+"")); } return manufacturers; }





Any pointers/suggestions will be highly appreciated
Regards
Bansi
15 years ago
JSF
I have developed simple CRUD application using JSF, Facelets, Ajax4JSF, Spring & Hibernate based on Appfuse/Equinox framework. After making the application to work successfully i am wondering whether i have used the best practices. Here is an example

" Is it recommended to instantiate Model object in Backing bean"

To elaborate the statement .........

I have the following

UserForm is a JSF managed bean,
User is a hibernate mapped POJO, and
UserManager is manager class in Spring
------------------------
UserForm.java (Backing Bean)
----------------------------
public class UserForm {
.........
.........
public User user = new User();
public UserManager mgr;
.............
.............
// Getter & Setter methods for user & mgr
....................
....................
//Persistence
public String save() {
mgr.saveUser(getUser());
addMessage("user.saved", getUser().getFullName());

return "success";
}
}

I undertand the purpose of having UserManager defined in backing bean but wondering why do we need to have Model (i.e. User) defined in backing bean . Is this a best practice?


Is it recommended to populate model object with data in the backing bean and then call for business methods like mgr.saveUser(getUser()



I am wondering about perfomance issues i.e. making DB calls from backing bean getters or setters. DB calls can mean a performance hit, and JSF will call the getters and setters multiple times per page request (which means you'll be doing multiple DB calls).



Regards

Bansi
15 years ago
JSF
Hibernate version: 3.1.2

Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class name="test.DeviceType" table="DEVICE_TYPE">
<id name="id" column="ID" unsaved-value="0" >
<generator class="increment"/>
</id>

<property name="deviceType">
<column name="NAME" />
</property>

<property name="description">
<column name="DESC" />
</property>

<set name="roles" table="DEVICETYPE_ROLES" inverse="true" cascade="all">
<key column="DEVICETYPE_ID" />
<many-to-many column="ROLE_ID" class="test.Role"/>
</set>

</class>

<class name="test.Role" table="ROLE">
<id name="id" column="ID">
<generator class="assigned">
</generator>
</id>

<property name="name" column="NAME" />

</class>



</hibernate-mapping>




Code between sessionFactory.openSession() and session.close():
package test;

import java.util.List;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.dao.DataAccessException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.orm.ObjectRetrievalFailureException;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Query;
import org.hibernate.SQLQuery;
import org.springframework.dao.DataAccessException;
import org.hibernate.HibernateException;



public class DeviceDao {

private HibernateTemplate hibernateTemplate;
protected final Log logger = LogFactory.getLog(getClass());

public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
logger.info(" *** In setHibernateTemplate method *** ");
this.hibernateTemplate = hibernateTemplate;
}
public void persist(DeviceType dt) {
logger.info(" *** In persist method *** ");
System.out.println(" *** In persist method *** ");
// System.out.println("***ID="+dt.getId()+"***DeviceType="+dt.getDeviceType()+"***Desc="+dt.getDescription());
// hibernateTemplate.save(dt);
System.out.println("***ID="+dt.getId()+"***DeviceType="+dt.getDeviceType()+"***Desc="+dt.getDescription()+"***Role Size="+dt.getRoles().size());
hibernateTemplate.save(dt);
System.out.println("ID***="+dt.getId());
}
public void update(DeviceType instance) {
hibernateTemplate.update(instance);
}
public void remove(Long deviceTypeId) {
Object device = hibernateTemplate.load(DeviceType.class, deviceTypeId);
hibernateTemplate.delete(device);
}



public List getDeviceTypes() throws DataAccessException {

return (List) hibernateTemplate.execute(new HibernateCallback() {
public Object doInHibernate(Session session) throws HibernateException {
String sql = "select dt.id, dt.deviceType from DeviceType dt";
Query query = session.createQuery(sql);
return query.list();
}
});

}

public DeviceType getDeviceType(Long id) {
System.out.println("***In DeviceDao selectedDevice***"+id);
DeviceType dt = (DeviceType) hibernateTemplate.get(DeviceType.class, id);
if (dt == null) {
throw new ObjectRetrievalFailureException(DeviceType.class, id);
}
return dt;
}

}




Full stack trace of any exception that occurs:
2007-01-19 12:14:03,759 ERROR [org.hibernate.property.BasicPropertyAccessor] - <IllegalArgumentException in class: test.Role, getter method of property: id>
2007-01-19 12:14:03,759 WARN [test.TestBean] - <IllegalArgumentException occurred calling getter of test.Role.id; nested exception is org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of test.Role.id>



Name and version of the database you are using:
HSQLDB


The generated SQL (show_sql=true):
Expected to generate following SQL statements but it doesn't due to Error
insert into DeviceType_Roles(DeviceType_id, Tole_Id) values (?, ?)
insert into Device_Type(Id, Name, Desc) values(?,?,?)



Debug level Hibernate log excerpt:
2007-01-19 12:14:03,759 ERROR [org.hibernate.property.BasicPropertyAccessor] - <IllegalArgumentException in class: test.Role, getter method of property: id>
2007-01-19 12:14:03,759 WARN [test.TestBean] - <IllegalArgumentException occurred calling getter of test.Role.id; nested exception is org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of test.Role.id>





Problems with Session and transaction handling?
Nope

Scenario :
Its an example of Many-To-Many Object Relationship i.e. DeviceType object is associated with Roles object. Here is the snippet
DeviceType dt = new DeviceType();
dt.setDeviceType(deviceType);
dt.setDescription(description);
dt.setRoles(deviceRoles);
deviceDao.persist(dt); // In Business Layer
Please not deviceRoles is Set of Roles.
deviceDao.persist(dt); results in call to Hibernate Layer and executes hibernateTemplate.save(dt);

Expected Results:
To persist DeviceType object along with set of Roles into DeviceType table and DeviceType_Roles table as shown below
insert into DeviceType_Roles(DeviceType_id, Tole_Id) values (?, ?)
insert into Device_Type(Id, Name, Desc) values(?,?,?)

Observed Results:
IllegalArgumentException occurred calling getter method of property: id>

Any pointers/suggestions will be highly appreciated

Regards
Bansi
The following code in Add Role method results in error
public String addRole() {
deviceRoles.addAll(selectedUserRoles);
return null;
}

ERROR:
javax.faces.FacesException: Collection referenced by UISelectItems with binding

'#{test.deviceRoles}' and Component-Path : {Component-Path : [Class:

org.ajax4jsf.framework.ajax.AjaxViewRoot,ViewId: /page.jsp][Class:

javax.faces.component.html.HtmlForm,Id: _id0][Class:

org.ajax4jsf.ajax.html.HtmlAjaxOutputPanel,Id: _id6][Class:

javax.faces.component.html.HtmlPanelGrid,Id: _id13][Class:

javax.faces.component.html.HtmlSelectManyListbox,Id: _id19][Class:

javax.faces.component.UISelectItems,Id: _id20]} <b>does not contain Objects of type

SelectItem
</b>


I fixed the error by hardcoding the values into Add Role method as shown below

public String addRole() {

deviceRoles.add(new SelectItem("10"," Admin"));
deviceRoles.add(new SelectItem("20"," Focal"));
deviceRoles.add(new SelectItem("30","Architect"));

return null;
}

So I guess the call to "selectedUserRoles" in deviceRoles.addAll(selectedUserRoles); should

return instances of SelectItem with Id and Value as arguments.

That means whenever users selects multiple values from user roles h:selectManyList box, the setselectedUserRoles() method should recieve both Id and Value as instance of Select Item.

Hence i changed the declaration to
private List selectedUserRoles = new ArrayList<SelectItem>();

But not sure how to change the defination of setselectedUserRoles() method to recieve instances of SelectItem with Id and Value as Arguments. Here is the defination

public void setSelectedUserRoles(List selectedUserRoles) {
this.selectedUserRoles = selectedUserRoles;
System.out.println("Setter this.selectedUserRoles "+ this.selectedUserRoles);}




Any pointers/suggestions will be highly appreciated in this regard.
Here is the code snippet in backing bean :

--------------------------------
TestBean.java (Backing Bean)
------------------------------------
private List<Role> userRoles;
private List deviceRoles = new ArrayList<SelectItem>();
private List selectedUserRoles = new ArrayList<SelectItem>();
private List selectedDeviceRoles = new ArrayList<SelectItem>();


public List getSelectedUserRoles() {
System.out.println("Getter this.selectedUserRoles"+selectedUserRoles);
return selectedUserRoles;
}



public void setSelectedUserRoles(List selectedUserRoles) {
this.selectedUserRoles = selectedUserRoles;
System.out.println("Setter this.selectedUserRoles "+ this.selectedUserRoles);}


public String addRole() {
deviceRoles.addAll(selectedUserRoles);
return null;
}

Regards
Bansi
15 years ago
JSF
selectManyListBox to add/remove user Roles

I am using JSF (MyFaces 1.1.1) component h:selectManyListBox along with Ajax4Jsf to add/remove user Roles.


I have created page called page.jsp as follows (need help in filling the code):

. . . .

<h:panelGrid columns="4" style="">
<h:outputText value="User Roles" />
<h:selectManyListbox id="userRoles" value="#{test.selectedRoles}">
<f:selectItems value="#{test.allAvailableRoles}" />
</h:selectManyListbox>

<h:commandButton value="Add"></h:commandButton>
<h:commandButton value="Remove"></h:commandButton>

<h:outputLabel value="Device Roles" />
<h:selectManyListbox>

</h:selectManyListbox>
</h:panelGrid>
</ajax:outputPanel>
. . . .


It uses managed bean called TestBean.java

public class TestBean {
private List<SelectItem> allAvailableRoles;
String[] selectedRoles;
public List getAllAvailableRoles(){
logger.info(" *** In getAllAvailableRoles Backing Bean*** ");
System.out.println(" *** In getAllAvailableRoles Backing Bean*** ");
allAvailableRoles = new ArrayList<SelectItem>();
List<Role> allRoles = new ArrayList<Role>();
allRoles = ( List ) deviceManager.getUserRoles(); //call to business layer to retrieve user roles from database
//System.out.println("Role Size"+allRoles.size());
//Iterate All Roles to create a SelectItem and add it to the list that will fill theSelectManyListbox
for ( Role role : allRoles ){

SelectItem item = new SelectItem();
item.setValue( ""+role.getId() );
item.setLabel( role.getName() );

allAvailableRoles.add( item );
}
selectedRoles = (String[])selectedRoles.toArray();
return allAvailableRoles;

}


public String[] getSelectedRoles() {
return selectedRoles;
}


public void setSelectedRoles(String[] selectedRoles) {
this.selectedRoles = selectedRoles;
}
}

I need help with the following:
1) The Layout of JSP page has to render
User Roles (h:selectManyListBox), Add and Remove Buttons, Device Roles (h:selectManyListBox) in a single colums. I am using <h:PanelGrid columns=4> . But i wanna Remove button to display in next row of Add button

2) I am looking for sample code for adding functionality to Add/Remove Buttons.

The Add button adds the selected user roles to Device Roles whereas Remove button removes the selected user roles from Device Roles to User Roles

Thanks for your time in advance

Regards
Bansi
15 years ago
JSF
I am having problems with JSF 1.1_01 (MyFaces 1.1.1).

I have created page called page.jsp as follows:

. . . .

<h:selectOneMenu value="#{test.selectedDevice}" id="deviceTypeList" styleClass="dropdown">
<f:selectItems value="#{test.deviceTypes}" />

<ajax:support action="#{test.loadDevice}" event="onchange" reRender="t2,t3,t4,t5"/>
</h:selectOneMenu>
. . . .

It is uses managed bean called TestBean.java:

public class TestBean {

public List getDeviceTypes(){
logger.info(" *** In getDeviceTypes Backing Bean*** ");
List<SelectItem> models = new ArrayList<SelectItem>();
List<SelectItem> deviceTypes = new ArrayList<SelectItem>();
// Gets Data from Hibernate Query . It returns List of Device Types
models = deviceManager.getDeviceTypes();
logger.info(" *** DeviceType List Size=*** "+models.size());

for (Iterator it = models.iterator(); it.hasNext();) {
System.out.println("Inside For Loop Iterator size="+models.size());
Object[] row = (Object[]) it.next();
System.out.println("ID: " + row[0]); // prints data
System.out.println("Name: " + row[1]); //prints data
// Below line results in error : does not have a Converter
deviceTypes.add(new SelectItem(row[0],row[1]+""));
}



return deviceTypes;

}
}



During page rendering, page.jsp throws following exception:
javax.servlet.ServletException: Value is no String and component _id0:deviceTypeList does not have a Converter


Is this bug with MyFaces 1.1.1 or I have made something wrong?

I am a newbie & didnt know much about Converters hence read some examples from the web stating to have getObject() & getString methods . So i added below Class but not sure how to align with page.jsp page.
public class DeviceTypeConverter implements Converter{
protected final Log logger = LogFactory.getLog(getClass());
public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String s) throws ConverterException {
DeviceDao dao = new DeviceDao();
return dao.getdeviceTypes().(Long.decode(s));
}

public String getAsString(FacesContext facesContext, UIComponent
uiComponent, Object o) throws ConverterException {

if(o!= null)
logger.debug(o.toString());

try {
if((o!= null) && (o instanceof DeviceType)){
DeviceType dt = (DeviceType) o;
return ""+dt.getId();
}
else
return "0";
} catch (Exception e) {
logger.error(e);
throw new ConverterException();
}
}

}

Any pointers/suggestions on how to write a Converter & help in resolving the error will be highly appreciated

Regards
Bansi
15 years ago
JSF
I am having problems with JSF 1.1_01 (MyFaces 1.1.1).

I have created page called page.jsp as follows:

. . . .

<h:selectOneMenu value="#{test.selectedDevice}" id="deviceTypeList" styleClass="dropdown">
<f:selectItems value="#{test.deviceTypes}" />

<ajax:support action="#{test.loadDevice}" event="onchange" reRender="t2,t3,t4,t5"/>
</h:selectOneMenu>
. . . .

It is uses managed bean called TestBean.java:

public class TestBean {

public List getDeviceTypes(){
logger.info(" *** In getDeviceTypes Backing Bean*** ");
List<SelectItem> models = new ArrayList<SelectItem>();
List<SelectItem> deviceTypes = new ArrayList<SelectItem>();
// Gets Data from Hibernate Query . It returns List of Device Types
models = deviceManager.getDeviceTypes();
logger.info(" *** DeviceType List Size=*** "+models.size());

for (Iterator it = models.iterator(); it.hasNext();) {
System.out.println("Inside For Loop Iterator size="+models.size());
Object[] row = (Object[]) it.next();
System.out.println("ID: " + row[0]); // prints data
System.out.println("Name: " + row[1]); //prints data
// Below line results in error : does not have a Converter
deviceTypes.add(new SelectItem(row[0],row[1]+""));
}



return deviceTypes;

}
}



During page rendering, page.jsp throws following exception:
javax.servlet.ServletException: Value is no String and component _id0:deviceTypeList does not have a Converter


Is this bug with MyFaces 1.1.1 or I have made something wrong?

I am a newbie & didnt know much about Converters hence read some examples from the web stating to have getObject() & getString methods . So i added below Class but not sure how to align with page.jsp page.
public class DeviceTypeConverter implements Converter{
protected final Log logger = LogFactory.getLog(getClass());
public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String s) throws ConverterException {
DeviceDao dao = new DeviceDao();
return dao.getdeviceTypes().(Long.decode(s));
}

public String getAsString(FacesContext facesContext, UIComponent
uiComponent, Object o) throws ConverterException {

if(o!= null)
logger.debug(o.toString());

try {
if((o!= null) && (o instanceof DeviceType)){
DeviceType dt = (DeviceType) o;
return ""+dt.getId();
}
else
return "0";
} catch (Exception e) {
logger.error(e);
throw new ConverterException();
}
}

}

Any pointers/suggestions on how to write a Converter & help in resolving the error will be highly appreciated

Regards
Bansi
15 years ago
JSF
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" into 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;
}
private DeviceTypeManager deviceManager;
public DeviceTypeManager getDeviceManager() {
return deviceManager;
}


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

Here are the configuration file snippets 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}'

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 it 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
15 years ago
JSF
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
15 years ago
JSF
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
15 years ago
JSF
Hi Alex
As described in your article http://today.java.net/pub/a/today/2004/07/16/jsfcustom.html i implemented simple application

I am getting the following error

OracleJSP: oracle.jsp.parse.JspParseException: /Simple.jsp: Line # 3, <%@ taglib prefix="cc" uri="http://bill.dudney.net/cc/component" %>
Error: "http://bill.dudney.net/cc/component" is not a registered TLD namespace

I am deploying it to Oracle 10g v 10.1.3 application server
Regards
Bansi
15 years ago
JSF
As described in your article http://today.java.net/pub/a/today/2004/07/16/jsfcustom.html i implemented simple application

I am getting the following error

OracleJSP: oracle.jsp.parse.JspParseException: /Simple.jsp: Line # 3, <%@ taglib prefix="cc" uri="http://bill.dudney.net/cc/component" %>
Error: "http://bill.dudney.net/cc/component" is not a registered TLD namespace

I am deploying it to Oracle 10g v 10.1.3 application server
Regards
Bansi
15 years ago
JSF
Hans
I am getting the following error
OracleJSP: oracle.jsp.parse.JspParseException: /Simple.jsp: Line # 3, <%@ taglib prefix="cc" uri="mytaglib" %>
Error: java.io.FileNotFoundException: /opt/ias/product/10.1.3/j2ee/home/applications/CustomComponent/CustomComponent/mytaglib (No such file or directory)

I am developing JSF Custom Component. The tld file is in the directory example\taglib. I cant put it in WEB-INF directory

Regards
Bansi
15 years ago
JSP

Originally posted by Kishore Dandu:
Well I live in Dallas.

I changed jobs recently, and almost all the employers who were hiring required atleast a green card(they simply don't want to sponsor anybody for the time being and they have enough supply of gc holders or citizens with decent experience and skills).

In Dallas, verizon is the only exception, that too they don't hire h1s directly, they get people as contractors through contracting firms.(and make them work insane hours and pay for only 40 hours a week, but that is a different story anyways)

18 years ago