You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Roger Kjensrud <ro...@cj.com> on 2001/01/11 18:39:44 UTC

Properties in ActionForms

Hello,

I wonder if any of you have implemented an automatic way of populating the
properties in the ActionForm? It's kind of tedious to write all these setter
and getter methods....

I found an
article(http://www.javaworld.com/javaworld/jw-12-2000/jw-1201-struts.html)
describing one way of doing this, and I would be interested in hearing some
feedback on doing it that way.

Thanks,
Roger Kjensrud



Re[4]: Properties in ActionForms

Posted by Oleg V Alexeev <go...@penza.net>.
Hello Martin,

With your example -

<form-bean name="AddressForm" validate="true">
  <property name="street"/>
  <property name="city" allowEmpty="false"
 errorMessage="error.city.required"/>
    <property name="zip" allowEmpty="false"
 errorMessage="error.zip.required"/>
 </form-bean>

Global error message -

<messages>
  <errorMessage group="field.empty" key="error.field.blank"/>
</messages>

All fields (without errorMessage) such as it -
<property name="city" allowEmpty="false"/>
will be processed with message from list global messages.

Type -
<property name="ordernum" allowEmpty="false"
 type="integer">
 <errorMessage group="field.empty" key="error.city.required"/>
 <errorMessage group="field.cast" key="error.number.conversion"/>
</property>

Global error message for casting -
<messages>
  <errorMessage group="field.empty" key="error.field.blank"/>
  <errorMessage group="field.cast.number" key="error.field.number.cast"/>
</messages>

All conversion operations with number properties will use global
message to generate error message in case of wrong conversion.


Friday, January 12, 2001, 7:54:44 AM, you wrote:

MC> Oleg,

MC> You mentioned four additions:

MC> - type
MC> - global error message for missing properties
MC> - error message for conversion error with property
MC> - global error message for properties of some type

MC> I understand the first one (type). There, I was just being lazy, since all
MC> my properties are Strings. :-)

MC> Can you help me understand what you mean by the other three?

MC> Thanks!

MC> --
MC> Martin Cooper
MC> Tumbleweed Communications

MC> ----- Original Message -----
MC> From: "Oleg V Alexeev" <go...@penza.net>
MC> To: "martin.cooper@tumbleweed.com" <st...@jakarta.apache.org>
MC> Sent: Thursday, January 11, 2001 1:31 PM
MC> Subject: Re[2]: Properties in ActionForms


>> Hello martin,
>>
>> Thursday, January 11, 2001, 10:50:00 PM, you wrote:
>>
>> mctc> Something I am working on at the moment is a very simple utility
MC> that
>> mctc> generates a form bean from an XML definition. The goal is simply to
MC> reduce
>> mctc> typing in generating beans - as Roger mentioned, it is kinda
MC> tedious. I'm
>> mctc> using something like this to specify a bean:
>>
>> mctc> <form-bean name="AddressForm" validate="true">
>> mctc>    <property name="street"/>
>> mctc>    <property name="city" allowEmpty="false"
>> mctc> errorMessage="error.city.required"/>
>> mctc>    <property name="zip" allowEmpty="false"
MC> errorMessage="error.zip.required"/>
>> mctc> </form-bean>
>>
>> mctc> Pretty simplistic stuff, but it meets my needs right now. If this
MC> would be
>> mctc> of interest to people (and if my company allows it), I can make it
>> mctc> available when I'm done.
>>
>> mctc> Also, if people have ideas on what it might do differently, or what
MC> else it
>> mctc> might do, I'd be interested in hearing them. And if anyone has a
MC> copy of
>> mctc> the messages from Mark Wutka mentioned in the Struts 1.1 TODO list,
MC> I'd
>> mctc> appreciate it if they could forward them to me.
>>
>> Good idea. I think global errorMessage for missing properties can be
>> defined. And add type as attribute for property. And add errorMessage
>> for convertion error with property. And add global errorMessage for
>> properties of some type.... 8)
>>
>> --
>> Best regards,
>>  Oleg                            mailto:gonza@penza.net
>>
>>





-- 
Best regards,
 Oleg                            mailto:gonza@penza.net



Re: Re[2]: Properties in ActionForms

Posted by Martin Cooper <ma...@tumbleweed.com>.
Oleg,

