Mohammed Nafie
Mohammed Nafie

Reputation: 434

need clarification on JSF and managed beans

i have some behavior im unable to understand, so i started to recently learn JSF, im using TOMCAT 6, now i created JSF file , and i created two Managed Beans under different packages, but each bean have the same name. 1. First bean is com.app.TestBean. 2. Second bean is jsftest.TestBean. now when i call my JSF page, i get to invoke the first bean, if i restart the TOMCAT , i get the result of the second bean, can any body explain what im doing wrong here ?

Upvotes: 0

Views: 56

Answers (1)

Yannick Menager
Yannick Menager

Reputation: 305

Unless you specified their name explicitely, the beans have their name/id assigned based on they class name.

So TestBean would be: testBean

So if you have conflicting class names, you need to explicitely specify their (different) name.

For example if you are using the annotation (which i suspect is the case), you need to do

package com.app;

@ManagedBean("testBean1")
public class TestBean {
  ...
}

and the other bean

package jsftest;

@ManagedBean("testBean2")
public class TestBean {
  ...
}

And then use either #{testBean1} or #{testBean2}

Upvotes: 1

Related Questions