You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Michael McGrady <mi...@michaelmcgrady.com> on 2004/08/25 19:53:56 UTC
Maps in Forms
I am using the following in an action form:
public void setMap(Map map) {
this.map = map;
}
public Map getMap() {
return map;
}
public void setValue(Object key, Object value) {
map.put(key,value);
}
public Object getValue(Object key) {
return map.get(key);
}
Yet, when I put setValue("test","TEST") into the session, I get the
following exception from the attempted use of <html:bean name="formName"
property="value(test)"/>:
"No getter method for property value(test) of bean formName"
This is quite a surprise. Anyone know what is going wrong here?
Sometimes the simplest things go wrong?
Michael
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Maps in Forms
Posted by Michael McGrady <mi...@michaelmcgrady.com>.
Rick Reumann wrote:
>
> As I side I really don't like Map backed ActionForms (I used to love
> them:) for the same reason that I don't like DynaForms (basically a
> Map form). The potential for problems later setting the properties is
> what bothers me. There isn't any compile time safety. Nothing would
> prevent you in your Action from doing...
>
> form.setValue("empNamme","John Doe") when in reality you wanted...
>
> form.setValue("empName", "John Doe")
>
> Even if you use constants for your keys it still can make a mess of
> things. I really like regular ActionForms now with your typical bean
> properties.
>
> Also you get the advantage of nice IDE automcomplete stuff using a
> regular Java bean:)
>
> form.setEm...(autocompletes.. to setEmpName( ) )
>
> Not that an IDE would be my reason for not using Map backed forms -
> it's the lack of compile time checks that I don't like.
>
> Michael McGrady wrote:
>
>> I am using the following in an action form:
>>
>>
>>
>> public void setMap(Map map) {
>> this.map = map;
>> }
>>
>> public Map getMap() {
>> return map;
>> }
>>
>> public void setValue(Object key, Object value) {
>> map.put(key,value);
>> }
>>
>> public Object getValue(Object key) {
>> return map.get(key);
>> }
>>
>>
>> Yet, when I put setValue("test","TEST") into the session, I get the
>> following exception from the attempted use of <html:bean
>> name="formName" property="value(test)"/>:
>>
>> "No getter method for property value(test) of bean formName"
>>
>> This is quite a surprise. Anyone know what is going wrong here?
>> Sometimes the simplest things go wrong?
>>
>> Michael
>
I use these solely for logic, Rick. In a Process.java class I use keys
of public static final String LEVEL_1 = "LEVEL_1"; etc. as the keys.
So, there is no problem with no warning at compilation, etc. This
allows repeated use of the same keys for navigation purposes at the
request level.
Michael
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Maps in Forms
Posted by Rick Reumann <st...@reumann.net>.
As I side I really don't like Map backed ActionForms (I used to love
them:) for the same reason that I don't like DynaForms (basically a Map
form). The potential for problems later setting the properties is what
bothers me. There isn't any compile time safety. Nothing would prevent
you in your Action from doing...
form.setValue("empNamme","John Doe") when in reality you wanted...
form.setValue("empName", "John Doe")
Even if you use constants for your keys it still can make a mess of
things. I really like regular ActionForms now with your typical bean
properties.
Also you get the advantage of nice IDE automcomplete stuff using a
regular Java bean:)
form.setEm...(autocompletes.. to setEmpName( ) )
Not that an IDE would be my reason for not using Map backed forms - it's
the lack of compile time checks that I don't like.
Michael McGrady wrote:
> I am using the following in an action form:
>
>
>
> public void setMap(Map map) {
> this.map = map;
> }
>
> public Map getMap() {
> return map;
> }
>
> public void setValue(Object key, Object value) {
> map.put(key,value);
> }
>
> public Object getValue(Object key) {
> return map.get(key);
> }
>
>
> Yet, when I put setValue("test","TEST") into the session, I get the
> following exception from the attempted use of <html:bean name="formName"
> property="value(test)"/>:
>
> "No getter method for property value(test) of bean formName"
>
> This is quite a surprise. Anyone know what is going wrong here?
> Sometimes the simplest things go wrong?
>
> Michael
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
--
Rick
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Maps in Forms
Posted by Michael McGrady <mi...@michaelmcgrady.com>.
Bill Siggelkow wrote:
> Michael McGrady wrote:
>
>>>
>>
>> Rick Reumann correctly pointed out that I just need to use map.test
>> rather than value(test). Thanks.
>
>
> True, map.test will work; I was answering the original question about
> why value(test) did not work.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>
>
Thanks. I appreciate that. I was just trying to get all the
possibilities in so someone does not have to redo this thread, Bill.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Maps in Forms
Posted by Bill Siggelkow <bi...@bellsouth.net>.
Michael McGrady wrote:
>>
>
> Rick Reumann correctly pointed out that I just need to use map.test
> rather than value(test). Thanks.
True, map.test will work; I was answering the original question about
why value(test) did not work.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Maps in Forms
Posted by Michael McGrady <mi...@michaelmcgrady.com>.
Bill Siggelkow wrote:
> Michael, for a map-backed property to work with the
> property="value(key)" syntax the key must be defined as a String; the
> methods must follow the pattern:
>
> public Object getFoo(String key) {…}
> public void setFoo(String key, Object value) {…}
>
> Try that out and let me know if it works for you.
>
> Bill Siggelkow
>
> Michael McGrady wrote:
>
>> I am using the following in an action form:
>>
>>
>>
>> public void setMap(Map map) {
>> this.map = map;
>> }
>>
>> public Map getMap() {
>> return map;
>> }
>>
>> public void setValue(Object key, Object value) {
>> map.put(key,value);
>> }
>>
>> public Object getValue(Object key) {
>> return map.get(key);
>> }
>>
>>
>> Yet, when I put setValue("test","TEST") into the session, I get the
>> following exception from the attempted use of <html:bean
>> name="formName" property="value(test)"/>:
>>
>> "No getter method for property value(test) of bean formName"
>>
>> This is quite a surprise. Anyone know what is going wrong here?
>> Sometimes the simplest things go wrong?
>>
>> Michael
>
>
Rick Reumann correctly pointed out that I just need to use map.test
rather than value(test). Thanks.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Maps in Forms
Posted by Bill Siggelkow <bi...@bellsouth.net>.
Michael, for a map-backed property to work with the
property="value(key)" syntax the key must be defined as a String; the
methods must follow the pattern:
public Object getFoo(String key) {…}
public void setFoo(String key, Object value) {…}
Try that out and let me know if it works for you.
Bill Siggelkow
Michael McGrady wrote:
> I am using the following in an action form:
>
>
>
> public void setMap(Map map) {
> this.map = map;
> }
>
> public Map getMap() {
> return map;
> }
>
> public void setValue(Object key, Object value) {
> map.put(key,value);
> }
>
> public Object getValue(Object key) {
> return map.get(key);
> }
>
>
> Yet, when I put setValue("test","TEST") into the session, I get the
> following exception from the attempted use of <html:bean name="formName"
> property="value(test)"/>:
>
> "No getter method for property value(test) of bean formName"
>
> This is quite a surprise. Anyone know what is going wrong here?
> Sometimes the simplest things go wrong?
>
> Michael
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Maps in Forms
Posted by Rick Reumann <st...@reumann.net>.
Michael McGrady wrote:
>
> Yet, when I put setValue("test","TEST") into the session, I get the
> following exception from the attempted use of <html:bean name="formName"
> property="value(test)"/>:
>
> "No getter method for property value(test) of bean formName"
try: property="map.test"
that should call getMap and then retrieve the value
--
Rick
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org