-
1. Re: s:convertEntity null objects
joblini Mar 6, 2009 1:58 AM (in response to mkoperski)Try writing your own converter, here is an example:
@Name("fooConverter") @BypassInterceptors @Converter public class FooConverter implements Converter { @Transactional public Object getAsObject(FacesContext context, UIComponent cmp, String value) { EntityManager entityManager = (EntityManager) Component.getInstance("entityManager"); entityManager.joinTransaction(); // Do the conversion } public String getAsString(FacesContext context, UIComponent cmp, Object value) { // Do the conversion } }
-
2. Re: s:convertEntity null objects
mkoperski Mar 6, 2009 4:29 PM (in response to mkoperski)Nope it is not working.
It is very strange for me. Cause as I said there is no problem with list with clients they are fetched from DB, but when bounded object is proxy there is a problem that parameters are null in equals method. For me a little bit illogical. That depends if bounded object is proxy or not affect list of objects in selectOneMenu.The only one solution I ve found is to read client bounded to Order construct new Client via constructor and set it to Order again. It s not very elegant solution.
-
3. Re: s:convertEntity null objects
mkoperski Mar 18, 2009 2:02 PM (in response to mkoperski)OK Finally I have found solution.
If You take a look to class:
com.sun.faces.renderkit.html basic.MenuRenderer
(jsf-impl.jar version 1.2 04 which comes with JBoss 4.2.2.GA)
on line 535 We ve got such piece of code:try { newValue = context.getApplication().getExpressionFactory(). coerceToType(itemValue, type); } catch (Exception e) { // this should catch an ELException, but there is a bug // in ExpressionFactory.coerceToType() in GF newValue = null; }
The problem is that when type is proxy object class method coerceToType throws excpetion which is silently catched and newValue is null. This is the reason of null parameters in equals method that I mentioned.
Ok that is the diagnosis now the solution: I did something like this:
1. I ve added method getObjectClass to MenuRenderer:
private Class getObjectClass(Object o) { Class r = o.getClass(); if (r.getName().contains("$$")) { r = r.getSuperclass(); } return r; }
2. And modify line 535 like this
try { type = getObjectClass(itemValue); newValue = context.getApplication().getExpressionFactory(). coerceToType(itemValue, type); } catch (Exception e) { // this should catch an ELException, but there is a bug // in ExpressionFactory.coerceToType() in GF newValue = null; }
I ve based my solution on this post.
And I addiotionaly modified method getCurrentSelectedValues as mentioned in the post above.Concusion is that the problem occurs in JSF implemmentation. I am not sure but maybe upgrade to newest version of JSF impl will help but I did not have time to check it.