[jboss-user] [JBoss Seam] - Re: s:selectItems and subclasses

MSchmidke do-not-reply at jboss.com
Tue Nov 13 07:17:27 EST 2007


Seam Version is 2.0.0.CR1.
JSF RI from JBoss 4.2.

No stack trace available since the exception is silently caught.

Have a look at JSF RI MenuRenderer.java lines 535 ff:

  |         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;
  |         }
  | 

So, I think it is not a bug of Seam, but it is a limitation of JSF which appears when using Seam UI components (it might appear without Seam, but it will appear with Seam), and since Seam is nothing but repairing things which are missing in the other frameworks, it would be nice if Seam could repair even this.

I have worked around this by replacing the MenuRenderer class, changing getCurrentSelectedValues() method: Instead of

  | if (size > 0) {
  |   // get the type of the first element - Should
  |   // we assume that all elements of the List are
  |   // the same type?
  |   return list.toArray((Object[]) Array.newInstance(
  |     list.iterator().next().getClass(),
  |     size));
  | } else {
  |   return ((Collection) value).toArray();
  | }
  | 

I have 

  | if (size > 0) {
  |   // get the type of the first element - Should
  |   // we assume that all elements of the List are
  |   // the same type?
  |   return list.toArray((Object[]) Array.newInstance(
  |     getObjectClass(list.iterator().next()), 
  |     size));
  | } else {
  |   return ((Collection) value).toArray();
  | }
  | 

with


  | private Class getObjectClass(Object o) {
  | 	Class r = o.getClass();
  | 	if (r.getName().contains("$$")) {
  | 		r = r.getSuperclass();
  | 	}
  | 	return r;
  | }
  | 

This method changes the class from "Proxy-For-A" to "A", so that even Bs and Cs may match.

This is clearly a hack, but for the moment, it works for me.

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

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



More information about the jboss-user mailing list