commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jesse Vitrone" <>
Subject struts / commons - objects on the form
Date Wed, 16 Apr 2003 13:17:00 GMT
I posted this on the Struts mailing list, but then realized that it might be
more appropriate to post it here.  I included the email I posted below,
since I was replying to myself, start from the bottom and read up :)


This is what I meant - if I add this code:

if (value == null) {
    try {
        Method writeMethod = getWriteMethod(descriptor);
        if (writeMethod == null) {
            throw new NoSuchMethodException("Property '" + name +
                "' has no setter method");
        value = readMethod.getReturnType().newInstance();
        writeMethod.invoke(bean, new Object[] {value});
    } catch (Exception e) {

To the bottom of commons,

everything works like I want it to. If the bean on my form is not
initialized, it creates me a new one, and sets in on the form.

Would other people find something like this useful? That way, if I have a
Person who's info is being submitted, I can just have a Person on my form,
and property="person.firstName" in my htm:form, and all my Person info is
set for me, and then back in my Action class, I have my Person object to

Granted, if I init my Person in my form, it'd work with no code change, but
that means all my objects everywhere would need to be initialized. That's a
lot of object creation when we don't need it. Keep in mind, I don't just
mean the objects on the forms, IE - all the objects on my Person would need
to be initialized too, or else Struts / Commons will get a null when it
tries to set those. So I'm trying to be able to do this w/o having to init
all those objects.

Would anyone else find this useful? Do you think there should be a flag or
something we can set somewhere that tells Struts / Commons to do this?




-----Original Message-----

From: Jesse Vitrone [ <>] 

Sent: Monday, April 14, 2003 11:19 AM


Subject: Objects in the form


I just started looking at putting an object in the form, then in the jsp


<html:text property="object.field"/>

The only problem I'm running into is that if the object is null, then Struts
can't set it when I submit.

That's not a big deal for the object, because I can just init it in the
form, but for objects on objects, that means I have to init them all on my
beans, which I don't want to do since we check to see if things are null to
see if they've been set before.

Has anyone else run into this problem? Why doesn't Struts / Bean Commons
just check for null and create a new instance if it's null? Are there issues
with doing that?

Thanks in advance,




To unsubscribe, e-mail:

For additional commands, e-mail:

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message