[jboss-user] [JBoss Eclipse IDE (users)] - Polimorphism problem

przemjaskier do-not-reply at jboss.com
Wed Feb 14 04:23:52 EST 2007


Polimorphism problem

** Problem: I cannot customize content of a template, depending on a type of returned hibernate @Entity.

** Environment: MyFaces 1.1.4, Facelets 1.1.12, Seam 1.1.6, Hibernate 3.2.1.

** Situation:
I have three Hibernate entities:
1. Item - annotated with @Inheritance(strategy=InheritanceType.SINGLE_TABLE), @DiscriminatorColumn, @DiscriminatorValue, @Entity
       public void getProperty();
       isExtendedFlagSet(); //returning true only when this is instance of
                                     //ExtendedItem below (I need such flags in 
                                    //general)
2. ExtendedItem extends Item - annotated with @DiscriminatorValue, @Entity
       public void getExtendedProperty();
3. ItemHolder - annotated with @Entity
       Item getItem();

And an EVENT scope backer:
currentItemProvider getting ItemHolder proxies/instances from Hibernate.

And two jsf+facelets templates, which I want to render different in case when ItemHolder.getItem()
returns instance if ExtendedItem than when it returns instance of Item.

** My (not working completely) solution:

Using custom, render-time-if component, which renders children when "currentItemProvider.itemholder.item.extendedFlagSet" is true,
   enable fragment of page:

    <h:outputText value="#{currentItemProvider.itemholder.item.property}"/>
    <mycomp:renderTimeIf condition="#{currentItemProvider.itemholder.item.extendedFlagSet}">
        
        
            <h:outputText value="#{currentItemProvider.itemholder.item.extendedProperty}"/>
        
    </mycomp:renderTimeIf>

1. WORKS OK, when placed in a render-time loop of ui:repeat. Different item appear
on a page rendered according to their isExtendedFlagSet value

2. But DOESN'T work when put in compile-time ui:decorate or direct in a template. I get:

SEVERE: Error Rendering View[/itemDetails.xhtml]
javax.faces.el.PropertyNotFoundException: /WEB-INF/templates/itemtemplate.xhtml @18,132 value="#{currentItemProvider.itemholder.item.extendedProperty}":
Bean: package.Item$$EnhancerByCGLIB$$b215fa4e, property: extendedProperty
	at com.sun.facelets.el.LegacyValueBinding.getValue(LegacyValueBinding.java:58)
	at javax.faces.component.UIOutput.getValue(UIOutput.java:77)
	at org.apache.myfaces.shared_impl.renderkit.RendererUtils.getStringValue(RendererUtils.java:217)
	at org.apache.myfaces.shared_impl.renderkit.html.HtmlTextRendererBase.renderOutput(HtmlTextRendererBase.java:69)
	at org.apache.myfaces.shared_impl.renderkit.html.HtmlTextRendererBase.encodeEnd(HtmlTextRendererBase.java:57)
	at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:536)


** Question: how to deal with such instance-dependent customization? I have a huge, complex domain (above is only a simplified illustration)
and would gladly stay with this consistent isFlasSet() approach, but if it should be done in a different way, please suggest.

Regards,
Przemek

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4016255#4016255

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4016255



More information about the jboss-user mailing list