I tweaked your wrap method to add some extra functionality.

I added the following annotation property to SelectItems.

 
  |    /**
  |      * If specified along with Strategy.OBJECT, and new
  |      * object with the specified empty lable will be added.
  |      * 
  |      * @return The method to call for a custom disabled value.
  |      */
  |     String emptyValueLabel() default "";
  | 

I modified the wrap methond on SelectItemsBinder to add an empty object with 
the specified emptyValueLabe.

I needed this because my users do not like when their drop downs are set to a 
value already and I wanted to control this where I load the collection.

I also needed this for an Excel style autofilter that I implemented.  I need a 
select option labled "Any" so I can conditionally include parts of a 
dynamically generated HQL query.


  |   public List<SelectItem> wrap(SelectItems ann, List list)
  |   {
  |     if (list != null)
  |     {
  |       WrappingArrayList<SelectItem> selectItems = new 
WrappingArrayList<SelectItem>();
  |       selectItems.setWrappedData(list);
  | 
  |       if (ann.emptyValueLabel().length() > 0 && ann.valueStrategy() == 
SelectItems.Strategy.OBJECT)
  |       {
  |         try
  |         {
  |           // Get an new instance of the type of the first object in the 
list.
  |           // If there is a problem do nothing.
  |           Object obj = list.get(0).getClass().newInstance();
  |           selectItems.add(new SelectItem(obj, ann.emptyValueLabel()));
  |         } catch (Exception e) { }
  |       }
  |       for (int i = 0; i < list.size(); i++)
  |       {
  |         selectItems.add(convertToSelectItem(String.valueOf(i), list.get(i), 
ann));
  |       }
  |       return selectItems;
  |     } else
  |     {
  |       return null;
  |     }
  |   }
  | 

The annotaion in use looks like this.

  |   @SelectItems(valueStrategy   = SelectItems.Strategy.OBJECT,
  |                labelMethod     = "getGrade",
  |                emptyValueLabel = "Any")
  |   private List gradeSelectItems;
  | 

I would like to hear others comments for improvement of this technique and 
expanding the funtionality of this in other ways.

The autofilter is much appreciated by my users, but still takes too much effort 
to set up.

I would like for it to me a pluggable configurable component.

Has anyone developed something like this yet?

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

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

Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
JBoss-user mailing list
JBoss-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to