Ok well I've been fighting this problem for months now and have never really
figured out the best way to deal with it.  I'll give a short description
hopefully it makes sense:

public class Parent {
    private String firstname;
    private String lastname;
    private Address address;
   .. getters/setters etc.
}

Ok now my form object basically just has a getter/setter for a Parenty
object.

Within my jsp I want to use html:text elements for parent.firstname,
parent.lastname, AND parent.address.street, parent.address.city,
parent.address.state, etc.  Now the problem is address has the potential to
be loaded as null from the database if an address record is not tied to the
parent.  So in that case my jsp will throw a null pointer exception because
it tried to initialize the text element from a null'd variable member.  But
even if there is no record for that I want to be able to edit the field and
add one if its submitted.  This doesn't pose a problem for
firstname/lastname because the parent object will never be null.

The alternatives that I can see to solve this:
1) Use logic:notEmpty tags to display the textbox as long as there is a
record, but if theres not the user won't be able to edit on that page, so
that doesn't really solve the problem
2) Within my parent object in its constructor initialize any member object.
IE:
       public Parent () {
         address = new Address()
       }
3) Within the form's constructor make sure all of its member variables
variables are non null. IE:
      public myActionForm() {
        parent.setAddress(new Address());
      }
      I don't like this though because that requires me to edit the form
everytime I change ANY of the objects contained therein.

4) ??

I hope that was clear.. any alternatives or what is everyone else doing to
deal with this problem?
Thanks,
David


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to