You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Anton Gavazuk <an...@gmail.com> on 2008/09/29 09:50:27 UTC

[MYFACES-IMPL] what's wrong with org.apache.myfaces.el.unified.resolver.GuiceResolver

Hello guys,

have a big problem with GuiceResolver, which is a part of
myfaces-implementation.

When I'm using it seems it doesnt pass/copy field members from
previous instance of managed bean  -
instead it creates new instances (according to source code) - and all
field members which have had parameters from web form in final
instance are null.

Actually it creates instances of managed bean for 9 times after a form
has been posted.

I'm not very confident in ELResolver stuff, but seems that this
resolver is not implemented in right way or I'm using it in wrong way.

Please, can you clarify what should be changed, or just give info how
to work with these "resolvers"?





The source code of
org.apache.myfaces.el.unified.resolver.GuiceResolver is below:
[CODE]
public class GuiceResolver extends ManagedBeanResolver {

    public static final String KEY = "oam." + Injector.class.getName();

    @Override
    public Object getValue(ELContext ctx, Object base, Object property)
        throws NullPointerException, PropertyNotFoundException, ELException {

        if (base != null || !(property instanceof String))
            return null;

        if (property == null)
            throw new PropertyNotFoundException();

        FacesContext fctx = (FacesContext) ctx.getContext(FacesContext.class);

        if(fctx == null)
            return null;

        ExternalContext ectx = fctx.getExternalContext();

        if (ectx == null ||
            ectx.getRequestMap().containsKey(property) ||
            ectx.getSessionMap().containsKey(property) ||
            ectx.getApplicationMap().containsKey(property) )
            return null;

        ManagedBean managedBean =
runtimeConfig(ctx).getManagedBean((String)property);

        return managedBean == null ? null : getValue(ctx, ectx,
managedBean.getManagedBeanClass());
    }

    private Object getValue(ELContext ctx, ExternalContext ectx, Class
managedBeanClass) {

        Injector injector = (Injector) ectx.getApplicationMap().get(KEY);

        if(injector == null)
            throw new FacesException("Could not find an instance of "
+ Injector.class.getName()
                    + " in application scope using key '" + KEY + "'");

        Object value = injector.getInstance(managedBeanClass);
        ctx.setPropertyResolved(true);
        return value;
    }

}
[/CODE]

Re: [MYFACES-IMPL] what's wrong with org.apache.myfaces.el.unified.resolver.GuiceResolver

Posted by Anton Gavazuk <an...@gmail.com>.
Hi Guys,

I suspect nobody knows ?



2008/9/29 Anton Gavazuk <an...@gmail.com>:
> Hello guys,
>
> have a big problem with GuiceResolver, which is a part of
> myfaces-implementation.
>
> When I'm using it seems it doesnt pass/copy field members from
> previous instance of managed bean  -
> instead it creates new instances (according to source code) - and all
> field members which have had parameters from web form in final
> instance are null.
>
> Actually it creates instances of managed bean for 9 times after a form
> has been posted.
>
> I'm not very confident in ELResolver stuff, but seems that this
> resolver is not implemented in right way or I'm using it in wrong way.
>
> Please, can you clarify what should be changed, or just give info how
> to work with these "resolvers"?
>
>
>
>
>
> The source code of
> org.apache.myfaces.el.unified.resolver.GuiceResolver is below:
> [CODE]
> public class GuiceResolver extends ManagedBeanResolver {
>
>    public static final String KEY = "oam." + Injector.class.getName();
>
>    @Override
>    public Object getValue(ELContext ctx, Object base, Object property)
>        throws NullPointerException, PropertyNotFoundException, ELException {
>
>        if (base != null || !(property instanceof String))
>            return null;
>
>        if (property == null)
>            throw new PropertyNotFoundException();
>
>        FacesContext fctx = (FacesContext) ctx.getContext(FacesContext.class);
>
>        if(fctx == null)
>            return null;
>
>        ExternalContext ectx = fctx.getExternalContext();
>
>        if (ectx == null ||
>            ectx.getRequestMap().containsKey(property) ||
>            ectx.getSessionMap().containsKey(property) ||
>            ectx.getApplicationMap().containsKey(property) )
>            return null;
>
>        ManagedBean managedBean =
> runtimeConfig(ctx).getManagedBean((String)property);
>
>        return managedBean == null ? null : getValue(ctx, ectx,
> managedBean.getManagedBeanClass());
>    }
>
>    private Object getValue(ELContext ctx, ExternalContext ectx, Class
> managedBeanClass) {
>
>        Injector injector = (Injector) ectx.getApplicationMap().get(KEY);
>
>        if(injector == null)
>            throw new FacesException("Could not find an instance of "
> + Injector.class.getName()
>                    + " in application scope using key '" + KEY + "'");
>
>        Object value = injector.getInstance(managedBeanClass);
>        ctx.setPropertyResolved(true);
>        return value;
>    }
>
> }
> [/CODE]
>