You mentioned four additions:

- type
- global error message for missing properties
- error message for conversion error with property
- global error message for properties of some type

I understand the first one (type). There, I was just being lazy, since all
my properties are Strings. :-)

Can you help me understand what you mean by the other three?

Thanks!

--
Martin Cooper
Tumbleweed Communications

----- Original Message -----
From: "Oleg V Alexeev" <go...@penza.net>
To: "martin.cooper@tumbleweed.com" <st...@jakarta.apache.org>
Sent: Thursday, January 11, 2001 1:31 PM
Subject: Re[2]: Properties in ActionForms


> Hello martin,
>
> Thursday, January 11, 2001, 10:50:00 PM, you wrote:
>
> mctc> Something I am working on at the moment is a very simple utility
that
> mctc> generates a form bean from an XML definition. The goal is simply to
reduce
> mctc> typing in generating beans - as Roger mentioned, it is kinda
tedious. I'm
> mctc> using something like this to specify a bean:
>
> mctc> <form-bean name="AddressForm" validate="true">
> mctc>    <property name="street"/>
> mctc>    <property name="city" allowEmpty="false"
> mctc> errorMessage="error.city.required"/>
> mctc>    <property name="zip" allowEmpty="false"
errorMessage="error.zip.required"/>
> mctc> </form-bean>
>
> mctc> Pretty simplistic stuff, but it meets my needs right now. If this
would be
> mctc> of interest to people (and if my company allows it), I can make it
> mctc> available when I'm done.
>
> mctc> Also, if people have ideas on what it might do differently, or what
else it
> mctc> might do, I'd be interested in hearing them. And if anyone has a
copy of
> mctc> the messages from Mark Wutka mentioned in the Struts 1.1 TODO list,
I'd
> mctc> appreciate it if they could forward them to me.
>
> Good idea. I think global errorMessage for missing properties can be
> defined. And add type as attribute for property. And add errorMessage
> for convertion error with property. And add global errorMessage for
> properties of some type.... 8)
>
> --
> Best regards,
>  Oleg                            mailto:gonza@penza.net
>
>



Re[2]: Properties in ActionForms

Posted by Oleg V Alexeev <go...@penza.net>.
Hello martin,

Thursday, January 11, 2001, 10:50:00 PM, you wrote:

mctc> Something I am working on at the moment is a very simple utility that 
mctc> generates a form bean from an XML definition. The goal is simply to reduce 
mctc> typing in generating beans - as Roger mentioned, it is kinda tedious. I'm 
mctc> using something like this to specify a bean:

mctc> <form-bean name="AddressForm" validate="true">
mctc>    <property name="street"/>
mctc>    <property name="city" allowEmpty="false" 
mctc> errorMessage="error.city.required"/>
mctc>    <property name="zip" allowEmpty="false" errorMessage="error.zip.required"/>
mctc> </form-bean>

mctc> Pretty simplistic stuff, but it meets my needs right now. If this would be 
mctc> of interest to people (and if my company allows it), I can make it 
mctc> available when I'm done.

mctc> Also, if people have ideas on what it might do differently, or what else it 
mctc> might do, I'd be interested in hearing them. And if anyone has a copy of 
mctc> the messages from Mark Wutka mentioned in the Struts 1.1 TODO list, I'd 
mctc> appreciate it if they could forward them to me.

Good idea. I think global errorMessage for missing properties can be
defined. And add type as attribute for property. And add errorMessage
for convertion error with property. And add global errorMessage for
properties of some type.... 8)

-- 
Best regards,
 Oleg                            mailto:gonza@penza.net



Re: Properties in ActionForms

Posted by ma...@tumbleweed.com.
Something I am working on at the moment is a very simple utility that 
generates a form bean from an XML definition. The goal is simply to reduce 
typing in generating beans - as Roger mentioned, it is kinda tedious. I'm 
using something like this to specify a bean:

<form-bean name="AddressForm" validate="true">
   <property name="street"/>
   <property name="city" allowEmpty="false" 
errorMessage="error.city.required"/>
   <property name="zip" allowEmpty="false" errorMessage="error.zip.required"/>
</form-bean>

Pretty simplistic stuff, but it meets my needs right now. If this would be 
of interest to people (and if my company allows it), I can make it 
available when I'm done.

