Thank you for your feedback Richard.<div><br></div><div>I tried your proposal and it breaks something else because the annotated class is used everywhere to convert the POJO, and on the log I can find this line:</div><div>
<br></div><div><div>10:45:46,485 INFO [javax.enterprise.resource.webcontainer.jsf.renderkit] (http--127.0.0.1-8080-2) WARNING: FacesMessage(s) have been enqueued, but may not have been displayed.</div><div>sourceId=create:accountBeanAccountGroupsSelect[severity=(ERROR 2), summary=(create:accountBeanAccountGroupsSelect: Validation Error: Value is not valid), detail=(create:accountBeanAccountGroupsSelect: Validation Error: Value is not valid)]</div>
</div><div><br></div><div>Regarding the solution I proposed, I agree that generated code must be simple, but I really can't figure another way to inject an extended persistence context inside a client object.</div><div>
<br></div><div>In case we factor out the converter and write an util class with a factory that hide that complexity.</div><div><br></div><div>What do you think ?</div><div><br></div><div><br><br><div class="gmail_quote">
2012/8/6 Richard Kennard <span dir="ltr"><<a href="mailto:richard@kennardconsulting.com" target="_blank">richard@kennardconsulting.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Luca,<br>
<br>
Thanks for your time and help debugging this. I think we need to proceed with caution.<br>
<br>
We're basically talking about hacks to work around bugs in the app server/shortcomings in the EE spec. The problem is these hacks are going to get<br>
re-generated for every domain entity (potentially dozens of times). It's critical we try to keep our generated code as clean as possible. In particular, we<br>
must keep the 'semantic complexity' low.<br>
<br>
The solution you're suggesting (injecting a SessionContext, taking EJBObject using getBusinessInterface etc) sounds like a lot of 'semantic complexity' for<br>
new users to understand?<br>
<br>
It's really important we try to find the cleanest approach. We tried/rejected a lot of variations when developing the current code. Here's one that's not<br>
quite as nice as the current one, but may work properly across TomEE/Weblogic/JBoss. Could you try it for me?<br>
<br>
1. Remove all references in the generated Facelets code to: converter="#{foo.converter}"<br>
2. Remove the 'getConverter()' method inside each xxxBean and replace with a static inner class that looks like:<br>
<br>
@FacesConverter( forClass = xxx.class )<br>
public static class xxxConverter<br>
implements Converter {<br>
<br>
@Override<br>
public Object getAsObject( FacesContext context, UIComponent component, String value ) {<br>
<br>
// EntityManager injection not reliable on all platforms<br>
<br>
xxx entity = new xxx();<br>
entity.setId( Long.valueOf( value ) );<br>
return entity;<br>
}<br>
<br>
@Override<br>
public String getAsString( FacesContext context, UIComponent component, Object value ) {<br>
<br>
...<br>
}<br>
}<br>
<br>
Here's a complete example:<br>
<br>
<a href="https://github.com/metawidget/metawidget/blob/master/integration-tests/faces/forge/src/main/java/com/test/view/PersonBean.java" target="_blank">https://github.com/metawidget/metawidget/blob/master/integration-tests/faces/forge/src/main/java/com/test/view/PersonBean.java</a><br>
<br>
Regards,<br>
<br>
Richard.<br>
<div><div class="h5"><br>
On 3/08/2012 9:17 PM, Luca Masini wrote:<br>
> The fact is that we have an extended persistente unit bound to the stateful ejb, so can't be injected or looked up.<br>
><br>
> I've found a solution working on my three target App Server (TomEE, Weblogic, JBoss).<br>
><br>
> Inject a SessionContext and take the EJBObject using the getBusinessInterface method.<br>
><br>
> For some strange reason SessionContext and his Ejb have different lifecycle so we need to take it before it is returned to the jsf client.<br>
><br>
> This way it works.<br>
><br>
> Il giorno venerdė 3 agosto 2012, Richard Kennard ha scritto:<br>
><br>
> Yes, you could try that. The history to this decision was:<br>
><br>
> 1. The Converter needs to use an EntityManager to load the entity<br>
> 2. For some reason you cannot (yet) inject EntityManagers into FacesConverters<br>
><br>
> So I made the Converter an inner class of the xxxBean, so that it could access the bean's EntityManager. However there would be other approaches, such as<br>
> looking up the EntityManager via JNDI or something.<br>
><br>
> Regards,<br>
><br>
> Richard.<br>
><br>
> On 3/08/2012 8:15 PM, Thomas Frühbeck wrote:<br>
> > Did you think of separating Converter and backing bean implementation?<br>
> > AFAIK the backing bean _provides_ a converter e.g.: #{xxxxxBean.converter} but should not implement Converter itself?<br>
> ><br>
> > Thomas<br>
> ><br>
> > Am 03.08.2012 11:13, schrieb Luca Masini:<br>
> >> I'm going crazy to let the generated faces scaffolding run on both WLS and JBoss.<br>
> >><br>
> >> Infact if I let the Bean implements the Converter interface then WLS works but JBoss complaints about missing method, it's like that the implemented<br>
> >> interface is the Local interface for the bean and no other method is found but those in the Converter interface itself.<br>
> >><br>
> >> So I remove the interface and everything work without the getConverter method, getAsObject and getAsString are method of the now interface bean.<br>
> >><br>
> >> On the counter side WLS is unable to call methods from the EL into faces files that are not part of the Converter interface.<br>
> >><br>
> >> So I'm in a deadlock. I'm unable to let it works on both the Java EE 6 server. I'm sure that a solution exist, but whichi ?<br>
> >><br>
> >> --<br>
> >> ****************************************<br>
> >> <a href="http://www.lucamasini.net" target="_blank">http://www.lucamasini.net</a><br>
> >> <a href="http://twitter.com/lmasini" target="_blank">http://twitter.com/lmasini</a><br>
> >> <a href="http://www.linkedin.com/pub/luca-masini/7/10/2b9" target="_blank">http://www.linkedin.com/pub/luca-masini/7/10/2b9</a><br>
> >> ****************************************<br>
> >><br>
> >><br>
> >> _______________________________________________<br>
> >> forge-dev mailing list<br>
</div></div>> >> <a href="mailto:forge-dev@lists.jboss.org">forge-dev@lists.jboss.org</a> <javascript:;><br>
<div class="im">> >> <a href="https://lists.jboss.org/mailman/listinfo/forge-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/forge-dev</a><br>
> ><br>
> ><br>
> ><br>
> ><br>
> > _______________________________________________<br>
> > forge-dev mailing list<br>
</div>> > <a href="mailto:forge-dev@lists.jboss.org">forge-dev@lists.jboss.org</a> <javascript:;><br>
<div class="im">> > <a href="https://lists.jboss.org/mailman/listinfo/forge-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/forge-dev</a><br>
><br>
> _______________________________________________<br>
> forge-dev mailing list<br>
</div>> <a href="mailto:forge-dev@lists.jboss.org">forge-dev@lists.jboss.org</a> <javascript:;><br>
<div class="im HOEnZb">> <a href="https://lists.jboss.org/mailman/listinfo/forge-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/forge-dev</a><br>
><br>
><br>
><br>
> --<br>
> ****************************************<br>
> <a href="http://www.lucamasini.net" target="_blank">http://www.lucamasini.net</a><br>
> <a href="http://twitter.com/lmasini" target="_blank">http://twitter.com/lmasini</a><br>
> <a href="http://www.linkedin.com/pub/luca-masini/7/10/2b9" target="_blank">http://www.linkedin.com/pub/luca-masini/7/10/2b9</a><br>
> ****************************************<br>
><br>
><br>
</div><div class="HOEnZb"><div class="h5">> _______________________________________________<br>
> forge-dev mailing list<br>
> <a href="mailto:forge-dev@lists.jboss.org">forge-dev@lists.jboss.org</a><br>
> <a href="https://lists.jboss.org/mailman/listinfo/forge-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/forge-dev</a><br>
<br>
_______________________________________________<br>
forge-dev mailing list<br>
<a href="mailto:forge-dev@lists.jboss.org">forge-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/forge-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/forge-dev</a><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br>****************************************<br><a href="http://www.lucamasini.net">http://www.lucamasini.net</a><br><a href="http://twitter.com/lmasini">http://twitter.com/lmasini</a><br>
<a href="http://www.linkedin.com/pub/luca-masini/7/10/2b9">http://www.linkedin.com/pub/luca-masini/7/10/2b9</a><br>****************************************<br>
</div>