History | Log In     View a printable version of the current page. Get help!  
Issue Details (XML | Word)

Key: STS-314
Type: Improvement Improvement
Status: Resolved Resolved
Resolution: Fixed
Priority: Minor Minor
Assignee: Aaron Porter
Reporter: Gregg Bolinger
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Stripes

stripes:options-collection null Collections

Created: 30/Nov/06 11:32 AM   Updated: 22/Mar/07 07:34 AM
Component/s: Tag Library
Affects Version/s: Release 1.4.2
Fix Version/s: Release 1.4.3

Environment: All


 Description  « Hide
It would be nice if the options-collection tag handled null Collections. Currently, you have to wrap the tag declaration around some sort of check like:

<c:if test="${someCollection != null}">
   <stripes:options-collection...../>
</c:if>

While this is fairly easy and straightfoward, it's more verbose than need be.

 All   Comments   Change History      Sort Order:
Aaron Porter [15/Jan/07 10:05 PM]
NPE occurs on empty collection as well.

This works well for me:

Index: /home/aaron/workspace/stripes/stripes/src/net/sourceforge/stripes/tag/InputOptionsCollectionTag.java
===================================================================
--- /home/aaron/workspace/stripes/stripes/src/net/sourceforge/stripes/tag/InputOptionsCollectionTag.java (revision 476)
+++ /home/aaron/workspace/stripes/stripes/src/net/sourceforge/stripes/tag/InputOptionsCollectionTag.java (working copy)
@@ -96,7 +96,7 @@
     }
 
     /** Internal list of entires that is assembled from the items in the collection. */
- private List<Entry> entries;
+ private List<Entry> entries = new LinkedList<Entry>();
 
     /** Sets the collection that will be used to generate options. */
     public void setCollection(Collection collection) {
@@ -161,7 +161,6 @@
      * @param value the actual value for the option
      */
     protected void addEntry(Object item, Object label, Object value) {
- if (this.entries == null) this.entries = new LinkedList<Entry>();
         this.entries.add(new Entry(item, label, value));
     }
 
@@ -175,6 +174,9 @@
      * not present on the beans in the collection
      */
     public int doStartTag() throws JspException {
+ if (this.collection == null)
+ return SKIP_BODY;
+
         String labelProperty = getLabel();
         String valueProperty = getValue();
 

Aaron Porter [22/Mar/07 07:34 AM]
Committed the patch I submitted earlier in SVN revision 490.