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 <[EMAIL PROTECTED]> 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
>         
> 

Reply via email to