changing to other bean

hello,

i have a little problem.

i have bean A, where i do a lot of stuff.

now i would like to make other things in bean B. But I need some information from the old bean (Bean A). Unfortunately by calling bean B i automatically go in constructor and all old information is lost.

Is there any solution?

[332 byte] By [naekoa] at [2007-11-27 4:07:42]
# 1
Here are several ways to access another managed bean by the facescontext: http://balusc.xs4all.nl/srv/dev-jep-com.html#AccessingAnotherManagedBean
BalusCa at 2007-7-12 9:12:59 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

useful link, thanks (curiosly only 2 first methods functions):

but i think in my case it should be done other way, only i don磘 know how it should be. I have such architecture:

MyBean1.java:

{

String a = "a";

String b = "b";

String c = "c";

int nr;

List<MyBean2> myBean2List = new ArrayList<MyBean2>();

//with getter/setter

String doIt()

{

//so here i just wanted to make something like that:

//MyBean2 myBean2 = new MyBean2(this.a, this.b, this.c);

//but unfortunately after calling action all my fields are empty so i make it

//as shown in the article from your link:

MyBean2 myBean2 =(BookingBean)context.getApplication().getVariableResolver().resolveVariable(context, "myBean2 ");

//now i set my values:

for(int i = 0; i < 2; i++)

{

myBean2.setA(this.a);

myBean2.setB(this.b);

myBean2.setC(this.c);

myBean2.setNr(i);

myBean2List.add(myBean2);

}

return "nextaction";

}

}

the myBean2List i use in my jsf

<h:dataTable id="a" value="#{myBean1.myBean2List }" var="singleBean" >

<h:column>

<h:inputText value="#{myBean2.nr}" readonly="true"></h:inputText>

</h:column>

</h:dataTable>

instead of getting 0 and 1 for my nr-attribute i just get twice 1, as if myList has overriden the first value (0) with 1.

How to handle with it?

naekoa at 2007-7-12 9:12:59 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
You're likely handling DTO's as backing beans? Don't do that.Back to the initial problem: you're overwriting the same object in the for loop instead of instantiating a new object. Changes will be reflected to the collection otherwise.
BalusCa at 2007-7-12 9:13:00 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...