myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Simon Lessard" <simon.lessar...@gmail.com>
Subject Re: Bean scope problem
Date Fri, 11 May 2007 17:24:29 GMT
Hello Simeon,

Can you give a little more detail on Bean C please? Like what kind of app.
specific parameters we're talking about and where those can be found? This
can help me give you a better solution. With the information I have though,
here's what I would do:

   1. A and B are managed bean;
   2. A constructs C in its constructor;
   3. A has a B-injection managed-property;
   4. In A's setB method, call B.setC(C) since A knows C.

Would that work?


Regards,

~ Simon

On 5/11/07, Leyzerzon, Simeon <simeon.leyzerzon@credit-suisse.com> wrote:
>
>  Is there maybe some kind of event notification system in JSF that will
> notify me that bean B is created successfully and thus available for its
> parent bean to set properties on?
>
> Thank you in advance
> Simeon
>
>  ------------------------------
> *From:* Leyzerzon, Simeon [mailto:simeon.leyzerzon@credit-suisse.com]
> *Sent:* Friday, May 11, 2007 1:01 PM
> *To:* 'MyFaces Discussion'
> *Subject:* RE: Bean scope problem
>
>  Thanks.
> Let me explain what I'm trying to achieve to clarify a bit.
>
> There is a managed bean (bean A) with a property that is not managed by
> faces (bean C), since it's based on some app specific parameters that I need
> to consider during its creation time.  So during the time jsf creates bean A
> (in its constructor), I myself create bean C and set it on A.
>
> Then there's another managed bean (bean B) which is a managed property of
> bean A.  This bean B needs to be passed a reference to bean C from bean A as
> it uses it internally.
>
> I tried setting C on B when C gets set in A, but at that time B doesn't
> yet exist so I'm getting a NPE.
>
> I also tried getting a reference to A from B when be gets constructed by
> JSF via
> FacesContext.currentInstance.application.variableResolver.resolveVariable(context,
> "A") but that gives me a circular reference error message as B is trying to
> reach its parent.
>
> Any suggestions on how else I can achieve this requirement, please?
>
> Thanks for your help.
> Simeon
>
>
>
>  ------------------------------
>  *From:* Simon Lessard [mailto:simon.lessard.3@gmail.com]
> *Sent:* Friday, May 11, 2007 11:49 AM
> *To:* MyFaces Discussion
> *Subject:* Re: Bean scope problem
>
> Hello,
>
> Actually, "none" is a perfectly valid managed bean scope. It means "create
> it every time".
>
> As for the original poster's problem, you cannot inject a session scoped
> value into a none scoped bean, see JSF specification section 5.3.1.3.
>
> Also, that being said, you should not access a none scoped bean directly
> in your pages, that scope was made mainly for managed-property injection
> like you seem to do already.
>
>
> Regards,
>
> ~ Simon
>
> On 5/11/07, William Diaz Pabón <widipa@hotmail.com> wrote:
> >
> > <managed-bean-scope>none</managed-bean-scope>  ????
> >
> >
> > it must define a scope the bean.
> >
> > opctions:
> >
> > 1) <managed-bean-scope>application</managed-bean-scope>
> > 2) <managed-bean-scope>session</managed-bean-scope>
> > 3) <managed-bean-scope>request</managed-bean-scope>
> >
> >
> >
> > Cordialmente.
> >
> > William Diaz Pabón
> > Tunja - Boyacá - Colombia
> >
> >
> >
> >
> >
> > >From: "Leyzerzon, Simeon" < simeon.leyzerzon@credit-suisse.com>
> > >Reply-To: "MyFaces Discussion" <users@myfaces.apache.org>
> > >To: "' users@myfaces.apache.org'" <users@myfaces.apache.org>
> > >Subject: Bean scope problem
> > >Date: Fri, 11 May 2007 11:13:34 -0400
> > >
> > >Hi,
> > >
> > >I'm getting the following exception at runtime:
> > >
> > >javax.faces.el.EvaluationException: Cannot get value for expression
> > >'#{searchHandler.intervalSelector.selectedIntervalTag}'
> > >       at
> > >org.apache.myfaces.el.ValueBindingImpl.getValue(ValueBindingImpl.java
> > :405)
> > >       at
> > >org.apache.myfaces.application.ApplicationImpl.createComponent(
> > ApplicationImpl.java:427)
> > >       at
> > >javax.faces.webapp.UIComponentTag.createComponentInstance(
> > UIComponentTag.java:881)
> > >       at
> > >javax.faces.webapp.UIComponentTag.findComponent(UIComponentTag.java
> > :768)
> > >       at javax.faces.webapp.UIComponentTag.doStartTag (
> > UIComponentTag.java:472)
> > >       Truncated. see log file for complete stacktrace
> > >javax.faces.el.EvaluationException: Cannot get value for expression
> > >'#{userControlsHandler}'
> > >       at
> > >org.apache.myfaces.el.ValueBindingImpl.getValue(ValueBindingImpl.java
> > :405)
> > >       at
> > >
> > org.apache.myfaces.config.impl.digester.elements.ManagedProperty.getRuntimeValue
> > (ManagedProperty.java:130)
> > >       at
> > >org.apache.myfaces.config.ManagedBeanBuilder.initializeProperties(
> > ManagedBeanBuilder.java:170)
> > >       at
> > >org.apache.myfaces.config.ManagedBeanBuilder.buildManagedBean(
> > ManagedBeanBuilder.java:55)
> > >       at
> > >org.apache.myfaces.el.VariableResolverImpl.resolveVariable(
> > VariableResolverImpl.java:314)
> > >       Truncated. see log file for complete stacktrace
> > >javax.faces.FacesException: Property searchService references object in
> > a
> > >scope with shorter lifetime than the target scope none
> > >       at
> > >org.apache.myfaces.config.ManagedBeanBuilder.initializeProperties(
> > ManagedBeanBuilder.java:167)
> > >       at
> > >org.apache.myfaces.config.ManagedBeanBuilder.buildManagedBean (
> > ManagedBeanBuilder.java:55)
> > >       at
> > >org.apache.myfaces.el.VariableResolverImpl.resolveVariable(
> > VariableResolverImpl.java:314)
> > >       at
> > >
> > org.apache.myfaces.custom.redirectTracker.RedirectTrackerVariableResolver.resolveVariable(
> > RedirectTrackerVariableResolver.java:41)
> > >       at
> > >
> > org.apache.myfaces.custom.security.SecurityContextVariableResolver.resolveVariable
> > (SecurityContextVariableResolver.java:45)
> > >       Truncated. see log file for complete stacktrace
> > >
> > >
> > >Could someone please help figure it out?
> > >Here is the faces-config.xml file:
> > >
> > >
> > ><?xml version="1.0" encoding="UTF-8"?>
> > ><!DOCTYPE faces-config PUBLIC "-//Sun Microsystems, Inc.//DTD
> > JavaServer
> > >Faces Config 1.0//EN"
> > >
> > >"http://java.sun.com/dtd/web-facesconfig_1_0.dtd
> > >< http://java.sun.com/dtd/web-facesconfig_1_0.dtd> ">
> > ><faces-config>
> > >
> > >       <managed-bean>
> > >               <description/>
> > >               <managed-bean-name>searchHandler</managed-bean-name>
> > >               <managed-bean-class>
> > com.csfb.fao.clr.controller.maintenance.search.SearchHandler
> > </managed-bean-class>
> > >               <managed-bean-scope>session</managed-bean-scope>
> > >               <managed-property>
> > >                       <property-name>controls</property-name>
> > >                       <value>#{userControlsHandler}</value>
> > >               </managed-property>
> > >               <managed-property>
> > >                       <property-name>searchService</property-name>
> > >                       <value>#{searchService}</value>
> > >               </managed-property>
> > >
> > >               <managed-property>
> > >                       <property-name>categorySelector</property-name>
> > >                       <value>#{selectCategories}</value>
> > >               </managed-property>
> > >               <managed-property>
> > >                       <property-name>intervalSelector</property-name>
> > >                       <value>#{selectIntervals}</value>
> > >               </managed-property>
> > >               <managed-property>
> > >
> > <property-name>userActionSelector</property-name>
> > >                       <value>#{selectUserActions}</value>
> > >               </managed-property>
> > >               <managed-property>
> > >
> > <property-name>searchCommandsController</property-name>
> > >                       <value>#{commandsController}</value>
> > >               </managed-property>
> > >               <managed-property>
> > >
> > <property-name>searchPanelStackController</property-name>
> > >                       <value>#{searchPanelStackController}</value>
> > >               </managed-property>
> > >               <managed-property>
> > >                       <property-name>regionSelector</property-name>
> > >                       <value>#{selectRegions}</value>
> > >               </managed-property>
> > >               <managed-property>
> > >
> > <property-name>bookingCountrySelector</property-name>
> > >                       <value>#{selectBookingCountries}</value>
> > >               </managed-property>
> > >               <managed-property>
> > >
> > <property-name>reportingLineSelector</property-name>
> > >                       <value>#{selectReportingLines}</value>
> > >               </managed-property>
> > >               <managed-property>
> > >
> > <property-name>clientNameController</property-name>
> > >                       <value>#{clientNameController}</value>
> > >               </managed-property>
> > >               <managed-property>
> > >                       <property-name>cifController</property-name>
> > >                       <value>#{cifController}</value>
> > >               </managed-property>
> > >               <managed-property>
> > >
> > <property-name>facilityController</property-name>
> > >                       <value>#{facilityController}</value>
> > >               </managed-property>
> > >
> > >
> > >
> > >               <managed-property>
> > >
> > <property-name>creditPurposeSelector</property-name>
> > >                       <value>#{selectCreditPurposes}</value>
> > >               </managed-property>
> > >               <managed-property>
> > >
> > <property-name>searchResultsHandler</property-name>
> > >                       <value>#{searchResultsHandler}</value>
> > >               </managed-property>
> > >
> > >       </managed-bean>
> > >
> > >       <managed-bean>
> > >               <description/>
> > >               <managed-bean-name>searchService</managed-bean-name>
> > >               <managed-bean-class>
> > com.csfb.fao.clr.service.SearchService</managed-bean-class>
> > >               <managed-bean-scope>none</managed-bean-scope>
> > >       </managed-bean>
> > >
> > >       <managed-bean>
> > >               <description/>
> > >
> > <managed-bean-name>userControlsHandler</managed-bean-name>
> > >               <managed-bean-class>
> > com.csfb.fao.clr.controller.maintenance.search.UserControlsHandler
> > </managed-bean-class>
> > >               <managed-bean-scope>none</managed-bean-scope>
> > >
> > >               <managed-property>
> > >                       <property-name>searchService</property-name>
> > >                       <value>#{searchHandler.searchService}</value>
> > >               </managed-property>
> > >
> > >               <managed-property>
> > >
> > <property-name>reportingPeriodSelector</property-name>
> > >                       <value>#{selectReportingPeriods}</value>
> > >               </managed-property>
> > >       </managed-bean>
> > >
> > >       <managed-bean>
> > >               <description/>
> > >
> > <managed-bean-name>selectReportingPeriods</managed-bean-name>
> > >               <managed-bean-class>
> > com.csfb.fao.clr.controller.maintenance.search.SelectReportingPeriods
> > </managed-bean-class>
> > >               <managed-bean-scope>none</managed-bean-scope>
> > >       </managed-bean>
> > >       <managed-bean>
> > >               <description/>
> > >               <managed-bean-name>selectCategories</managed-bean-name>
> > >               <managed-bean-class>
> > com.csfb.fao.clr.controller.maintenance.search.SelectCategories
> > </managed-bean-class>
> > >               <managed-bean-scope>none</managed-bean-scope>
> > >       </managed-bean>
> > >       <managed-bean>
> > >               <description/>
> > >               <managed-bean-name>selectIntervals</managed-bean-name>
> > >               <managed-bean-class>
> > com.csfb.fao.clr.controller.maintenance.search.SelectInterval</managed-bean-class>
> > >               <managed-bean-scope>none</managed-bean-scope>
> > >       </managed-bean>
> > >       <managed-bean>
> > >               <description/>
> > >               <managed-bean-name>selectUserActions</managed-bean-name>
> > >               <managed-bean-class>
> > com.csfb.fao.clr.controller.maintenance.search.SelectUserAction</managed-bean-class>
> >
> > >               <managed-bean-scope>none</managed-bean-scope>
> > >       </managed-bean>
> > >       <managed-bean>
> > >               <description/>
> > >
> > <managed-bean-name>commandsController</managed-bean-name>
> > >               <managed-bean-class>
> > com.csfb.fao.clr.controller.maintenance.search.SearchCommandsController
> > </managed-bean-class>
> > >               <managed-bean-scope>none</managed-bean-scope>
> > >       </managed-bean>
> > >       <managed-bean>
> > >               <description/>
> > >
> > <managed-bean-name>searchPanelStackController</managed-bean-name>
> > >               <managed-bean-class>
> > com.csfb.fao.clr.controller.maintenance.search.SearchPanelStackController
> > </managed-bean-class>
> > >               <managed-bean-scope>none</managed-bean-scope>
> > >       </managed-bean>
> > >       <managed-bean>
> > >               <description/>
> > >               <managed-bean-name>selectRegions</managed-bean-name>
> > >               <managed-bean-class>
> > com.csfb.fao.clr.controller.maintenance.search.SelectRegion</managed-bean-class>
> > >               <managed-bean-scope>none</managed-bean-scope>
> > >       </managed-bean>
> > >       <managed-bean>
> > >               <description/>
> > >
> > <managed-bean-name>selectBookingCountries</managed-bean-name>
> > >               <managed-bean-class>
> > com.csfb.fao.clr.controller.maintenance.search.SelectBookingCountry</managed-bean-class>
> >
> > >               <managed-bean-scope>none</managed-bean-scope>
> > >       </managed-bean>
> > >
> > >       <managed-bean>
> > >               <description/>
> > >
> > <managed-bean-name>clientNameController</managed-bean-name>
> > >               <managed-bean-class>
> > com.csfb.fao.clr.controller.maintenance.search.ClientNameController
> > </managed-bean-class>
> > >               <managed-bean-scope>none</managed-bean-scope>
> > >       </managed-bean>
> > >       <managed-bean>
> > >               <description/>
> > >               <managed-bean-name>cifController</managed-bean-name>
> > >               <managed-bean-class>
> > com.csfb.fao.clr.controller.maintenance.search.CIFController
> > </managed-bean-class>
> > >               <managed-bean-scope>none</managed-bean-scope>
> > >       </managed-bean>
> > >       <managed-bean>
> > >               <description/>
> > >
> > <managed-bean-name>facilityController</managed-bean-name>
> > >               <managed-bean-class>
> > com.csfb.fao.clr.controller.maintenance.search.FacilityController</managed-bean-class>
> > >               <managed-bean-scope>none</managed-bean-scope>
> > >       </managed-bean>
> > >
> > >       <managed-bean>
> > >               <description/>
> > >
> > <managed-bean-name>selectReportingLines</managed-bean-name>
> > >               <managed-bean-class>
> > com.csfb.fao.clr.controller.maintenance.search.SelectReportingLine</managed-bean-class>
> >
> > >               <managed-bean-scope>none</managed-bean-scope>
> > >       </managed-bean>
> > >       <managed-bean>
> > >               <description/>
> > >
> > <managed-bean-name>selectCreditPurposes</managed-bean-name>
> > >               <managed-bean-class>
> > com.csfb.fao.clr.controller.maintenance.search.SelectCreditPurpose
> > </managed-bean-class>
> > >               <managed-bean-scope>none</managed-bean-scope>
> > >       </managed-bean>
> > >
> > >
> > ></faces-config>
> > >
> > >
> > >
> > >Thank you,
> > >Simeon
> > >
> > >==============================================================================
> >
> > >Please access the attached hyperlink for an important electronic
> > >communications disclaimer:
> > >
> > >http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html
> >
> > >==============================================================================
> >
> > _________________________________________________________________
> > Las mejores tiendas, los precios mas bajos, entregas en todo el mundo,
> > YupiMSN Compras: http://latam.msn.com/compras/
> >
> >
> ==============================================================================
> Please access the attached hyperlink for an important electronic communications disclaimer:
>
> http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html
> ==============================================================================
>
>  ==============================================================================
> Please access the attached hyperlink for an important electronic communications disclaimer:
>
> http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html
> ==============================================================================
>
>

Mime
View raw message