You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Alec Bau <Al...@msdw.com> on 2000/07/17 23:17:24 UTC

Image buttons in Struts

We frequently use image buttons (<input type="image" name="xxxx" ...>) in forms.
Unfortunately, if I'm correct, they don't integrate well with Struts because when a
button is hit parameter names for them are "name.x" and "name.y" with respective
coordinates as values. As a result associated Form Bean isn't automatically populated
since it's impossible to have setters with these names. Also there's no taglib support
for image buttons.

Is it possible to make an addition to bean introspection where parameter names with dots
inside will be mapped to setters with names like "setNameX" or maybe  "setName$X"? The
other solution may be to have a single setter "setName (String xy[])" or  "setName (int
xy[])". Thanks!


Problem with struts 7/17 option tag

Posted by Robert Edgar <ro...@hkstar.com>.
    Till now I have been using struts from 1/7,  just installed the 17/7
build and hit an error in the option tag where it says it cant find a getter
method for a property called Values which is where I supply the values
attributes for the option tags. ( I have a bean with two properties, Values
and Labels which are both ArrayLists).

    I double checked and swapped back in the old stuts lib and it works OK,
so I havent changed any of my code.

    Any thoughts on what the problem might be or what has changed

    Rob


RE: How to use a CONTEXT value inside the action.xml to specify forwarding to a page in a context (multiple web apps at once)

Posted by Kevin Duffey <kd...@buymedia.com>.
Ok..thats what I thought.


> -----Original Message-----
> From: Craig R. McClanahan [mailto:Craig.McClanahan@eng.sun.com]
> Sent: Monday, July 24, 2000 8:57 PM
> To: struts-user@jakarta.apache.org
> Subject: Re: How to use a CONTEXT value inside the action.xml to specify
> forwarding to a page in a context (multiple web apps at once)
>
>
> Kevin Duffey wrote:
>
> > Hi,
> >
> > I appear to have come across a need to allow the action.xml file contain
> > "dynamic" data. haha..not sure how to explain this. I have 3 web-apps
> > running (servlet 2.2 deployment only). Each app has its own
> context path to
> > access it, so that all 3 may maintain their own data in their
> context. Thus,
> > I have app /A, /B and /C so requests to /A/myresource do NOT
> interfere with
> > /B/resource. All 3 apps point to the same one WWW root dir,
> which is ok. The
> > problem I am having is that in action.xml, I specify a /path/page.jsp to
> > forward to. However, in order to access /A, /B or /C depending on some
> > condition, I need a way to specify /A/path/page.jsp and I am
> not quite sure
> > how this is possible with Struts.
> >
> > So I ask you, oh great Struts gurus, how do I get Struts
> ActionServlet to
> > use a context without having to override it myself?
> >
>
> You will not be able to use RequestDispatcher.forward() -- with or without
> Struts -- to cross web application boundaries.  This is because
> the request path
> that you specify is context relative.  Your only option will be to use
> sendRedirect() instead for these types of links, and specify a
> request path that
> is either absolute or host-relative (instead of context-relative).
>
> >
> > Thanks.
>
> Craig
>
>
>


Problem with run Structs example

Posted by Yuan Jun <yj...@sunjapan.co.jp>.
deployed expamle.war under jrun3.0
when excute it shows errors below

i checked struts.jar and it did contant
org.apache.struts.taglib.LocalStrings, what should i do?

500 Internal Server Error
/StrutsSample/:

javax.servlet.ServletException: Exception thrown on line '6' from page
'C:\\Program
Files\\Allaire\\JRun\\servers\\default\\Struts-Example\\index.jsp'.
java.lang.ExceptionInInitializerError: java.util.MissingResourceException:
Can't find resource for base name org.apache.struts.taglib.LocalStrings,
locale ja_JP
	at java.util.ResourceBundle.getBundle(ResourceBundle.java:423)
	at java.util.ResourceBundle.getBundle(ResourceBundle.java:339)
	at org.apache.struts.util.MessageResources.(MessageResources.java:102)
	at
org.apache.struts.util.MessageResources.getMessageResources(MessageResources
.java:579)
	at org.apache.struts.taglib.MessageTag.(MessageTag.java:164)
	at java.lang.Class.newInstance0(Native Method)
	at java.lang.Class.newInstance(Class.java, Compiled Code)
	at
allaire.jrun.jsp.JRunJSPStaticHelpers.createTagHandler(JRunJSPStaticHelpers.
java:47)
	at jrun__index2ejspa._jspService(jrun__index2ejspa.java:39)
	at allaire.jrun.jsp.HttpJSPServlet.service(HttpJSPServlet.java:40)




Problem with option tag

Posted by Robert Edgar <ro...@hkstar.com>.
Till now I have been using struts from 1/7,  just installed the 17/7  build
and hit an error in the option tag where it says it cant find a getter
method for a property called Values which is where I supply the values
attributes for the option tags. ( I have a bean with two properties, Values
and Labels which are both ArrayLists).

