On Sun, 2006-01-08 at 00:42 -0500, Tom Butler wrote:
> However, I'm having an issue with implementing approach #2 defined in the
> wiki article:
> "C:\side\JavaServerFaces\ExecutingMethodsFromLinkButtonParameters - Myfaces
> Wiki.htm"
> 
> #1  When I configure <t:updateactionlistener> to set a direct member
> property on the backing bean everything works fine:
> 
> <t:updateActionListener property="#{bean_myisp.id}" value="#{isp.id}" />
> (bean_myisp = backing bean; bean_myisp.id = member property of backing bean)
> 
> #2   However, I receive errors if the member property on the backing bean is
> itself a bean (these 2 approaches are defined in the wiki):
> 
> <t:updateActionListener property="#{bean_myisp.isp.id}" value="#{isp.id}" />
> (bean_mysip.isp - isp is a bean member property of the backing bean)
> 
> I have tried to configure my facesconfig.xml as described in the wiki, but
> when I include the <managed property> for bean_myisp.isp, I receive errors:
> 
> <managed-bean>
>   <managed-bean-name>bean_myisp</managed-bean-name>
>   <managed-bean-class>com.abc.bean_myisp</managed-bean-class>
>   <managed-bean-scope>session</managed-bean-scope>
>   <managed-property>
>     <property-name>isp</property-name>
>      <value>#{isp}</value>
>      </managed-property>      
>  </managed-bean>
> 
> Is the line "<value>#{isp}</value>" correct - wasn't sure if I was suppose
> to enter this verbatim from wiki article?  Will JSF take care of
> initializing the bean_mysip and ensure its member property bean 'isp' has an
> instance?

What the configuration you've used above means is that this will
effectively occur:
  com.abc.bean_myisp = new com.abc.bean_myisp();
  Object isp = findOrCreateBeanWithName("isp");
  bean_myisp.setIsp(isp);
  
Firstly, I really hope that "com.abc.bean_myisp" isn't really the
classname, in violation of every Java convention!

As you can see from the pseudocode above, <value>#{isp}</value> means
that the provided expression will be *evaulated* and the result passed
to a setter method for the specified property, at the time the specified
managed bean instance is created.

However for obvious reasons, a bean can't be initialised with a
reference to another bean that has a *shorter* lifetime. You've got your
bean_myisp with a lifetime of "session", so you can't inject a bean with
lifetime shorter than that.

If all you want is for each instance to have a valid "isp" object, then
you don't need managed bean "injection" for that; just create it as you
would for normal java code.

Regards,

Simon

Reply via email to