You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Zhiyong Li <Zh...@ibiomatics.com> on 2001/01/23 21:54:26 UTC

set methods in ActionForm

I have two questions related with the set methods in any of the Form
class, such as MyActionForm.

1. It seems to me that if we use a form with POST method, the
corresponding "set" method will be called as it should be. What I want
to confirm is that if I have the URL with query string, does the
parameter specified overthere also cause the "set" to be called? For
example, I have the URL: http://.../action?name=value And in the
MyActionForm.java, I have the method:

	public void setName(String name) {name = value;}

My experiment shows that when I clicked the URL, setName got called. 

2. My second question is that I found the "set" method did not got
called if the length of the "keyword" is 2. For example, in the above
example, if "name" is "aT" and I have the "set" method,

	public void setAT(String aT) {aT = value;}

The "setAT" does not got called. 

Thank you for the help,
Zhiyong Li
Platform Development
iBiomatics LLC ,  a SAS Company
(919) 653-2746
Zhiyong.Li@iBiomatics.com



Re: Example not working in Apache

Posted by Dan Miser <dm...@wi.rr.com>.
Thank you very much. That was it.
--
Dan Miser

----- Original Message -----
From: "Craig R. McClanahan" <Cr...@eng.sun.com>
To: <st...@jakarta.apache.org>
Sent: Wednesday, January 24, 2001 12:03 PM
Subject: Re: Example not working in Apache


> If you run Tomcat behind Apache, there are some tweaks needed in
httpd.conf to
> make Apache understand the session ids added via URL rewriting.  This will
> affect all webapps that use URL rewriting, not just Struts.
>
> The details are in the FAQ at the Jakarta web site
<http://jakarta.apache.org>
> -- do a search for "URL rewriting" and you should find the right article.



Re: Example not working in Apache

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

> I installed the binary Struts in Tomcat 3.2.1 on Win2000 Advanced Server. I
> am able to access http://localhost/struts-documentation with no problems. I
> can also access http://localhost:8080/struts-example with no problems.
>
> However, if I look at the login link on the main page of
> http://localhost/struts-example I see
> http://localhost/struts-example/logon.jsp;jsessionid=d4hn9n5b31.
> The registration link is the same (i.e. it has jsessionid appended to the
> URL). This results in a 404 when trying to access the page.
>

If you run Tomcat behind Apache, there are some tweaks needed in httpd.conf to
make Apache understand the session ids added via URL rewriting.  This will
affect all webapps that use URL rewriting, not just Struts.

The details are in the FAQ at the Jakarta web site <http://jakarta.apache.org>
-- do a search for "URL rewriting" and you should find the right article.

>
> Any ideas on what's causing this? Thanks.
> --
> Dan Miser

Craig



Example not working in Apache

Posted by Dan Miser <dm...@wi.rr.com>.
I installed the binary Struts in Tomcat 3.2.1 on Win2000 Advanced Server. I
am able to access http://localhost/struts-documentation with no problems. I
can also access http://localhost:8080/struts-example with no problems.

However, if I look at the login link on the main page of
http://localhost/struts-example I see
http://localhost/struts-example/logon.jsp;jsessionid=d4hn9n5b31.
The registration link is the same (i.e. it has jsessionid appended to the
URL). This results in a 404 when trying to access the page.

Any ideas on what's causing this? Thanks.
--
Dan Miser



Re: set methods in ActionForm

Posted by Dzenan Ridjanovic <dz...@fsa.ulaval.ca>.
private String eMail;

public void setEMail(String eMail) {...}

does not work either.  It seems to me that eMail is a correct design pattern.  When
I had changed eMail to email and setEMail to setEmail it worked.

"Craig R. McClanahan" wrote:

> Zhiyong Li wrote:
>
> > I have two questions related with the set methods in any of the Form
> > class, such as MyActionForm.
> >
> > 1. It seems to me that if we use a form with POST method, the
> > corresponding "set" method will be called as it should be. What I want
> > to confirm is that if I have the URL with query string, does the
> > parameter specified overthere also cause the "set" to be called? For
> > example, I have the URL: http://.../action?name=value And in the
> > MyActionForm.java, I have the method:
> >
> >         public void setName(String name) {name = value;}
> >
>
> I imagine you really meant:
>
>     private String name;
>     public void setName(String name) {this.name = name;}
>
> right?
>
> >
> > My experiment shows that when I clicked the URL, setName got called.
> >
>
> Yes -- the controller servlet sees that the field name (from the form) matches
> the property name (from the bean), once you apply the JavaBeans design patterns
> for method names.  See the JavaBeans spec for more details.
>
> >
> > 2. My second question is that I found the "set" method did not got
> > called if the length of the "keyword" is 2. For example, in the above
> > example, if "name" is "aT" and I have the "set" method,
> >
> >         public void setAT(String aT) {aT = value;}
> >
> > The "setAT" does not got called.
> >
>
> That's because this spelling does not match the required design pattern, so the
> controller servlet (actually, it is the Java introspector that is used to ask a
> bean class what it's property setter methods are) does not recognize this as a
> property.
>
> >
> > Thank you for the help,
> > Zhiyong Li
> > Platform Development
> > iBiomatics LLC ,  a SAS Company
> > (919) 653-2746
> > Zhiyong.Li@iBiomatics.com
>
> Craig McClanahan


Re: set methods in ActionForm

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.

Zhiyong Li wrote:

> I have two questions related with the set methods in any of the Form
> class, such as MyActionForm.
>
> 1. It seems to me that if we use a form with POST method, the
> corresponding "set" method will be called as it should be. What I want
> to confirm is that if I have the URL with query string, does the
> parameter specified overthere also cause the "set" to be called? For
> example, I have the URL: http://.../action?name=value And in the
> MyActionForm.java, I have the method:
>
>         public void setName(String name) {name = value;}
>

I imagine you really meant:

    private String name;
    public void setName(String name) {this.name = name;}

right?

>
> My experiment shows that when I clicked the URL, setName got called.
>

Yes -- the controller servlet sees that the field name (from the form) matches
the property name (from the bean), once you apply the JavaBeans design patterns
for method names.  See the JavaBeans spec for more details.

>
> 2. My second question is that I found the "set" method did not got
> called if the length of the "keyword" is 2. For example, in the above
> example, if "name" is "aT" and I have the "set" method,
>
>         public void setAT(String aT) {aT = value;}
>
> The "setAT" does not got called.
>

That's because this spelling does not match the required design pattern, so the
controller servlet (actually, it is the Java introspector that is used to ask a
bean class what it's property setter methods are) does not recognize this as a
property.

>
> Thank you for the help,
> Zhiyong Li
> Platform Development
> iBiomatics LLC ,  a SAS Company
> (919) 653-2746
> Zhiyong.Li@iBiomatics.com

Craig McClanahan