I double checked and swapped back in the old stuts lib and it works OK, so I
havent changed any of my code just switched libs.

Any thoughts on what the problem might be or what has changed

Rob



RE: How to use a CONTEXT value inside the action.xml to specify forwarding to a page in a context (multiple web apps at once)

Posted by Kevin Duffey <kd...@buymedia.com>.
On that note...

What if my site is set up like so...I have a web app for apples, oranges and
bananas. All three use the same /www root files (jsp pages). In those jsp
pages I have some scriplet code that basically says if the path has a
/apple/ in it, display this. If it has a /oranges/ in it, do this and if it
has /bananas/ in it, display this instead. All 3 web apps use the same "jsp"
pages, so each page only needs to be changed once for all 3 web-apps to be
affected. However, each app needs its own context to make absolutley sure
incase a use is on /bananans/ and hits the BACK button into a previous page,
/apples/, that because they use the same JSP pages data is not
"cross-talked" across the pages for different contexts. Its hard to explain,
but on our site we have 3 types, each needing separate "private" data pools
for each client (3 sessions for each one login), but all 3 using the same
set of pages since they are identically displayed (all 3 apps are very
similar in nature with slight differences in displays depending on the
specific app).


I want links to reflect the specific app they are in. If they switch to
/apples/, all links show /apples/ instead of say /oranges/ or /bananas/.
That is easy to do. In my JSP pages I have them all include the same one
header.inc file (inline it). In there, I have scriplet code that simply does
something like

<%
if( request.getRequestURI().indexOf("/apples/") >= 0 ) {
%>
<h1>APPLES</h1>
<% } else { %>
<h2>ORANAGES OR BANANAS</h2>
<% } %>

This is simple enough for displaying.

My main problem right now is not what clients need..they would only be
logged in to one of the 3. But our "admin" (customer support people really)
need to be logged in to all 3 of them at the same time, using 3 separate
windows. Because cookies from one machine limit the user to one browser
window (in terms of session data being stored via a cookie session id), I
decided to use 3 separate web apps, so that even though the one
client/browser returns the same one cookie id value, the server has 3
separate sessions, one in each context. So, on the admin site, I need to log
in the user one time, but really I need to create 3 separate contexts at one
time. I am doing this like so:

inside the login method I have:

URL url1 = new
URL("/apples/Login.do?command=3&LoginName=xxxx*LoginPassword=xxx");
url1.openConnection();
url1.getContent();

etc..

I do this for the other two as well, substituting /apples/ for /oranges/ and
/bananas/.

The method called by command==3 is:

someMethdo(HttpServletRequest request)
{
  request.getSession(true).setAttribute("ClientSession", someObject);
}

So now..the problem is, inside any page when I do /apples/page.jsp, the
object (someObject) should exist in the /apples/ web-app session for that
client..but it does not. I think the reason is the url1.getContent() is
either not sending the same cookie as the browser is, thus when I attempt to
use my browser "after" the login method creates the 3 contexts, the session
ID is invalid..and thus does not access the same context/session that was
created in the url1.getContent() call. Ofcourse, if I could manually set the
jsessionid cookie key that is used to the same cookie value the browser
would return (if thats possible), this might work.

So...I leave off with that. Any ideas?

Thanks.


Re: How to use a CONTEXT value inside the action.xml to specify forwarding to a page in a context (multiple web apps at once)

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

> Hi,
>
> I appear to have come across a need to allow the action.xml file contain
> "dynamic" data. haha..not sure how to explain this. I have 3 web-apps
> running (servlet 2.2 deployment only). Each app has its own context path to
> access it, so that all 3 may maintain their own data in their context. Thus,
> I have app /A, /B and /C so requests to /A/myresource do NOT interfere with
> /B/resource. All 3 apps point to the same one WWW root dir, which is ok. The
> problem I am having is that in action.xml, I specify a /path/page.jsp to
> forward to. However, in order to access /A, /B or /C depending on some
> condition, I need a way to specify /A/path/page.jsp and I am not quite sure
> how this is possible with Struts.
>
> So I ask you, oh great Struts gurus, how do I get Struts ActionServlet to
> use a context without having to override it myself?
>

You will not be able to use RequestDispatcher.forward() -- with or without
Struts -- to cross web application boundaries.  This is because the request path
that you specify is context relative.  Your only option will be to use
sendRedirect() instead for these types of links, and specify a request path that
is either absolute or host-relative (instead of context-relative).

>
> Thanks.

Craig



How to use a CONTEXT value inside the action.xml to specify forwarding to a page in a context (multiple web apps at once)

Posted by Kevin Duffey <kd...@buymedia.com>.
Hi,

