You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by rh...@rdg.boehringer-ingelheim.com on 2001/03/20 07:08:32 UTC

Object oriented question regarding ActionForms

I have an object oriented question related to how Struts instantiates an
ActionForm. What I am trying to do is utilize a factory for creation of my
ActionForms. In my application, I have a base (abstract) ActionForm class
called Fermentation, and subclasses FermentationYeast, FermentationEcoli,
etc...  The factory is called from my Action servlet to create the
appropriate instance of an ActionForm (a subtype of Fermentation). Then I
save the newly created ActionForm in the session. The object type that gets
saved in the session is the subtype, but in my Struts config I am specifying
the base type. I want Struts to read this object from the session, but
Struts always creates a new ActionForm of the base type. I want it to find
and use the subtype!

For example, the Action servlet calls the factory and the factory returns a
FermentationYeast. This object is saved in the session, and then I forward
to the EditFermentation page. The EditFermentation page is mapped in the
Struts config to use a Fermentation form, so Struts does not recognize the
FermentationYeast that is already in the session and it creates a new
ActionForm. Even though a FermentationYeast *is a* Fermentation, Struts does
not seem to support this. I think it would be helpful if Struts supported
generalization... or if it does and I am missing something here please let
me know :) Or, If you think I should change my design, please let me know
this as well.

I think I have a good reason to need to do this. The first page is where the
user enters common information, then the next page is loaded based on the
type of the Fermentation (ActionFrom). I could create 2 separate ActionForms
(one for the common attributes and then another for the details) but I would
like to use inheritance to model this relationship. In other words, I want
to create a single ActionForm which will be used across multiple pages, but
I want to share pages that ask for the same information.


Thanks,
Bob

RE: strange html:form tag

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Tue, 20 Mar 2001, Troy Hart wrote:

> OK, so let me see if I understand what you are saying:
> 
> the tag <html:form action="/someAction"> will trigger FormTag.doStartTag(),
> which will append ".do" if no extension was specified. I guess it looks
> first to see if if extension mapping is being used vs. path (???) mapping?
> 

