-
1. Re: Custom ELResolver in Seam
nickarls Oct 21, 2008 8:25 AM (in response to hsingh2)I don't think you can have multiple resolvers like that (latest probably wins). Try extending the Seam version and call super()-methods where applicable.
-
2. Re: Custom ELResolver in Seam
hsingh2 Oct 21, 2008 7:53 PM (in response to hsingh2)Thanks for Reply!
you are right i can do that,Actually i tried that solution I was successful in overriding the SeamELResolver likepublic class CustomELResolver extends SeamELResolver { public getValue(...){ if(condition==true){ //do the custom stuff else super.getValue(..) //call the super } ... .. }
it works perfect and in faces-config.xml i insert the entry like
<el-resolver>com.company.CustomELResolver</el-resolver>
but i do not want to check on my condition for each and every expression and then call the super. To avoid that i am more interested in the idea of CompositeELResolver
i was under impression that seam/faces do not use the CompositeELResolver from following bug report
My Linkand then i tried to write my own implementation of CompositeELResolver and add the SeamELResolver first and then my CustomELResolver, that way it will go to my CustomELResolver if it is not resolved with SeamELResolver
but on debuging the code i find that it is always going to my CustomELResolver and also there is FacesCompositeELResolver class that has 11 ELResolvers including SeamELResolver
at the 2nd place and this class is present in jsf-api/** * Maintains an ordered composite list of child <code>ELResolver for JSF</code>. * */ public class FacesCompositeELResolver extends CompositeELResolver { public void add(ELResolver elResolver) { super.add(elResolver); } ... }
Ok now I thought oh its great I just add my CustomELResolver at the end of this FacesCompositeELResolver and my resolver will only get called if the expression is not get resolved from other 11 Resolvers.
Tried following two solutions
1) just add the CustomELResolver in faces-configthis solutions works it added CustomELResolver at third place in FacesCompositeELResolver list
[com.sun.faces.el.ImplicitObjectELResolver@804b62, org.jboss.seam.el.SeamELResolver@d54694, com.company.CustomELResolver, com.sun.faces.el.ManagedBeanELResolver@ed705f, javax.el.ResourceBundleELResolver@d0c62b, com.sun.faces.el.FacesResourceBundleELResolver@6fa88c, javax.el.MapELResolver@a28ff7, javax.el.ListELResolver@99a27a, javax.el.ArrayELResolver@7a3885, javax.el.BeanELResolver@14b051, com.sun.faces.el.ScopedAttributeELResolver@4395e1, null, null, null, null, null]
but now my problem is it is added at 3rd place and it is still going to CustomELResolver for all the Expressions, i want to add this CustomELResolver at end of the resolvers List
2) then i tried to override the FacesCompositeELResolver class as
public class CompositeELResolverImpl extends FacesCompositeELResolver{ //Constructor public CompositeELResolverImpl(ELResolverChainType chainType) { super(chainType); } @Override public void add(ELResolver elResolver) { //add all the resolvers ...... super.add(new SeamELResolver()); ... super.add(new WamELResolver()); //at the end add CustomELResolver } @Override public Object getValue(ELContext arg0, Object arg1, Object arg2) { return super.getValue(arg0, arg1, arg2); } ... }
but throws a exceptions as
/ 4,570 FATAL [jsf] Cant instantiate class: com.company.CompositeELResolverImpl . java.lang.InstantiationException:: com.company.CompositeELResolverImpl at java.lang.Class.newInstance0(Class.java:340) at java.lang.Class.newInstance(Class.java:308) at com.sun.faces.util.Util.createInstance(Util.java:471) at com.sun.faces.util.Util.createInstance(Util.java:436) at com.sun.faces.config.ConfigureListener.configure(ConfigureListener.java:601) at com.sun.faces.config.ConfigureListener.configure(ConfigureListener.java:487) at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:381) at org.jboss.web.jsf.integration.config.JBossJSFConfigureListener.contextInitialized(JBossJ gureListener.java:69)
I hope i didn't confuse you, the whole idea is i want to use the idea of CompositeELResolver and want to add my CustomELResolver at the end so that in all the 99% cases it works as ususal and only go to CustomELResolver to resolve that 1% special expression
Please give me clue on this FacesCompositeELResolver class so that i can add my ELResolver at the end of his resolvers list
Thanks in advance
Regards, -