Also, if people have ideas on what it might do differently, or what else it 
might do, I'd be interested in hearing them. And if anyone has a copy of 
the messages from Mark Wutka mentioned in the Struts 1.1 TODO list, I'd 
appreciate it if they could forward them to me.

Thanks!

--
Martin Cooper
Tumbleweed Communications


At 10:12 AM 1/11/01 -0800, you wrote:
>Roger Kjensrud wrote:
>
> > Hello,
> >
> > I wonder if any of you have implemented an automatic way of populating the
> > properties in the ActionForm? It's kind of tedious to write all these 
> setter
> > and getter methods....
> >
>
>For generating the code of a form bean automatically, that is something I want
>to look at in the 1.1 time frame.  As well, we need to look at use cases where
>you do not know the property names ahead of time, and need them to work 
>totally
>dynamically.
>
>For populating the properties, if you are trying to copy things from a 
>"business
>logic" bean that has the same property names, consider the
>PropertyUtils.copyProperties() method.
>
> >
> > I found an
> > article(http://www.javaworld.com/javaworld/jw-12-2000/jw-1201-struts.html)
> > describing one way of doing this, and I would be interested in hearing some
> > feedback on doing it that way.
> >
> > Thanks,
> > Roger Kjensrud
>
>Craig McClanahan



Re: Properties in ActionForms

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
Roger Kjensrud wrote:

> Hello,
>
> I wonder if any of you have implemented an automatic way of populating the
> properties in the ActionForm? It's kind of tedious to write all these setter
> and getter methods....
>

For generating the code of a form bean automatically, that is something I want
to look at in the 1.1 time frame.  As well, we need to look at use cases where
you do not know the property names ahead of time, and need them to work totally
dynamically.

For populating the properties, if you are trying to copy things from a "business
logic" bean that has the same property names, consider the
PropertyUtils.copyProperties() method.

>
> I found an
> article(http://www.javaworld.com/javaworld/jw-12-2000/jw-1201-struts.html)
> describing one way of doing this, and I would be interested in hearing some
> feedback on doing it that way.
>
> Thanks,
> Roger Kjensrud

Craig McClanahan



Re[2]: Properties in ActionForms

Posted by Oleg V Alexeev <go...@penza.net>.
Hello Craig,

Thursday, January 11, 2001, 9:46:45 PM, you wrote:

CRM> We're talking futures in terms of Struts here, but my question is ... aren't you
CRM> doing the Locale-specific conversion a little bit too early?

CRM> My thinking is that business logic objects maintain data objects in a
CRM> Locale-insensitive format (like java.util.GregorianCalendar or
CRM> java.math.BigDecimal).  And, the ActionForm properties would be of the same
CRM> type.  Conversion to or from String would happen at the last minute -- just as
CRM> you prepare the page for display, or as you are accepting the input.

CRM> Admittedly, we need better support in Struts (such as your formatting version of
CRM> <bean:write>, and a way to process the input string with PropertyEditor type
CRM> classes) to make this strategy really effective, but I would suggest not doing
CRM> the Locale-specific formatting until you have to.

We start work at struts 0.5 stage and found some troubles with
non-String properties for Form beans. Because of it I break classes to
the groups: 1-form beans (String only properties) and 2-data beans
(with such types of properties as Integer, Date, etc.). Action class
fills form bean with values from data bean and make locale specific
conversion at this stage. User fills form with new values and submit
it to the save action. Save action takes String values from form and
make conversion to the internal representation (Integer, Date, etc.)
There are two variants to perform conversion to/from form beans -
place all logic in set/get methods in form or incorporate
import/export methods to the form beans and call it on phase of init
or submit. But locale specific conversion needs to be performed with
current locale and value of current locale must be retrieved every
set/get calling. And because of it I make import/export methods, where
is place to perform all locale specific operations - retrieve locale,
retrieve format beans, convert values to/from String.
For my mind it is most effective way to perform tranlation, but I
don't like this scheme... Can you pass some words about another
solution, if you have one?

-- 
Best regards,
 Oleg                            mailto:gonza@penza.net



Re: Properties in ActionForms

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
Oleg V Alexeev wrote:

> Hello Ted,
>
> In my application I use import/export methods in Form classes. For the
> first time I try to use PropertyUtils.copyProperties(), but this
> method convert properties without locale choosing. I need to process
> different time/date and number formats for different languages.
> Because of it I use my own methods to convert values to String and
> from String to values.
> I think that locale must be used to convert values in
> PropertyUtils.copyProperties() and in <bean:write> tag.
> If anybody can suggest another way, plesase, I am very interested in
> it.
>

We're talking futures in terms of Struts here, but my question is ... aren't you
doing the Locale-specific conversion a little bit too early?

My thinking is that business logic objects maintain data objects in a
Locale-insensitive format (like java.util.GregorianCalendar or
java.math.BigDecimal).  And, the ActionForm properties would be of the same
type.  Conversion to or from String would happen at the last minute -- just as
you prepare the page for display, or as you are accepting the input.

Admittedly, we need better support in Struts (such as your formatting version of
<bean:write>, and a way to process the input string with PropertyEditor type
classes) to make this strategy really effective, but I would suggest not doing
the Locale-specific formatting until you have to.

Craig



Re[2]: Properties in ActionForms

Posted by Oleg V Alexeev <go...@penza.net>.
Hello Ted,

In my application I use import/export methods in Form classes. For the
first time I try to use PropertyUtils.copyProperties(), but this
method convert properties without locale choosing. I need to process
different time/date and number formats for different languages.
Because of it I use my own methods to convert values to String and
from String to values.
I think that locale must be used to convert values in
PropertyUtils.copyProperties() and in <bean:write> tag.
If anybody can suggest another way, plesase, I am very interested in
it. 

Thursday, January 11, 2001, 9:17:49 PM, you wrote:

>>I wonder if any of you have implemented an automatic way of populating
TH> the properties in the ActionForm? 

TH> Doing more with "auto beans" is being discussed for the 1.1 timefreame.
TH> Meanwhile, the latest builds support the next best thing: You can
TH> define generic data beans for your business logic data, and then make
TH> these instance variables on your action forms. The HTML form tags now
TH> support a nested syntax like this:
  
TH>       <html:text property="mailingAddress.street"/>
  
TH> and the appropriate processing will be applied to get the street
TH> address (for initial display) and set the street address (when the form
TH> is processed).

TH> Of course, you still have to define the accessor and mutators for your
TH> generic data beans, but it's a step in the right direction!

TH> *********** REPLY SEPARATOR  ***********

TH> On 1/11/2001 at 9:39 AM Roger Kjensrud wrote:

TH> Hello,

TH> I wonder if any of you have implemented an automatic way of populating
TH> the
TH> properties in the ActionForm? It's kind of tedious to write all these
TH> setter
TH> and getter methods....

TH> I found an
TH> article(http://www.javaworld.com/javaworld/jw-12-2000/jw-1201-struts.htm
TH> l)
TH> describing one way of doing this, and I would be interested in hearing
TH> some
TH> feedback on doing it that way.

TH> Thanks,
TH> Roger Kjensrud





-- 
Best regards,
 Oleg                            mailto:gonza@penza.net



Re: Properties in ActionForms

Posted by Ted Husted <ne...@husted.com>.
>I wonder if any of you have implemented an automatic way of populating
the properties in the ActionForm? 

Doing more with "auto beans" is being discussed for the 1.1 timefreame.
Meanwhile, the latest builds support the next best thing: You can
define generic data beans for your business logic data, and then make
these instance variables on your action forms. The HTML form tags now
support a nested syntax like this:
  
      <html:text property="mailingAddress.street"/>
  
and the appropriate processing will be applied to get the street
address (for initial display) and set the street address (when the form
is processed).

Of course, you still have to define the accessor and mutators for your
generic data beans, but it's a step in the right direction!

*********** REPLY SEPARATOR  ***********

On 1/11/2001 at 9:39 AM Roger Kjensrud wrote:

Hello,

I wonder if any of you have implemented an automatic way of populating
the
properties in the ActionForm? It's kind of tedious to write all these
setter
and getter methods....

I found an
article(http://www.javaworld.com/javaworld/jw-12-2000/jw-1201-struts.htm
l)
describing one way of doing this, and I would be interested in hearing
some
feedback on doing it that way.

Thanks,
Roger Kjensrud