[seam-issues] [JBoss JIRA] (SEAMFACES-242) WELD-001318 AmbiguousResolutionException with Converter having subclass

Jason Porter (JIRA) jira-events at lists.jboss.org
Fri Mar 30 16:39:47 EDT 2012


    [ https://issues.jboss.org/browse/SEAMFACES-242?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12680737#comment-12680737 ] 

Jason Porter commented on SEAMFACES-242:
----------------------------------------

Here's the transcript of an IRC conversation with Brian Leathem (the Seam Faces lead):

{quote}
jbossbot	jira [SEAMFACES-242] WELD-001318 AmbiguousResolutionException with Converter having subclass [Open (Unresolved) Bug, Major, Unassigned] https://issues.jboss.org/browse/SEAMFACES-242	
{color:red}lightguard_jp{color}	Right.	
{color:blue}bleathem{color}	why does a bean lookup of a base class result in being ambiguous with the classes that extend it?	
{color:red}lightguard_jp{color}	I haven't looked at the code at all, but based on what he's seeing, how does this even work?	
{color:blue}bleathem{color}	If I lookup A	
{color:blue}bleathem{color}	and B extedns A	
{color:red}lightguard_jp{color}	Or is it only when there's a subclass involved	
{color:blue}bleathem{color}	why is B ambiguous with A?	
{color:blue}bleathem{color}	right	
{color:blue}bleathem{color}	this issue has to do with subclassing	
{color:red}lightguard_jp{color}	Because there are two of them	
{color:red}lightguard_jp{color}	A is an A and B is also an A	
{color:blue}bleathem{color}	so how can I lookup A?	
{color:blue}bleathem{color}	if I want A?	
{color:blue}bleathem{color}	if I wanted B, I'd lookup B	
{color:red}lightguard_jp{color}	A qualifier, B could also @Specialize	
{color:blue}bleathem{color}	hmm	
{color:red}lightguard_jp{color}	A could be an abstract class	
{color:red}lightguard_jp{color}	Well, then you'd get B anyway.	
{color:red}lightguard_jp{color}	If both A and B are concrete classes	
{color:blue}bleathem{color}	@Quliafirers won't work so well in the facelet scenario	
{color:red}lightguard_jp{color}	You have to use @Specializes or a qualifier	
{color:blue}bleathem{color}	so is there no resolution to be found here?	
{color:red}lightguard_jp{color}	Why would you subclass a validator or a converter?	
{color:red}lightguard_jp{color}	Wouldn't composition work better?	
{color:red}lightguard_jp{color}	hm	
{color:red}lightguard_jp{color}	Even if we return a set of beans that would work, how do we select the correct one?	
{color:red}lightguard_jp{color}	What's to say we'll actually get a subclass from JSF? What if it passes us the super class and what the developer is expecting is a subclass?	
{color:red}lightguard_jp{color}	All we get is a converterId (which would work) or a target class, which any of the subclasses should be able to handle	
{color:red}lightguard_jp{color}	It really seems like supporting inheritance here is going to be extremely difficult.	
{color:red}lightguard_jp{color}	If it's even possible	
{color:red}lightguard_jp{color}	{color:blue}bleathem{color}: thoughts?	
{color:blue}bleathem{color}	{color:red}lightguard_jp{color}: that's a good summary of the problems we'd face in trying to support this use case	
{color:blue}bleathem{color}	I agree - composition would work better here
{quote}
                
> WELD-001318 AmbiguousResolutionException with Converter having subclass
> -----------------------------------------------------------------------
>
>                 Key: SEAMFACES-242
>                 URL: https://issues.jboss.org/browse/SEAMFACES-242
>             Project: Seam Faces
>          Issue Type: Bug
>          Components: CDI Integration, Validation & Conversion
>    Affects Versions: 3.1.0.Final
>         Environment: GF 3.1.2 with JDK 1.6.0b29 + SeamFaces 3.1.0 + RichFaces 4.2.0
>            Reporter: Fab Mars
>
> On some page I have <rich:inputNumberSpinner label="Count" value="#{orderLine.quantity}" converter="IntegerOrNullConverter".../>
> The converter to use is explicit. But I also extended that converter class twice for other purposes.
> When accessing the page I get a WELD-001318 ambiguous dependency. Stacktrace below.
> SeamApplicationWrapper#createConverter ends up calling BeanManagerUtils#isDependentScoped which tries to CDI-resolve the the converter type. Naturally weld finds the 3 converters (the one I asked for and the 2 subclasses) and it complains as it should. I strongly believe calling BM#resolve here is wrong.
> The same will happen with SeamApplicationWrapper#createValidator.
> 1) These methods should deal with only the actual requested type
> 2) The use of BeanManagerUtils.getContextualInstance in SeamApplicationWrapper.attemptExtension will also lead to problems.
> 3) More generally, I BeanManagerUtils.isDependentScoped isn't selective enough either
> Instead of #resolve, another utility method like this may be called:
> {code}
>     public <T> Set<Bean<?>> getExactBeanForType(final Class<T> type) {
>       Set<Bean<?>> beans = manager.getBeans(type);
>       for(Bean<?> bean : beans) {
>         if(type.equals(bean.getBeanClass())) {
>           return Collections.<Bean<?>>singleton(bean);
>         }
>       }
>       
>       return Collections.<Bean<?>>emptySet();
>     }
> {code}
> Stacktrace of the issue:
> {code}
> GRAVE: org.jboss.weld.exceptions.AmbiguousResolutionException: WELD-001318 Cannot resolve an ambiguous dependency between [Managed Bean [class org.mars.toolkit.jsf.converter.MonthConverter] with qualifiers [@Any @Default], Managed Bean [class org.mars.toolkit.jsf.converter.IntegerOrNullConverter] with qualifiers [@Any @Default], Managed Bean [class org.mars.toolkit.jsf.converter.YearConverter] with qualifiers [@Any @Default]]
>     at org.jboss.weld.manager.BeanManagerImpl.resolve(BeanManagerImpl.java:1013)
>     at org.jboss.seam.faces.util.BeanManagerUtils.isDependentScoped(BeanManagerUtils.java:74)
>     at org.jboss.seam.faces.environment.SeamApplicationWrapper.attemptExtension(SeamApplicationWrapper.java:81)
>     at org.jboss.seam.faces.environment.SeamApplicationWrapper.createConverter(SeamApplicationWrapper.java:60)
>     at org.jboss.seam.faces.environment.SeamApplicationWrapper$Proxy$_$$_WeldClientProxy.createConverter(SeamApplicationWrapper$Proxy$_$$_WeldClientProxy.java)
>     at com.sun.faces.facelets.tag.jsf.ValueHolderRule$LiteralConverterMetadata.applyMetadata(ValueHolderRule.java:85)
>     at com.sun.faces.facelets.tag.MetadataImpl.applyMetadata(MetadataImpl.java:81)
>     at javax.faces.view.facelets.MetaTagHandler.setAttributes(MetaTagHandler.java:129)
>     at javax.faces.view.facelets.DelegatingMetaTagHandler.setAttributes(DelegatingMetaTagHandler.java:102)
>     at org.richfaces.view.facelets.html.BehaviorsAddingComponentHandlerWrapper.setAttributes(BehaviorsAddingComponentHandlerWrapper.java:113)
>     at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.doNewComponentActions(ComponentTagHandlerDelegateImpl.java:409)
>     at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:159)
>     at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:120)
>     at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:98)
>     at javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:137)
>     at org.richfaces.view.facelets.html.BehaviorsAddingComponentHandlerWrapper.applyNextHandler(BehaviorsAddingComponentHandlerWrapper.java:53)
>     at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:184)
>     at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:120)
>     at javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:137)
>     at org.richfaces.view.facelets.html.BehaviorsAddingComponentHandlerWrapper.applyNextHandler(BehaviorsAddingComponentHandlerWrapper.java:53)
>     at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:184)
>     at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:120)
>     at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:98)
>     at javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:137)
>     at org.richfaces.view.facelets.html.BehaviorsAddingComponentHandlerWrapper.applyNextHandler(BehaviorsAddingComponentHandlerWrapper.java:53)
>     at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:184)
>     at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:120)
>     at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:98)
>     at javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:137)
>     at org.richfaces.view.facelets.html.BehaviorsAddingComponentHandlerWrapper.applyNextHandler(BehaviorsAddingComponentHandlerWrapper.java:53)
>     at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:184)
>     at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:120)
>     at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:98)
>     at javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:137)
>     at org.richfaces.view.facelets.html.BehaviorsAddingComponentHandlerWrapper.applyNextHandler(BehaviorsAddingComponentHandlerWrapper.java:53)
>     at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:184)
>     at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:120)
>     at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:98)
>     at javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:137)
>     at org.richfaces.view.facelets.html.BehaviorsAddingComponentHandlerWrapper.applyNextHandler(BehaviorsAddingComponentHandlerWrapper.java:53)
>     at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:184)
>     at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:120)
>     at javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:137)
>     at org.richfaces.view.facelets.html.BehaviorsAddingComponentHandlerWrapper.applyNextHandler(BehaviorsAddingComponentHandlerWrapper.java:53)
>     at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:184)
>     at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:120)
>     at javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandle.java:137)
>     at org.richfaces.view.facelets.html.BehaviorsAddingComponentHandlerWrapper.applyNextHandler(BeaviorsAddingComponentHandlerWrapper.java:53)
>     at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelgateImpl.java:184)
>     at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:120)
>     at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:98)
>     at com.sun.faces.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:93)
>     at com.sun.faces.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:86)
>     at com.sun.faces.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:308)
>     at com.sun.faces.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:367)
>     at com.sun.faces.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:346)
>     at com.sun.faces.facelets.impl.DefaultFaceletContext.includeFacelet(DefaultFaceletContext.java:199)
>     at com.sun.faces.facelets.tag.ui.IncludeHandler.apply(IncludeHandler.java:120)
>     at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:98)
>     at com.sun.faces.facelets.tag.ui.DefineHandler.applyDefinition(DefineHandler.java:107)
>     at com.sun.faces.facelets.tag.ui.CompositionHandler.apply(CompositionHandler.java:178)
>     at com.sun.faces.facelets.impl.DefaultFaceletContext$TemplateManager.apply(DefaultFaceletContext.java:395)
>     at com.sun.faces.facelets.impl.DefaultFaceletContext.includeDefinition(DefaultFaceletContext.java:366)
>     at com.sun.faces.facelets.tag.ui.InsertHandler.apply(InsertHandler.java:112)
>     at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:98)
>     at javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:137)
>     at org.richfaces.view.facelets.html.BehaviorsAddingComponentHandlerWrapper.applyNextHandler(BehaviorsAddingComponentHandlerWrapper.java:53)
>     at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:184)
>     at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:120)
>     at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:98)
>     at javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:137)
>     at org.richfaces.view.facelets.html.BehaviorsAddingComponentHandlerWrapper.applyNextHandler(BehaviorsAddingComponentHandlerWrapper.java:53)
>     at com.sun.faces.
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.jboss.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the seam-issues mailing list