I appear to have come across a need to allow the action.xml file contain
"dynamic" data. haha..not sure how to explain this. I have 3 web-apps
running (servlet 2.2 deployment only). Each app has its own context path to
access it, so that all 3 may maintain their own data in their context. Thus,
I have app /A, /B and /C so requests to /A/myresource do NOT interfere with
/B/resource. All 3 apps point to the same one WWW root dir, which is ok. The
problem I am having is that in action.xml, I specify a /path/page.jsp to
forward to. However, in order to access /A, /B or /C depending on some
condition, I need a way to specify /A/path/page.jsp and I am not quite sure
how this is possible with Struts.

So I ask you, oh great Struts gurus, how do I get Struts ActionServlet to
use a context without having to override it myself?

Thanks.


Struts with WebLogic 5.1 server?

Posted by Kevin Duffey <kd...@buymedia.com>.
Hi all,

I am now trying my hand at Struts with WebLogic 5.1 server. I am running the
same web-app with the same web.xml settings as I had in Orion, and I see it
can't seem to find the Login.do resource. Has anyone experienced any
problems with initial "actions" being passed on to the ActionServlet with
WebLogic 5.1 yet? Is there some special settings required to get this to
work?

Thanks.


RE: Image buttons in Struts

Posted by Roger Hyam <ro...@orbital.co.uk>.
Hi,

Could some one summarise that last series of exchanges about image buttons?

Is there a plan in corporate a struts tag for them?

Roger



Re: Image buttons in Struts

Posted by Giuseppe Galli <gi...@agora.it>.
Hi all, and many thanks to Craig for his response.

Craig R. McClanahan's dream is a reality here in Agora. We developed
G.A.S.P. a jsp single-page application that utilizes a third party library
that parses HTML pages an produce a file.java, and a modify.jsp with
validation and error handling.

PS
The result is a bean with getter and setter methods that simply set and get
the value of the fields....

Ciao
Pino

"Craig R. McClanahan" wrote:

> Giuseppe Galli wrote:
>
> > Hi all,
> [snip]

> ..will do some "quality time" thinking about it next week, after I get
> back from O'Reilly.
> [snip]
>
> Craig

Re: Image buttons in Struts

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

