You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Emily Gu <e2...@gmail.com> on 2006/01/17 23:07:16 UTC
Components referencing the parent class didn't get value
Hi,
I have a page that have some components referencing the parent backing bean
and some referencing the child backing bean. I need to do some action
handling in child class. But the value of component referencing the parent
class is null all the time. The component referencing the child class is
fine. Do you see anything I am missing so that the component referencing the
parent class didn't get bonded?
Thanks,
Emily
Re: Components referencing the parent class didn't get value
Posted by Emily Gu <e2...@gmail.com>.
Thanks, Simon!!
I have got rid of the B extends A (Child and Parent) structure. Since two
beans are both in the session scope. I just load A in B so that B can
reference A. It works. Hope this solution is fine.
Thanks,
Emily
On 1/17/06, Emily Gu <e2...@gmail.com> wrote:
>
> Hi Simon,
>
> Thanks for such clear explaination. You are right if I put everything in
> B, it'll work. The form page B has included all components in form A plus
> some B specific components. If I don't use such parent and child class, the
> class B would have many duplicated method as class A. Do you have any
> suggestions in such case?
>
> Thank you a lot!
> Emily
>
>
>
> On 1/17/06, Simon Kitching <skitching@apache.org > wrote:
> >
> > You've got class B extending class A.
> > You've got a managed-bean declaration mapping "a" to class A.
> > You've got a managed-bean declaration mapping "b" to class B.
> >
> > When the JSP page references "a", this creates an instance of A and sets
> > it up.
> >
> > When the JSP page references "b", this creates an instance of B, a
> > *separate* object. This object will of course not see the values set up
> > for the object "a".
> >
> > Shouldn't your jsp page reference "b" everywhere, rather than mix "a"
> > and "b"? That way, only one managed bean instance is created.
> >
> > Regards,
> >
> > Simon
> >
> >
> > On Tue, 2006-01-17 at 18:07 -0500, Emily Gu wrote:
> > > Thanks for your quick reply, Simon!
> > >
> > > I have something like following
> > >
> > > public class A {
> > >
> > > public void changeChoices(ValueChangeEvent event) {
> > > // Gets the car from the cars list
> > >
> > > // Updates the myCar instance to be selected car.
> > >
> > > }
> > >
> > > public update () {
> > > System.out.println(myCar.getId());
> > > System.out.println(myCar.getName());
> > >
> > > ...
> > > }
> > >
> > > public MyCar getMyCar() {
> > > return myCar;
> > > }
> > >
> > > private MyCar myCar = new MyCar();
> > > private Cars cars = new Cars();
> > >
> > > }
> > >
> > > Where
> > > myCar = new MyCar();
> > > cars = new Cars();
> > >
> > > Instantiates objects and gets data from database. Both have been
> > > defined as the managed bean and put in the session scope.
> > >
> > > I have another class
> > >
> > > public class B extends A {
> > > public create () {
> > > System.out.println(getMyCar().getId());
> > > }
> > > }
> > >
> > > In the jsp page I have something like:
> > >
> > > <h:form>
> > >
> > > <
> > >
> > > h:selectOneMenu id="profiles" value="#{a.myCar.id<http://a.mycar.id/>
> > }"
> > >
> > > onchange=" document.myForm.submit()"
> > >
> > > valueChangeListener="#{ a.changeChoices}"
> > >
> > > immediate="false">
> > >
> > > <f:selectItems value="#{a.cars.carList}"/>
> > >
> > > </h:selectOneMenu>
> > >
> > > // some other form fields directly bonded to class B properties....
> > >
> > > <
> > >
> > > h:commandLink immediate="false" action="#{ b.create}"
> > > styleClass="formButtonLink"
> > >
> > > value="Create" />
> > > </h:form>
> > >
> > > The problem is the component bonded to Class A, when I try to get the
> > > the value in class B
> > > as System.out.println(getMyCar().getId()); it always returns null. For
> > > components bonded to Class B, everything is fine. I must have done
> > > something wrong. please advice.
> > >
> > > Thanks a lot!
> > > Emily
> > >
> > > On 1/17/06, Simon Kitching <skitching@apache.org > wrote:
> > > On Tue, 2006-01-17 at 17:07 -0500, Emily Gu wrote:
> > > > Hi,
> > > >
> > > > I have a page that have some components referencing the
> > > parent
> > > > backing bean and some referencing the child backing bean. I
> > > need to do
> > > > some action handling in child class. But the value of
> > > component
> > > > referencing the parent class is null all the time. The
> > > component
> > > > referencing the child class is fine. Do you see anything I
> > > am missing
> > > > so that the component referencing the parent class didn't
> > > get bonded?
> > >
> > > I think you'll need to provide some more information.
> > >
> > > What do you mean by "parent backing bean" and "child backing
> > > bean"?
> > >
> > > Please also include relevant parts of your JSP page and
> > > backing bean
> > > classes.
> > >
> > > Regards,
> > >
> > > Simon
> > >
> > >
> >
> >
>
Re: Components referencing the parent class didn't get value
Posted by Emily Gu <e2...@gmail.com>.
Hi Simon,
Thanks for such clear explaination. You are right if I put everything in
B, it'll work. The form page B has included all components in form A plus
some B specific components. If I don't use such parent and child class, the
class B would have many duplicated method as class A. Do you have any
suggestions in such case?
Thank you a lot!
Emily
On 1/17/06, Simon Kitching <sk...@apache.org> wrote:
>
> You've got class B extending class A.
> You've got a managed-bean declaration mapping "a" to class A.
> You've got a managed-bean declaration mapping "b" to class B.
>
> When the JSP page references "a", this creates an instance of A and sets
> it up.
>
> When the JSP page references "b", this creates an instance of B, a
> *separate* object. This object will of course not see the values set up
> for the object "a".
>
> Shouldn't your jsp page reference "b" everywhere, rather than mix "a"
> and "b"? That way, only one managed bean instance is created.
>
> Regards,
>
> Simon
>
>
> On Tue, 2006-01-17 at 18:07 -0500, Emily Gu wrote:
> > Thanks for your quick reply, Simon!
> >
> > I have something like following
> >
> > public class A {
> >
> > public void changeChoices(ValueChangeEvent event) {
> > // Gets the car from the cars list
> >
> > // Updates the myCar instance to be selected car.
> >
> > }
> >
> > public update () {
> > System.out.println(myCar.getId());
> > System.out.println(myCar.getName());
> >
> > ...
> > }
> >
> > public MyCar getMyCar() {
> > return myCar;
> > }
> >
> > private MyCar myCar = new MyCar();
> > private Cars cars = new Cars();
> >
> > }
> >
> > Where
> > myCar = new MyCar();
> > cars = new Cars();
> >
> > Instantiates objects and gets data from database. Both have been
> > defined as the managed bean and put in the session scope.
> >
> > I have another class
> >
> > public class B extends A {
> > public create () {
> > System.out.println(getMyCar().getId());
> > }
> > }
> >
> > In the jsp page I have something like:
> >
> > <h:form>
> >
> > <
> >
> > h:selectOneMenu id="profiles" value="#{a.myCar.id <http://a.mycar.id/>
> }"
> >
> > onchange="document.myForm.submit()"
> >
> > valueChangeListener="#{ a.changeChoices}"
> >
> > immediate="false">
> >
> > <f:selectItems value="#{a.cars.carList}"/>
> >
> > </h:selectOneMenu>
> >
> > // some other form fields directly bonded to class B properties....
> >
> > <
> >
> > h:commandLink immediate="false" action="#{b.create}"
> > styleClass="formButtonLink"
> >
> > value="Create" />
> > </h:form>
> >
> > The problem is the component bonded to Class A, when I try to get the
> > the value in class B
> > as System.out.println(getMyCar().getId()); it always returns null. For
> > components bonded to Class B, everything is fine. I must have done
> > something wrong. please advice.
> >
> > Thanks a lot!
> > Emily
> >
> > On 1/17/06, Simon Kitching <sk...@apache.org> wrote:
> > On Tue, 2006-01-17 at 17:07 -0500, Emily Gu wrote:
> > > Hi,
> > >
> > > I have a page that have some components referencing the
> > parent
> > > backing bean and some referencing the child backing bean. I
> > need to do
> > > some action handling in child class. But the value of
> > component
> > > referencing the parent class is null all the time. The
> > component
> > > referencing the child class is fine. Do you see anything I
> > am missing
> > > so that the component referencing the parent class didn't
> > get bonded?
> >
> > I think you'll need to provide some more information.
> >
> > What do you mean by "parent backing bean" and "child backing
> > bean"?
> >
> > Please also include relevant parts of your JSP page and
> > backing bean
> > classes.
> >
> > Regards,
> >
> > Simon
> >
> >
>
>
Re: Components referencing the parent class didn't get value
Posted by Simon Kitching <sk...@apache.org>.
You've got class B extending class A.
You've got a managed-bean declaration mapping "a" to class A.
You've got a managed-bean declaration mapping "b" to class B.
When the JSP page references "a", this creates an instance of A and sets
it up.
When the JSP page references "b", this creates an instance of B, a
*separate* object. This object will of course not see the values set up
for the object "a".
Shouldn't your jsp page reference "b" everywhere, rather than mix "a"
and "b"? That way, only one managed bean instance is created.
Regards,
Simon
On Tue, 2006-01-17 at 18:07 -0500, Emily Gu wrote:
> Thanks for your quick reply, Simon!
>
> I have something like following
>
> public class A {
>
> public void changeChoices(ValueChangeEvent event) {
> // Gets the car from the cars list
>
> // Updates the myCar instance to be selected car.
>
> }
>
> public update () {
> System.out.println(myCar.getId());
> System.out.println(myCar.getName());
>
> ...
> }
>
> public MyCar getMyCar() {
> return myCar;
> }
>
> private MyCar myCar = new MyCar();
> private Cars cars = new Cars();
>
> }
>
> Where
> myCar = new MyCar();
> cars = new Cars();
>
> Instantiates objects and gets data from database. Both have been
> defined as the managed bean and put in the session scope.
>
> I have another class
>
> public class B extends A {
> public create () {
> System.out.println(getMyCar().getId());
> }
> }
>
> In the jsp page I have something like:
>
> <h:form>
>
> <
>
> h:selectOneMenu id="profiles" value="#{a.myCar.id}"
>
> onchange="document.myForm.submit()"
>
> valueChangeListener="#{a.changeChoices}"
>
> immediate="false">
>
> <f:selectItems value="#{a.cars.carList}"/>
>
> </h:selectOneMenu>
>
> // some other form fields directly bonded to class B properties....
>
> <
>
> h:commandLink immediate="false" action="#{b.create}"
> styleClass="formButtonLink"
>
> value="Create" />
> </h:form>
>
> The problem is the component bonded to Class A, when I try to get the
> the value in class B
> as System.out.println(getMyCar().getId()); it always returns null. For
> components bonded to Class B, everything is fine. I must have done
> something wrong. please advice.
>
> Thanks a lot!
> Emily
>
> On 1/17/06, Simon Kitching <sk...@apache.org> wrote:
> On Tue, 2006-01-17 at 17:07 -0500, Emily Gu wrote:
> > Hi,
> >
> > I have a page that have some components referencing the
> parent
> > backing bean and some referencing the child backing bean. I
> need to do
> > some action handling in child class. But the value of
> component
> > referencing the parent class is null all the time. The
> component
> > referencing the child class is fine. Do you see anything I
> am missing
> > so that the component referencing the parent class didn't
> get bonded?
>
> I think you'll need to provide some more information.
>
> What do you mean by "parent backing bean" and "child backing
> bean"?
>
> Please also include relevant parts of your JSP page and
> backing bean
> classes.
>
> Regards,
>
> Simon
>
>
Re: Components referencing the parent class didn't get value
Posted by Emily Gu <e2...@gmail.com>.
Thanks for your quick reply, Simon!
I have something like following
public class A {
public void changeChoices(ValueChangeEvent event) {
// Gets the car from the cars list
// Updates the myCar instance to be selected car.
}
public update () {
System.out.println(myCar.getId());
System.out.println(myCar.getName());
...
}
public MyCar getMyCar() {
return myCar;
}
private MyCar myCar = new MyCar();
private Cars cars = new Cars();
}
Where
myCar = new MyCar();
cars = new Cars();
Instantiates objects and gets data from database. Both have been defined as
the managed bean and put in the session scope.
I have another class
public class B extends A {
public create () {
System.out.println(getMyCar().getId());
}
}
In the jsp page I have something like:
<h:form>
<h:selectOneMenu id="profiles" value="#{a.myCar.id}"
onchange="document.myForm.submit()"
valueChangeListener="#{a.changeChoices}"
immediate="false">
<f:selectItems value="#{a.cars.carList}"/>
</h:selectOneMenu>
// some other form fields directly bonded to class B properties....
<h:commandLink immediate="false" action="#{b.create}" styleClass=
"formButtonLink"
value="Create" />
</h:form>
The problem is the component bonded to Class A, when I try to get the the
value in class B
as System.out.println(getMyCar().getId()); it always returns null. For
components bonded to Class B, everything is fine. I must have done something
wrong. please advice.
Thanks a lot!
Emily
On 1/17/06, Simon Kitching <sk...@apache.org> wrote:
>
> On Tue, 2006-01-17 at 17:07 -0500, Emily Gu wrote:
> > Hi,
> >
> > I have a page that have some components referencing the parent
> > backing bean and some referencing the child backing bean. I need to do
> > some action handling in child class. But the value of component
> > referencing the parent class is null all the time. The component
> > referencing the child class is fine. Do you see anything I am missing
> > so that the component referencing the parent class didn't get bonded?
>
> I think you'll need to provide some more information.
>
> What do you mean by "parent backing bean" and "child backing bean"?
>
> Please also include relevant parts of your JSP page and backing bean
> classes.
>
> Regards,
>
> Simon
>
>
Re: Components referencing the parent class didn't get value
Posted by Simon Kitching <sk...@apache.org>.
On Tue, 2006-01-17 at 17:07 -0500, Emily Gu wrote:
> Hi,
>
> I have a page that have some components referencing the parent
> backing bean and some referencing the child backing bean. I need to do
> some action handling in child class. But the value of component
> referencing the parent class is null all the time. The component
> referencing the child class is fine. Do you see anything I am missing
> so that the component referencing the parent class didn't get bonded?
I think you'll need to provide some more information.
What do you mean by "parent backing bean" and "child backing bean"?
Please also include relevant parts of your JSP page and backing bean
classes.
Regards,
Simon