[jboss-user] [JBoss Seam] - Injection / Outjection
mikepkp17
do-not-reply at jboss.com
Thu Jan 4 04:06:55 EST 2007
I still have troubles to understand how this bijection stuff works. What I want to achieve is the following:
I have a SFSB called TestSessionBean:
| @Scope(ScopeType.SESSION)
| @Clustered
| @Name("testSessionBean")
| @Stateful
| public class TestSessionBean implements TestSession, Serializable {
|
| @Logger
| private Log log;
|
| private Session someSession;
|
| private TabItem activeTab;
|
| public TabItem getActiveTab() {
| return activeTab;
| }
|
| public void setActiveTab(TabItem activeTab) {
| this.activeTab = activeTab;
| }
|
| public Session getSomeSession() {
| this.initSomeSession();
| return this.someSession;
| }
|
| private void initSomeSession() {
| ...
| }
|
| @PrePassivate
| @Destroy
| @Remove
| public void passivate() {
| if (this.someSession != null) {
| this.someSession.logout();
| }
| }
|
| @PostActivate
| public void activate() {
| this.initSomeSession();
| }
|
| public String getHello(){
| return "Hello";
| }
|
| }
|
I want to inject this TestSessionBean into another SFSB called TabBean:
| @Stateful
| @Scope(ScopeType.SESSION)
| @Name("foo.bar.TabBean")
| @Clustered
| public class TabBean implements Tab, Serializable {
|
| @In
| public TestSession testSessionBean;
|
| private TabItem activeTab;
|
| private Collection<TabItem> tabs = new Vector<TabItem>();
|
| public Collection getTabs() {
| return tabs;
| }
|
| public TabItem getActiveTab() {
| return activeTab;
| }
|
| public void setActiveTab(TabItem activeTab) {
| this.activeTab = activeTab;
| testSessionBean.setActiveTab(activeTab);
| }
|
| public void setInit(String[] tabArray) {
| for (int i = 0; i < tabArray.length; i++) {
| tabs.add(createTabItem(tabArray.split(";")));
| }
| if (tabs.size() > 0) {
| activeTab = tabs.iterator().next();
| }
|
| }
|
| private TabItem createTabItem(String[] vals) {
| if (vals.length != 4) {
| System.out.println("Wrong tab values inserted!");
| }
| return new TabItemImpl(vals[0], vals[1], vals[2], vals[3], this);
| }
|
| @Destroy
| @Remove
| public void destroy() {
| }
| }
|
The TabBean gets configured with components.xml:
| <components>
| <component name="org.jboss.seam.core.resourceBundle">
| <property name = "bundleNames">
| <value>bundle</value>
| </property>
| </component>
|
| <component name="org.jboss.seam.core.init">
| <property name="debug">true</property>
| <property name="jndiPattern">join2learn/#{ejbName}/local</property>
| </component>
|
| <component name="org.jboss.seam.core.manager">
| <!-- half second wait for conversation lock on concurrent requests -->
| <property name="concurrentRequestTimeout">500</property>
| <!-- 120 second conversation timeout -->
| <property name="conversationTimeout">120000</property>
| <property name="conversationIdParameter">cid</property>
| <property name="conversationIsLongRunningParameter">
| clr
| </property>
| </component>
|
| <component class="org.jboss.seam.core.Ejb"
| installed="false" />
|
| <component class="foo.bar.TabBean"
| name="tabBean">
| <property name="init">
| <value>0;tab.startpage;tab1;startpage</value>
| </property>
| </component>
| </components>
|
My ejb-jar.xml is the seam default one.
My problem is, that I get a NPE in TabBean if I try to invoke a method on the injected TestSessionBean and if I debug this stuff the testSessionBean variable is in fact null.
The TestSessionBean is first accessed in my index.xhtml page with the following call:
| <h:outputLabel value="#{testSessionBean.hello}" />
|
After that call I go to the debug.seam page and both the testSessionBean and the tabBean show up in the Session Context.
When I then click the link on the index page which invokes tabBean.setActiveTab(...) I get the NPE.
I also already tried all combinations of the @In Parameters which also didn't work out.
If I remove the @In and initialize testSessionBean with
| TestSession testSessionBean = (TestSession)Component.getInstance("testSessionBean");
|
everything works but I suppose its not the same as with the @In annotation...
I then added this to the TabBean:
| @In(create=true)
| private FacesMessages facesMessages;
|
and also this is not injected (which should work because FacesMessages is a seam standard component, isn't it?)
I am really stuck on this one, maybe someone can point me in the right direction...
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3997861#3997861
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3997861
More information about the jboss-user
mailing list