> Hi all,
> I saw the response by Craig R. McClanahan to my question about the
> reason for use get/setter methods while its possible to access the
> fields object by introspection. There is no doubt that the
> philosophical reason is good, but in practise I always used
> introspection to set the fields with the values shipping with the
> response (Note that this eliminates the need for a new bean for each
> form! isn't this the major cumbersome in form data processing?).
>

It is certainly more cumbersome than it needs to be -- but tools that
can auto-generate form beans will go a long ways towards making it not
so bad.  I've been dreaming a little about a way to auto-generate a form
bean (including the validations for standard sorts of things) from a
description of that bean's interesting properties.

>
> However if the use of set/getter method is a must for form data
> processing, than my proposal is to handle composite data (e.g when you
> have parameteres named name.x ) with setter methods ( setX() ) in the
> object returned by get<Name>().
>

Something like this sounds best of what we've talked about so far, and
will do some "quality time" thinking about it next week, after I get
back from O'Reilly.

>
> What about? it seems reasonable and clear.
>
> Thanks all.
>

Craig



Re: Image buttons in Struts

Posted by Giuseppe Galli <gi...@agora.it>.
Hi all,
I saw the response by Craig R. McClanahan to my question about the
reason for use get/setter methods while its possible to access the
fields object by introspection. There is no doubt that the philosophical
reason is good, but in practise I always used introspection to set the
fields with the values shipping with the response (Note that this
eliminates the need for a new bean for each form! isn't this the major
cumbersome in form data processing?).

However if the use of set/getter method is a must for form data
processing, than my proposal is to handle composite data (e.g when you
have parameteres named name.x ) with setter methods ( setX() ) in the
object returned by get<Name>().

What about? it seems reasonable and clear.

Thanks all.


Alec Bau wrote:

> Giuseppe,
>
> >If you have a form with more than one image button, say 'Confirm' and
> 'Delete' that produce a request that
> >can contain the following parameters: confirm, confirm.x, confirm.y
> OR (not AND!) delete, delete.x,
>
> Unfortunately, according to standard there won't be "confirm"  or
> "delete" param names, there will be only ones with .x/y  suffixes.
>
> >I think there is no clean way using setter methods, I mean that
> BeanUtils.populate should replace '.' with '_' >or something alike
> (obtaining 'name.x' in 'name_x') and then use the setter method
> set<Name>_x
>
> Yes, that's what I'm trying to propose except for I really think it's
> enough to map xy pair just to a single "setName" method and disregard
> coordinate values in case of image buttons (not image maps!).
>
> Currently to achieve same effect I use a cumbersome combination of a
> hidden action field and JavaScript event like this:
>
>      <input type="hidden" name="action">
>      <input type="image" name="yes"
>      onClick="document.myForm.action.value='yes'" ...>
>      <input type="image" name="no"
>      onClick="document.myForm.action.value='no'" ...>
>
> Struts then finds MyForm.setAction method and passes the right button
> value.
> Thanks,
>     Alec
>
>
>> [snip..]
>

Re: Image buttons in Struts

Posted by Alec Bau <Al...@msdw.com>.
Giuseppe,

>If you have a form with more than one image button, say 'Confirm' and 'Delete' that produce a request that
>can contain the following parameters: confirm, confirm.x, confirm.y OR (not AND!) delete, delete.x,

Unfortunately, according to standard there won't be "confirm"  or "delete" param names, there will be only
ones with .x/y  suffixes.

>I think there is no clean way using setter methods, I mean that BeanUtils.populate should replace '.' with
'_' >or something alike (obtaining 'name.x' in 'name_x') and then use the setter method set<Name>_x

Yes, that's what I'm trying to propose except for I really think it's enough to map xy pair just to a single
"setName" method and disregard coordinate values in case of image buttons (not image maps!).

Currently to achieve same effect I use a cumbersome combination of a hidden action field and JavaScript event
like this:

     <input type="hidden" name="action">
     <input type="image" name="yes" onClick="document.myForm.action.value='yes'" ...>
     <input type="image" name="no" onClick="document.myForm.action.value='no'" ...>

Struts then finds MyForm.setAction method and passes the right button value.
Thanks,
    Alec

Giuseppe Galli wrote:

> Hi Alec,
>
> Alec Bau wrote:
>
> > Giuseppe,
> >
> > >1) find a field named 'x' in the object
> > >2) if you find assign it the value passed by the request
> >
> > It's quite normal to have 2 or more image buttons within a form, i.e. Yes, No and Cancel. So having a
> > single "x" and "y" methods isn't enough since I want to distinguish action by button's name.
>
> Sorry, I should have been more clear.
> when I talk about the object containing the field named 'x' I was not talking about the bean, but the
> field on which the setter method set<Name>)( ) will work.
> If you have a form with more than one image button, say 'Confirm' and 'Delete' that produce a request that
> can contain the following parameters: confirm, confirm.x, confirm.y OR (not AND!) delete, delete.x,
> delete.y, all you need is a java class that has 2 fields named 'confirm' and 'delete' whose type is a
> class that defines 2 fields: x and y.
> At process time the actual values of the request parameters will be assigned to the fields through the one
> to one naming mechanism (and introspection).
>
> > As
> > opposed to image maps, for image buttons in most cases you even don't need to know button image
> > coordinates. That's why ideally it would be nice that Struts could handle them as normal buttons, so
> > that your controller won't depend upon what buttons were used. This way Struts can simply map both
> > name.x and name.y to "setName(String val)". Value is irrelevant here (just to conform to JavaBeans)
> > since you're interested in what particular button caused form submit. The setter could be called twice
> > (for name.x and name.y) or, preferably, BeanUtils.populate can simply skip the 2nd "name." occurrence.
> >
>
> So all you want is to find the way that permits to struts to handle image button clicks as normal submit
> input type, since normally we are not interested in the x and y values. Uhm.. I think there is no clean
> way using setter methods, I mean that BeanUtils.populate should replace '.' with '_' or something alike
> (obtaining 'name.x' in 'name_x') and then use the setter method set<Name>_x
>
> ...any cue?
>
> Pino
>
> > Thanks,
> >     Alec
> >
> > Giuseppe Galli wrote:
> >
> > > hi Alec,
> > > thank's to you.
> > >
>
> [snip..]

Re: Image buttons in Struts

Posted by Giuseppe Galli <gi...@agora.it>.
Hi Alec,

Alec Bau wrote:

> Giuseppe,
>
> >1) find a field named 'x' in the object
> >2) if you find assign it the value passed by the request
>
> It's quite normal to have 2 or more image buttons within a form, i.e. Yes, No and Cancel. So having a
> single "x" and "y" methods isn't enough since I want to distinguish action by button's name.

Sorry, I should have been more clear.
when I talk about the object containing the field named 'x' I was not talking about the bean, but the
field on which the setter method set<Name>)( ) will work.
If you have a form with more than one image button, say 'Confirm' and 'Delete' that produce a request that
can contain the following parameters: confirm, confirm.x, confirm.y OR (not AND!) delete, delete.x,
delete.y, all you need is a java class that has 2 fields named 'confirm' and 'delete' whose type is a
class that defines 2 fields: x and y.
At process time the actual values of the request parameters will be assigned to the fields through the one
to one naming mechanism (and introspection).


> As
> opposed to image maps, for image buttons in most cases you even don't need to know button image
> coordinates. That's why ideally it would be nice that Struts could handle them as normal buttons, so
> that your controller won't depend upon what buttons were used. This way Struts can simply map both
> name.x and name.y to "setName(String val)". Value is irrelevant here (just to conform to JavaBeans)
> since you're interested in what particular button caused form submit. The setter could be called twice
> (for name.x and name.y) or, preferably, BeanUtils.populate can simply skip the 2nd "name." occurrence.
>

