struts ActionForm pattern

From: analogueboy (analogueboy_at_NOSPAMPLS.blueyonder.co.uk)
Date: 03/31/04


Date: Wed, 31 Mar 2004 12:52:21 +0100

I've two problems that i am trying to over-come with struts action forms
which I'd like to ask other people's advice on. Ultimately I want to be
able to re-use the same ActionForms and HTML forms (in JSP files) for
creating and updating objects.

1. java.util.Date form elements, I'd like to pass a value from a form
straight into a Date object on the server. When I try and do that currently
I get incompatibility exceptions from BeanUtils. To get around the problem,
I create a string object and use java.text.SimpleDateFormat to convert the
values for me. Am I missing something here? Can I set a default pattern for
the DateFormat that BeanUtils can use? What have other people done to get
around this?

2. When I use ActionForms, I create member classes like this

public class MyForm extends ActionForm{
    private Profile profile;

    public MyForm(){
        profile = new Profile();
    }
    public Profile getProfile(){
        return this.profile;
    }
    public void setProfile(Profile profile){
        this.profile = profile;
    }
}

So my form elements look like this
<html:text property="profile.name"/>

Which saves having to populate the bean by hand. The problem is that if
Profile has a complex Object as a member variable and I set that as the
property of the HTML form element like this

<html:text property="profile.parent.name"/>

Then I get NPE's because parent will be null when the form is being used to
create a new Profile, editing is OK because the values have been
initialised.

I know that I could initialise the values myself, but I'd like to be able to
use the Tags like JSTL where nulls are handled more gracefully and are not
terminal to the rendering of the JSP. Will the Struts-El tags handle this
condition for me?

TIA

AB