Sparse indexed properties and avoiding nulls in resulting Lists

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Sparse indexed properties and avoiding nulls in resulting Lists

lsavolainen
Hello,

This is my first time posting here so my apologies in advance if I am not doing this the right way. :)

My Stripes application contains a form which has several rows of fields that correspond to a list in an object accessible in my ActionBean. When the user decides, for example, to fill the first and the third row while leaving the second one blank I get a List which has instances at indexes 0 and 2 and a null at 1. Is it possible to avoid having nulls bound to my list? Is there some alternative way I should implement this?

A simplified example:

class MyActionBean
  private Submission submission

class Submission
  private List<Thing> things

class Thing
  private propA
  private propB

And in the JSP template:
<s:text name="submission.things[0].propA"/>
<s:text name="submission.things[0].propB"/>
<s:text name="submission.things[1].propA"/>
<s:text name="submission.things[1].propB"/>
<s:text name="submission.things[2].propA"/>
<s:text name="submission.things[2].propB"/>

.. and when the user just fills the [0] and [2] inputs and submits the form I end up with a Submission instance that has a things list that has a null as the second element.

With regards,
Lauri Savolainen