• Post Reply Bookmark Topic Watch Topic
  • New Topic

JSF Dependency Injection inheritence issue

 
Vincent Zhao
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE faces-config PUBLIC "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN" "http://java.sun.com/dtd/web-facesconfig_1_1.dtd">

<faces-config>
<application/>

<managed-bean>
<managed-bean-name>UserAccountBean</managed-bean-name>
<managed-bean-class>
com.kmv.view.UserAccountBean
</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
<managed-property>
<property-name>multiUser</property-name>
<value>false</value>
</managed-property>
</managed-bean>

<managed-bean>
<managed-bean-name>UserCheckingAccountBean</managed-bean-name>
<managed-bean-class>
com.kmv.view.UserCheckingAccountBean
</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>

<managed-bean>
<managed-bean-name>UserSavingAccountBean</managed-bean-name>
<managed-bean-class>
com.kmv.view.UserSavingAccountBean
</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>

<managed-bean>
<managed-bean-name>UserUSDAccountBean</managed-bean-name>
<managed-bean-class>com.kmv.view.UserUSDAccountBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>


</faces-config>

1. UserCheckingAccountBean extends UserAccountBean
UserSavingAccountBean extends UserAccountBean
UserUSDAccountBean extends UserAccountBean

2. I want to inject "multiUser" property in superclass UserAccountBean, but no luck, so I have to do like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE faces-config PUBLIC "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN" "http://java.sun.com/dtd/web-facesconfig_1_1.dtd">

<faces-config>
<application/>

<managed-bean>
<managed-bean-name>UserCheckingAccountBean</managed-bean-name>
<managed-bean-class>
com.kmv.view.UserCheckingAccountBean
</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
<managed-property>
<property-name>multiUser</property-name>
<value>false</value>
</managed-property>
</managed-bean>

<managed-bean>
<managed-bean-name>UserSavingAccountBean</managed-bean-name>
<managed-bean-class>
com.kmv.view.UserSavingAccountBean
</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<managed-property>
<property-name>multiUser</property-name>
<value>false</value>
</managed-property>
</managed-bean>

<managed-bean>
<managed-bean-name>UserUSDAccountBean</managed-bean-name>
<managed-bean-class>com.kmv.view.UserUSDAccountBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
<managed-property>
<property-name>multiUser</property-name>
<value>false</value>
</managed-property>
</managed-bean>


</faces-config>

Is that means I cannot inject property to superclass and let subclass get it from superclass?
Thanks in advance.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's the exception/trace you got?
 
Vincent Zhao
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No exception. But if I used first way, that value was not inject at all, it always is "FALSE".
 
Tim Holloway
Bartender
Posts: 18412
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Managed bean declarations define an instance of a JavaBean. It does not (re)define the class.

What you did was create 4 beans, not 3, and the first bean was simply an instance of a UserAccountBean. You could inject that bean into your other beans, but that wouldn't be a superclass, it would be an object reference.

In other words, no, you can't override a class definitions using faces-config. All you can do is control the property injections on a per-bean basis.
 
Vincent Zhao
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tim,

Thanks a lot. I am clear now!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!