So all you want is to find the way that permits to struts to handle image button clicks as normal submit
input type, since normally we are not interested in the x and y values. Uhm.. I think there is no clean
way using setter methods, I mean that BeanUtils.populate should replace '.' with '_' or something alike
(obtaining 'name.x' in 'name_x') and then use the setter method set<Name>_x

...any cue?

Pino

> Thanks,
>     Alec
>
> Giuseppe Galli wrote:
>
> > hi Alec,
> > thank's to you.
> >

[snip..]

Re: Image buttons in Struts

Posted by Alec Bau <Al...@msdw.com>.
Giuseppe,

>1) find a field named 'x' in the object
>2) if you find assign it the value passed by the request

It's quite normal to have 2 or more image buttons within a form, i.e. Yes, No and Cancel. So having a
single "x" and "y" methods isn't enough since I want to distinguish action by button's name. As
opposed to image maps, for image buttons in most cases you even don't need to know button image
coordinates. That's why ideally it would be nice that Struts could handle them as normal buttons, so
that your controller won't depend upon what buttons were used. This way Struts can simply map both
name.x and name.y to "setName(String val)". Value is irrelevant here (just to conform to JavaBeans)
since you're interested in what particular button caused form submit. The setter could be called twice
(for name.x and name.y) or, preferably, BeanUtils.populate can simply skip the 2nd "name." occurrence.

Thanks,
    Alec

Giuseppe Galli wrote:

> hi Alec,
> thank's to you.
>
> What I wanted to point out in my response was that I don't like the use of setter methods like
> set<Name>$x or set<Name>_x when processing a request with the param 'name.x'.
> The primary reason is that it's not necessary. I don't' know the BeanUtils.populate() method, I'm
> going to have a look (it seems a helper method). I think that you can use introspection tools to:
> 1) find a field named 'x' in the object
> 2) if you find assign it the value passed by the request
>
> As you can see  no setter method is required..
>
> Hope this helps.
> Ciao.
> Pino
>
> Alec Bau wrote:
>
> > Thanks, Giuseppe! My point is that support for image buttons as well as image maps is worthwhile
> > including in Struts since these are very frequently used elements.
> >
> > This could easily be done by changing "BeanUtils.populate" method that's called from
> > "ActionServlet.processActionForm" to populate the form bean. For example, populate method can
> > map "<name>.x" and "<name>.y" request parameters to bean setters with signatures "set<Name>X(int
> > x)" and  "set<Name>Y(int y)". Also it will be nice to have corresponding tags, i.e.
> > "<struts:imageButton ...>".
> >
> > Thanks,
> >     Alec
> >
> > Giuseppe Galli wrote:
> >
> > > hello to the list,
> > > just to say that we use Java introspection, to populate the fields 'x' and 'y' of the object
> > > when request contains parameters named name.x and name.y. The object must have two fields,
> > > 'x' and 'y' and it's not required to be a well-formed Java Bean. In this way the only setter
> > > method to define should be "setRequest( request )".
> > > If anyone think this could help I can e-mail an example and the source code.
> > >
> > > Hope this helps,
> > > Pino
> > >
> > > Alec Bau wrote:
> > >
> > > > We frequently use image buttons (<input type="image" name="xxxx" ...>) in forms.
> > > > Unfortunately, if I'm correct, they don't integrate well with Struts because when a
> > > > button is hit parameter names for them are "name.x" and "name.y" with respective
> > > > coordinates as values. As a result associated Form Bean isn't automatically populated
> > > > since it's impossible to have setters with these names. Also there's no taglib support
> > > > for image buttons.
> > > >
> > > > Is it possible to make an addition to bean introspection where parameter names with dots
> > > > inside will be mapped to setters with names like "setNameX" or maybe  "setName$X"? The
> > > > other solution may be to have a single setter "setName (String xy[])" or  "setName (int
> > > > xy[])". Thanks!

Re: Image buttons in Struts

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

> Hi Eduardo,
> I saw the source code for the BeanUtilspopulate() method.
> It uses introspection to find out the bean setter methods by:
> Method methods[] = null;
> methods = bean.getClass().getMethods();
>
> why don't use getField()  also where the setter method is not available?
>
> Is there anyone that can explain me why use introspection to find only setter/getter methods and not all
> the fields of the object? why not use the simplest naming mechanism: param name = "m_strId" to map the
> m_strId field of the class?
>

The philosophical reason to use JavaBeans introspection, and not access
the fields directly, is the same
philosophical reason why classes generally do not create public instance
variables -- the names of those
variables (and whether they really exist at all) is an internal
implementation detail.  A JavaBean should be
able to control what "properties" it makes visible -- either by
following the normal getter/setter naming
patterns, or by providing a corresponding BeanInfo that may only list a
subset of all the actual properties
as available for getting and setting -- and the actual method names used
need not correspond to the
getter/setter patterns.

The practical reason to use JavaBeans introspection is that JSP engines
use it.  I want to have the behavior
of BeanUtils.populate() match that of <jsp:setProperty name="xxx"
property="*"/> as closely as practical, so
that someone switching from using <jsp:setProperty> to an MVC design
pattern using Struts is not
unpleasantly surprised by the semantic differences.