At startup time, the Struts controller servlet reads the web.xml file and
finds out what <servlet-mapping> entry you have selected.  If you use
extension mapping, <html:form> will append the appropriate suffix
(for example, "/saveCustomer.do")  On the other hand, if you used:

	<servlet-mapping>
		<servlet-name>action</servlet-name>
		<url-pattern>/process/*</url-pattern>
	</servlet-mapping>

The submitted URL will be something like "/process/saveCustomer" instead.

> Maybe I should go review the tag's java source... :)
> 

That's always useful :-).

> Thanks,
> 
> Troy
> 

Craig


RE: strange html:form tag

Posted by Troy Hart <th...@part.net>.
OK, so let me see if I understand what you are saying:

the tag <html:form action="/someAction"> will trigger FormTag.doStartTag(),
which will append ".do" if no extension was specified. I guess it looks
first to see if if extension mapping is being used vs. path (???) mapping?

Maybe I should go review the tag's java source... :)

Thanks,

Troy

-----Original Message-----
From: Rob Leland [mailto:Robert@freetocreate.org]
Sent: Tuesday, March 20, 2001 9:36 AM
To: struts-user@jakarta.apache.org
Subject: Re: strange html:form tag


Then struts html:form tag is processed
if the action name does not have
a .do at the end, one will be appended so when
it is sent out to the browser it will
always see a 'XXX.do' present.

Troy Hart wrote:
>
> What does that mean? How do you set up your servlet mapping in web.xml
then?
>
> -----Original Message-----
> From: Rob Leland [mailto:Robert@freetocreate.org]
> Sent: Tuesday, March 20, 2001 6:39 AM
> To: struts-user@jakarta.apache.org
> Subject: Re: strange html:form tag
>
> Yuan Jun wrote:
> >
> > i download jakarta-struts-1.0-b1 today and found next in
registration.jsp
> >
> > <html:form action="/saveRegistration">
> > <html:hidden property="action"/>
> > <table border="0" width="100%">
> >
> > should it be:
> > <html:form action="/saveRegistration.do">
>
> Either would be correct.
>
> The '.do' has been optional since the last week
> in January, maybe before.
>
> > or i've missed something?
> >
> > John.
>
> -Rob


Re: strange html:form tag

Posted by Rob Leland <Ro...@freetocreate.org>.
Then struts html:form tag is processed
if the action name does not have
a .do at the end, one will be appended so when
it is sent out to the browser it will
always see a 'XXX.do' present.

Troy Hart wrote:
> 
> What does that mean? How do you set up your servlet mapping in web.xml then?
> 
> -----Original Message-----
> From: Rob Leland [mailto:Robert@freetocreate.org]
> Sent: Tuesday, March 20, 2001 6:39 AM
> To: struts-user@jakarta.apache.org
> Subject: Re: strange html:form tag
> 
> Yuan Jun wrote:
> >
> > i download jakarta-struts-1.0-b1 today and found next in registration.jsp
> >
> > <html:form action="/saveRegistration">
> > <html:hidden property="action"/>
> > <table border="0" width="100%">
> >
> > should it be:
> > <html:form action="/saveRegistration.do">
> 
> Either would be correct.
> 
> The '.do' has been optional since the last week
> in January, maybe before.
> 
> > or i've missed something?
> >
> > John.
> 
> -Rob

RE: strange html:form tag

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Tue, 20 Mar 2001, Troy Hart wrote:

> What does that mean? How do you set up your servlet mapping in web.xml then?
> 

You still need to set up your <servlet-mapping> in web.xml, the same as
you did before.

THe difference is that the Struts controller servlet reads the web.xml
file itself at startup time, and remembers which mapping you have
selected.  If you do the usual extension mapping ("*.do"), it will
generate a hyperlink to "/saveRegistration.do").  Likewise, if you use
path mapping instead (say, "/execute/*"), the same <html:form> tag would
generate a hyperlink to "/execute/saveRegistration".

Craig


> -----Original Message-----
> From: Rob Leland [mailto:Robert@freetocreate.org]
> Sent: Tuesday, March 20, 2001 6:39 AM
> To: struts-user@jakarta.apache.org
> Subject: Re: strange html:form tag
> 
> 
> 
> 
> Yuan Jun wrote:
> > 
> > i download jakarta-struts-1.0-b1 today and found next in registration.jsp
> > 
> > <html:form action="/saveRegistration">
> > <html:hidden property="action"/>
> > <table border="0" width="100%">
> > 
> > should it be:
> > <html:form action="/saveRegistration.do">
> 
> Either would be correct.
> 
> The '.do' has been optional since the last week
> in January, maybe before.
> 
> > or i've missed something?
> > 
> > John.
> 
> -Rob
> 


RE: strange html:form tag

Posted by Troy Hart <th...@part.net>.
What does that mean? How do you set up your servlet mapping in web.xml then?

-----Original Message-----
From: Rob Leland [mailto:Robert@freetocreate.org]
Sent: Tuesday, March 20, 2001 6:39 AM
To: struts-user@jakarta.apache.org
Subject: Re: strange html:form tag




Yuan Jun wrote:
> 
> i download jakarta-struts-1.0-b1 today and found next in registration.jsp
> 
> <html:form action="/saveRegistration">
> <html:hidden property="action"/>
> <table border="0" width="100%">
> 
> should it be:
> <html:form action="/saveRegistration.do">

Either would be correct.

The '.do' has been optional since the last week
in January, maybe before.

> or i've missed something?
> 
> John.

-Rob

Re: strange html:form tag

Posted by Rob Leland <Ro...@freetocreate.org>.

Yuan Jun wrote:
> 
> i download jakarta-struts-1.0-b1 today and found next in registration.jsp
> 
> <html:form action="/saveRegistration">
> <html:hidden property="action"/>
> <table border="0" width="100%">
> 
> should it be:
> <html:form action="/saveRegistration.do">

Either would be correct.

The '.do' has been optional since the last week
in January, maybe before.

> or i've missed something?
> 
> John.

-Rob

RE: strange html:form tag

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Wed, 21 Mar 2001, Yuan Jun wrote:

> 
> 
> > On Tue, 20 Mar 2001, Yuan Jun wrote:
> >
> > > i download jakarta-struts-1.0-b1 today and found next in
> > registration.jsp
> > >
> > > <html:form action="/saveRegistration">
> > > <html:hidden property="action"/>
> > > <table border="0" width="100%">
> > >
> > > should it be:
> > > <html:form action="/saveRegistration.do">
> > > or i've missed something?
> > >
> >
> > Although the latter still works, the <html:form> tag has been made smart
> > enough to figure out how an action path is mapped to the controller
> > servlet.  The former will work even if you change from path mapping to
> > extension mapping (or vice versa), for example.
> >
> 
> i see. but when i depoyed struts-example to orion 1.4.5, it did work. i have
> to modify jsp files adding .do to html:form to make it work, is it a bug of
> orion?
> 

It might be.

In order for this to work, Struts has to be able to parse the web
application deployment descriptor (/WEB-INF/web.xml).  To do this, Struts
calls:

	InputStream is =
	  getServletContext().getResourceAsStream("/WEB-INF/web.xml");

At various times Orion has returned null from this call, because the
developers incorrectly believed that a servlet should not be able to
access resources in the /WEB-INF directory.  This has gone back and forth
in various Orion versions.

Are there any interesting log messages during the startup of the
controller servlet?

> John

Craig



RE: strange html:form tag

Posted by Yuan Jun <jo...@sunjapan.com.cn>.

> On Tue, 20 Mar 2001, Yuan Jun wrote:
>
> > i download jakarta-struts-1.0-b1 today and found next in
> registration.jsp
> >
> > <html:form action="/saveRegistration">
> > <html:hidden property="action"/>
> > <table border="0" width="100%">
> >
> > should it be:
> > <html:form action="/saveRegistration.do">
> > or i've missed something?
> >
>
> Although the latter still works, the <html:form> tag has been made smart
> enough to figure out how an action path is mapped to the controller
> servlet.  The former will work even if you change from path mapping to
> extension mapping (or vice versa), for example.
>

i see. but when i depoyed struts-example to orion 1.4.5, it did work. i have
to modify jsp files adding .do to html:form to make it work, is it a bug of
orion?

> > John.
> >
> >
>
> Craig
>
>
John


Re: strange html:form tag

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Tue, 20 Mar 2001, Yuan Jun wrote:

> i download jakarta-struts-1.0-b1 today and found next in registration.jsp
> 
> <html:form action="/saveRegistration">
> <html:hidden property="action"/>
> <table border="0" width="100%">
> 
> should it be:
> <html:form action="/saveRegistration.do">
> or i've missed something?
> 

Although the latter still works, the <html:form> tag has been made smart
enough to figure out how an action path is mapped to the controller
servlet.  The former will work even if you change from path mapping to
extension mapping (or vice versa), for example.

> John.
> 
> 

Craig



strange html:form tag

Posted by Yuan Jun <jo...@sunjapan.com.cn>.
i download jakarta-struts-1.0-b1 today and found next in registration.jsp

<html:form action="/saveRegistration">
<html:hidden property="action"/>
<table border="0" width="100%">

should it be:
<html:form action="/saveRegistration.do">
or i've missed something?

John.