communicating between beans in request scope

I have list.jsp that has a table of items with a link to edit each item like so

<h:dataTable value="#{list.model}" var="curItem">

<h:commandLink actionListener="#{item.doActionEdit}" action="edit">

<h:outputText value="#{curItem.id}"/>

<f:param name="id" value="#{curItem.id}"/>

</h:commandLink>

</h:dataTable>

edit is map to item.jsp

when i click on the link the item bean gets called and doActionEdit sets up the id and fetches data from db but then the bean gets recreated (from scratch and all data is lots id is unset) and it loads item.jsp with and empty bean.

This only happens when item bean is in request scope, however when it is in session scope it works fine, which brings the question; how can I pass objects to a bean that is in the request scope?

I have tries to map id of item in faces-config.xml with #{param.id} which works fine if id is passed but fails with a npe when item.jsp loads without id (say I want to create a new item.)

Please advise me what is the best approach to communicate between beans in request scope, so it will work with and without id being passed.

[1373 byte] By [PC_Guya] at [2007-11-27 8:30:44]
# 1
u can post ur doActionEdit() method also here.
veerjaa at 2007-7-12 20:25:54 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

here is doActionEdit, basicly it gets the id param and then calls setId which tries to load data from db if id is >0 if that fails or id is <=0 it creates new data object instead.

when the item bean is in session scope the constructor is called once but if the scope is request it is called twice (first time doActionEdit is called after constructor but the 2nd time only constructor is called and the itemData is empty.

public void doActionEdit(final ActionEvent event) {

int id = 0;

try {

id = Integer.parseInt(FacesUtil.getParameter("id"));

} catch (Exception e) {

e.printStackTrace();

}

setId(id);

}

private ItemData data = null;

public void setId(final int id) {

if (id > 0) {

data = DB.getItemData(id); //load data from db

if (data == null) {

data=new Data();

}

}

else {

data=new Data();

}

}

public Item() {

data=new Data();

System.out.println("Loading Item class");

}

PC_Guya at 2007-7-12 20:25:54 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...