>
> Thanks in advance.
> Pino.
>

Craig

PS:  I am going to propose something for image buttons -- but it will
probably be next week, after I get
back from O'Reilly.

Re: Image buttons in Struts

Posted by Giuseppe Galli <gi...@agora.it>.
Hi Eduardo,
I saw the source code for the BeanUtilspopulate() method.
It uses introspection to find out the bean setter methods by:
Method methods[] = null;
methods = bean.getClass().getMethods();

why don't use getField()  also where the setter method is not available?

Is there anyone that can explain me why use introspection to find only setter/getter methods and not all
the fields of the object? why not use the simplest naming mechanism: param name = "m_strId" to map the
m_strId field of the class?

Thanks in advance.
Pino.

Eduardo Pelegri--Llopart wrote:

> If you are going to use setters and getters you may want to use the
> Beans introspector to provide a consistent naming mechanism.  But beware
> three is some initial cost in doing the introspection.
>
>         - eduard/o
>
> Giuseppe Galli wrote:
> >
> > hi Alec,
> > thank's to you.
> >
> > What I wanted to point out in my response was that I don't like the use of setter methods like
> > set<Name>$x or set<Name>_x when processing a request with the param 'name.x'.
> > The primary reason is that it's not necessary. I don't' know the BeanUtils.populate() method, I'm
> > going to have a look (it seems a helper method). I think that you can use introspection tools to:
> > 1) find a field named 'x' in the object
> > 2) if you find assign it the value passed by the request
> >
> > As you can see  no setter method is required..
> >
> > Hope this helps.
> > Ciao.
> > Pino
> >
> > Alec Bau wrote:
> >
> > > Thanks, Giuseppe! My point is that support for image buttons as well as image maps is worthwhile
> > > including in Struts since these are very frequently used elements.
> > >
> > > This could easily be done by changing "BeanUtils.populate" method that's called from
> > > "ActionServlet.processActionForm" to populate the form bean. For example, populate method can
> > > map "<name>.x" and "<name>.y" request parameters to bean setters with signatures "set<Name>X(int
> > > x)" and  "set<Name>Y(int y)". Also it will be nice to have corresponding tags, i.e.
> > > "<struts:imageButton ...>".
> > >
> > > Thanks,
> > >     Alec
> > >
> > > Giuseppe Galli wrote:
> > >
> > > > hello to the list,
> > > > just to say that we use Java introspection, to populate the fields 'x' and 'y' of the object
> > > > when request contains parameters named name.x and name.y. The object must have two fields,
> > > > 'x' and 'y' and it's not required to be a well-formed Java Bean. In this way the only setter
> > > > method to define should be "setRequest( request )".
> > > > If anyone think this could help I can e-mail an example and the source code.
> > > >
> > > > Hope this helps,
> > > > Pino
> > > >
> > > > Alec Bau wrote:
> > > >
> > > > > We frequently use image buttons (<input type="image" name="xxxx" ...>) in forms.
> > > > > Unfortunately, if I'm correct, they don't integrate well with Struts because when a
> > > > > button is hit parameter names for them are "name.x" and "name.y" with respective
> > > > > coordinates as values. As a result associated Form Bean isn't automatically populated
> > > > > since it's impossible to have setters with these names. Also there's no taglib support
> > > > > for image buttons.
> > > > >
> > > > > Is it possible to make an addition to bean introspection where parameter names with dots
> > > > > inside will be mapped to setters with names like "setNameX" or maybe  "setName$X"? The
> > > > > other solution may be to have a single setter "setName (String xy[])" or  "setName (int
> > > > > xy[])". Thanks!

Re: Image buttons in Struts

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
Eduardo Pelegri--Llopart wrote:

> If you are going to use setters and getters you may want to use the
> Beans introspector to provide a consistent naming mechanism.  But beware
> three is some initial cost in doing the introspection.
>

As of last weekend, this is what Struts does.  To deal with the cost
issue, I also cache the results
(the array of PropertyDescriptors) so that a particular Java class need
only be introspected once.

>
>         - eduard/o
>

Craig


>
> Giuseppe Galli wrote:
> >
> > hi Alec,
> > thank's to you.
> >
> > What I wanted to point out in my response was that I don't like the use of setter methods like
> > set<Name>$x or set<Name>_x when processing a request with the param 'name.x'.
> > The primary reason is that it's not necessary. I don't' know the BeanUtils.populate() method, I'm
> > going to have a look (it seems a helper method). I think that you can use introspection tools to:
> > 1) find a field named 'x' in the object
> > 2) if you find assign it the value passed by the request
> >
> > As you can see  no setter method is required..
> >
> > Hope this helps.
> > Ciao.
> > Pino
> >
> > Alec Bau wrote:
> >
> > > Thanks, Giuseppe! My point is that support for image buttons as well as image maps is worthwhile
> > > including in Struts since these are very frequently used elements.
> > >
> > > This could easily be done by changing "BeanUtils.populate" method that's called from
> > > "ActionServlet.processActionForm" to populate the form bean. For example, populate method can
> > > map "<name>.x" and "<name>.y" request parameters to bean setters with signatures "set<Name>X(int
> > > x)" and  "set<Name>Y(int y)". Also it will be nice to have corresponding tags, i.e.
> > > "<struts:imageButton ...>".
> > >
> > > Thanks,
> > >     Alec
> > >
> > > Giuseppe Galli wrote:
> > >
> > > > hello to the list,
> > > > just to say that we use Java introspection, to populate the fields 'x' and 'y' of the object
> > > > when request contains parameters named name.x and name.y. The object must have two fields,
> > > > 'x' and 'y' and it's not required to be a well-formed Java Bean. In this way the only setter
> > > > method to define should be "setRequest( request )".
> > > > If anyone think this could help I can e-mail an example and the source code.
> > > >
> > > > Hope this helps,
> > > > Pino
> > > >
> > > > Alec Bau wrote:
> > > >
> > > > > We frequently use image buttons (<input type="image" name="xxxx" ...>) in forms.
> > > > > Unfortunately, if I'm correct, they don't integrate well with Struts because when a
> > > > > button is hit parameter names for them are "name.x" and "name.y" with respective
> > > > > coordinates as values. As a result associated Form Bean isn't automatically populated
> > > > > since it's impossible to have setters with these names. Also there's no taglib support
> > > > > for image buttons.
> > > > >
> > > > > Is it possible to make an addition to bean introspection where parameter names with dots
> > > > > inside will be mapped to setters with names like "setNameX" or maybe  "setName$X"? The
> > > > > other solution may be to have a single setter "setName (String xy[])" or  "setName (int
> > > > > xy[])". Thanks!

Re: Image buttons in Struts

Posted by Eduardo Pelegri--Llopart <Ed...@eng.sun.com>.
If you are going to use setters and getters you may want to use the
Beans introspector to provide a consistent naming mechanism.  But beware
three is some initial cost in doing the introspection.

	- eduard/o

Giuseppe Galli wrote:
> 
> hi Alec,
> thank's to you.
> 
> What I wanted to point out in my response was that I don't like the use of setter methods like
> set<Name>$x or set<Name>_x when processing a request with the param 'name.x'.
> The primary reason is that it's not necessary. I don't' know the BeanUtils.populate() method, I'm
> going to have a look (it seems a helper method). I think that you can use introspection tools to:
> 1) find a field named 'x' in the object
> 2) if you find assign it the value passed by the request
> 
> As you can see  no setter method is required..
> 
> Hope this helps.
> Ciao.
> Pino
> 
> Alec Bau wrote:
> 
> > Thanks, Giuseppe! My point is that support for image buttons as well as image maps is worthwhile
> > including in Struts since these are very frequently used elements.
> >
> > This could easily be done by changing "BeanUtils.populate" method that's called from
> > "ActionServlet.processActionForm" to populate the form bean. For example, populate method can
> > map "<name>.x" and "<name>.y" request parameters to bean setters with signatures "set<Name>X(int
> > x)" and  "set<Name>Y(int y)". Also it will be nice to have corresponding tags, i.e.
> > "<struts:imageButton ...>".
> >
> > Thanks,
> >     Alec
> >
> > Giuseppe Galli wrote:
> >
> > > hello to the list,
> > > just to say that we use Java introspection, to populate the fields 'x' and 'y' of the object
> > > when request contains parameters named name.x and name.y. The object must have two fields,
> > > 'x' and 'y' and it's not required to be a well-formed Java Bean. In this way the only setter
> > > method to define should be "setRequest( request )".
> > > If anyone think this could help I can e-mail an example and the source code.
> > >
> > > Hope this helps,
> > > Pino
> > >
> > > Alec Bau wrote:
> > >
> > > > We frequently use image buttons (<input type="image" name="xxxx" ...>) in forms.
> > > > Unfortunately, if I'm correct, they don't integrate well with Struts because when a
> > > > button is hit parameter names for them are "name.x" and "name.y" with respective
> > > > coordinates as values. As a result associated Form Bean isn't automatically populated
> > > > since it's impossible to have setters with these names. Also there's no taglib support
> > > > for image buttons.
> > > >
> > > > Is it possible to make an addition to bean introspection where parameter names with dots
> > > > inside will be mapped to setters with names like "setNameX" or maybe  "setName$X"? The
> > > > other solution may be to have a single setter "setName (String xy[])" or  "setName (int
> > > > xy[])". Thanks!

Re: Image buttons in Struts

Posted by Giuseppe Galli <gi...@agora.it>.
hi Alec,
thank's to you.

What I wanted to point out in my response was that I don't like the use of setter methods like
set<Name>$x or set<Name>_x when processing a request with the param 'name.x'.
The primary reason is that it's not necessary. I don't' know the BeanUtils.populate() method, I'm
going to have a look (it seems a helper method). I think that you can use introspection tools to:
1) find a field named 'x' in the object
2) if you find assign it the value passed by the request

As you can see  no setter method is required..

Hope this helps.
Ciao.
Pino


Alec Bau wrote:

> Thanks, Giuseppe! My point is that support for image buttons as well as image maps is worthwhile
> including in Struts since these are very frequently used elements.
>
> This could easily be done by changing "BeanUtils.populate" method that's called from
> "ActionServlet.processActionForm" to populate the form bean. For example, populate method can
> map "<name>.x" and "<name>.y" request parameters to bean setters with signatures "set<Name>X(int
> x)" and  "set<Name>Y(int y)". Also it will be nice to have corresponding tags, i.e.
> "<struts:imageButton ...>".
>
> Thanks,
>     Alec
>
> Giuseppe Galli wrote:
>
> > hello to the list,
> > just to say that we use Java introspection, to populate the fields 'x' and 'y' of the object
> > when request contains parameters named name.x and name.y. The object must have two fields,
> > 'x' and 'y' and it's not required to be a well-formed Java Bean. In this way the only setter
> > method to define should be "setRequest( request )".
> > If anyone think this could help I can e-mail an example and the source code.
> >
> > Hope this helps,
> > Pino
> >
> > Alec Bau wrote:
> >
> > > We frequently use image buttons (<input type="image" name="xxxx" ...>) in forms.
> > > Unfortunately, if I'm correct, they don't integrate well with Struts because when a
> > > button is hit parameter names for them are "name.x" and "name.y" with respective
> > > coordinates as values. As a result associated Form Bean isn't automatically populated
> > > since it's impossible to have setters with these names. Also there's no taglib support
> > > for image buttons.
> > >
> > > Is it possible to make an addition to bean introspection where parameter names with dots
> > > inside will be mapped to setters with names like "setNameX" or maybe  "setName$X"? The
> > > other solution may be to have a single setter "setName (String xy[])" or  "setName (int
> > > xy[])". Thanks!

Re: Image buttons in Struts

Posted by Alec Bau <Al...@msdw.com>.
Thanks, Giuseppe! My point is that support for image buttons as well as image maps is worthwhile
including in Struts since these are very frequently used elements.

This could easily be done by changing "BeanUtils.populate" method that's called from
"ActionServlet.processActionForm" to populate the form bean. For example, populate method can
map "<name>.x" and "<name>.y" request parameters to bean setters with signatures "set<Name>X(int
x)" and  "set<Name>Y(int y)". Also it will be nice to have corresponding tags, i.e.
"<struts:imageButton ...>".

Thanks,
    Alec

Giuseppe Galli wrote:

> hello to the list,
> just to say that we use Java introspection, to populate the fields 'x' and 'y' of the object
> when request contains parameters named name.x and name.y. The object must have two fields,
> 'x' and 'y' and it's not required to be a well-formed Java Bean. In this way the only setter
> method to define should be "setRequest( request )".
> If anyone think this could help I can e-mail an example and the source code.
>
> Hope this helps,
> Pino
>
> Alec Bau wrote:
>
> > We frequently use image buttons (<input type="image" name="xxxx" ...>) in forms.
> > Unfortunately, if I'm correct, they don't integrate well with Struts because when a
> > button is hit parameter names for them are "name.x" and "name.y" with respective
> > coordinates as values. As a result associated Form Bean isn't automatically populated
> > since it's impossible to have setters with these names. Also there's no taglib support
> > for image buttons.
> >
> > Is it possible to make an addition to bean introspection where parameter names with dots
> > inside will be mapped to setters with names like "setNameX" or maybe  "setName$X"? The
> > other solution may be to have a single setter "setName (String xy[])" or  "setName (int
> > xy[])". Thanks!

Re: Image buttons in Struts

Posted by Giuseppe Galli <gi...@agora.it>.
hello to the list,
just to say that we use Java introspection, to populate the fields 'x' and 'y' of the object
when request contains parameters named name.x and name.y. The object must have two fields,
'x' and 'y' and it's not required to be a well-formed Java Bean. In this way the only setter
method to define should be "setRequest( request )".
If anyone think this could help I can e-mail an example and the source code.

Hope this helps,
Pino

Alec Bau wrote:

> We frequently use image buttons (<input type="image" name="xxxx" ...>) in forms.
> Unfortunately, if I'm correct, they don't integrate well with Struts because when a
> button is hit parameter names for them are "name.x" and "name.y" with respective
> coordinates as values. As a result associated Form Bean isn't automatically populated
> since it's impossible to have setters with these names. Also there's no taglib support
> for image buttons.
>
> Is it possible to make an addition to bean introspection where parameter names with dots
> inside will be mapped to setters with names like "setNameX" or maybe  "setName$X"? The
> other solution may be to have a single setter "setName (String xy[])" or  "setName (int
> xy[])". Thanks!