You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Thai Thanh Ha <th...@psv.com.vn> on 2001/03/05 05:35:08 UTC

Problem in Struts example (struts-example.war)

 Hi all,

 I have found this  code in the Struts example (file:
EditRegistrationAction.java, line: 144)

 if (form == null) {
   ...   
 }

 When EditRegistrationAction.perform() is called, form will be a reference
to a RegistrationForm (*never* be null, because the ActionForm object has
been created before by the ActionServlet object). Is it correct? Why has the
author written this code? Can anyone help me?

 Regards,
 Thai 

Re: Problem in Struts example (struts-example.war)

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

> Craig,
>
> If one Action chains to another using a ForwardingActionForward with no
> query string in the URL, will the form bean for the second Action still be
> created by Struts?
>

If you forward to a controller servlet URL (i.e. something like
"/saveCustomer.do?name1=value1&name2=value2" when using extension mapping), and
if the destination action has an "input" attribute defined, the form bean will
indeed be created by Struts (if it doesn't exist yet), and the form bean
properties will be populated.

However, you should be aware that the set of request parameters seen by the
"second" request will be the *union* of request parameters from the query string
(name1 and name2 in my example above) and the request parameters from the
original request.  If you have the same parameter name defined in both the query
string and the original request, both values will be passed (the one from the
query string first), so your corresponding bean property will need to accept an
array to avoid conversion problems.

>
> --
> Martin Cooper
>

Craig


>
> ----- Original Message -----
> From: "Craig R. McClanahan" <Cr...@eng.sun.com>
> To: <st...@jakarta.apache.org>
> Sent: Sunday, March 04, 2001 9:40 PM
> Subject: Re: Problem in Struts example (struts-example.war)
>
> > Thai Thanh Ha wrote:
> >
> > >  Hi all,
> > >
> > >  I have found this  code in the Struts example (file:
> > > EditRegistrationAction.java, line: 144)
> > >
> > >  if (form == null) {
> > >    ...
> > >  }
> > >
> > >  When EditRegistrationAction.perform() is called, form will be a
> reference
> > > to a RegistrationForm (*never* be null, because the ActionForm object
> has
> > > been created before by the ActionServlet object). Is it correct? Why has
> the
> > > author written this code? Can anyone help me?
> > >
> >
> > The "form" object passed to an Action will indeed be null if the
> > struts-config.xml file does not define an "input" attribute for this
> particular
> > action.
> >
> > Although that is not the case currently for the Struts example app,
> consider me
> > an old paranoid programmer about double checking the "it can never happen"
> cases
> > ... :-)
> >
> > >
> > >  Regards,
> > >  Thai
> >
> > Craig McClanahan
> >
> >


RE: Action forwards

Posted by Katherine Barry <kb...@SS8.com>.
We are have a side-menu so generally it hasn't been a problem. What we do
care about is the refresh. We would like to be able to use it, but it goes
back to the original page forces us to log back in. If we live with
forwards, can we get the refresh to work?

Thanks.

Katherine

-----Original Message-----
From: Craig R. McClanahan [mailto:Craig.McClanahan@eng.sun.com]
Sent: Tuesday, March 06, 2001 10:03 AM
To: struts-user@jakarta.apache.org
Subject: Re: Action forwards


Katherine Barry wrote:

> We are using action forwards, but the url in the browser never changes.
> Everything works happily, so the only thing we want is for the browser to
> change and display the new URL(mainly for the refresh button). I know
> everyone is now using 1.0, but we haven't migrated, and are still using
> 0.5(we are to close to release to have changed). How can I get the browser
> to update?
>

What you are seeing is the result of how a RequestDispatcher.forward()
works.
This all happens on the server side, and the client browser has no clue what
happened.  The only way to get the browser's displayed URL to change would
be
to use redirects instead of forwards, which has two disadvantages:

* It is much slower, because of the extra round trip to the browser

* It eliminates the ability to use request attributes, because the redirect
  comes in as a separate request.

As I general rule, I train my users to totally ignore the location bar when
running a web application (as opposed to surfing a web site).  If they still
get confused, you have several options:

* Run inside a framed presentation so that the location bar
  *never* changes.

* Use JavaScript to create a new window that has no location
  bar, and run your app inside that.

* Get some new users (don't we wish sometimes :-).


> Katherine

Craig


Re: Action forwards

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

> We are using action forwards, but the url in the browser never changes.
> Everything works happily, so the only thing we want is for the browser to
> change and display the new URL(mainly for the refresh button). I know
> everyone is now using 1.0, but we haven't migrated, and are still using
> 0.5(we are to close to release to have changed). How can I get the browser
> to update?
>

What you are seeing is the result of how a RequestDispatcher.forward() works.
This all happens on the server side, and the client browser has no clue what
happened.  The only way to get the browser's displayed URL to change would be
to use redirects instead of forwards, which has two disadvantages:

* It is much slower, because of the extra round trip to the browser

* It eliminates the ability to use request attributes, because the redirect
  comes in as a separate request.

As I general rule, I train my users to totally ignore the location bar when
running a web application (as opposed to surfing a web site).  If they still
get confused, you have several options:

* Run inside a framed presentation so that the location bar
  *never* changes.

* Use JavaScript to create a new window that has no location
  bar, and run your app inside that.

* Get some new users (don't we wish sometimes :-).


> Katherine

Craig



Re: Action forwards

Posted by Ted Husted <ne...@husted.com>.
Katherine Barry wrote:
> We are using action forwards, but the url in the browser never changes.
> Everything works happily, so the only thing we want is for the browser to
> change and display the new URL(mainly for the refresh button).

I believe Refresh repeats the last request, rather than the URL that
appears in the browser's address window. 

If you want refresh to redisplay the current page (without repeating the
last request, which may include input from a form), then you should use
the redirect technique that Craig mentioned. (In which case generating a
new request becomes a benefit rather than a drawback.)

-- Ted Husted, Husted dot Com, Fairport NY USA.
-- Custom Software ~ Technical Services.
-- Tel 716 737-3463.
-- http://www.husted.com/about/struts/

Action forwards

Posted by Katherine Barry <kb...@SS8.com>.
We are using action forwards, but the url in the browser never changes.
Everything works happily, so the only thing we want is for the browser to
change and display the new URL(mainly for the refresh button). I know
everyone is now using 1.0, but we haven't migrated, and are still using
0.5(we are to close to release to have changed). How can I get the browser
to update?

Katherine


newbie: org.apache.struts.digester, HELP please

Posted by Joel Cordonnier <jo...@yahoo.fr>.
Hi ! i'm a mewbie with struts.

In fact, i'm very interested in the
org.apache.struts.digester package for XML parsing.
There a some questions:

- I have some XML file that are processed by XSLT for
rendering, and i have also to build an other version
of the front end with JSP pages. IS STRUTS THE RIGHT
TOOL ?

- if so, is there some example that use the
org.apache.struts.digester package ?

Thanks
Joel

___________________________________________________________
Do You Yahoo!? -- Pour dialoguer en direct avec vos amis, 
Yahoo! Messenger : http://fr.messenger.yahoo.com

Re: Problem in Struts example (struts-example.war)

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

If one Action chains to another using a ForwardingActionForward with no
query string in the URL, will the form bean for the second Action still be
created by Struts?

--
Martin Cooper

----- Original Message -----
From: "Craig R. McClanahan" <Cr...@eng.sun.com>
To: <st...@jakarta.apache.org>
Sent: Sunday, March 04, 2001 9:40 PM
Subject: Re: Problem in Struts example (struts-example.war)


> Thai Thanh Ha wrote:
>
> >  Hi all,
> >
> >  I have found this  code in the Struts example (file:
> > EditRegistrationAction.java, line: 144)
> >
> >  if (form == null) {
> >    ...
> >  }
> >
> >  When EditRegistrationAction.perform() is called, form will be a
reference
> > to a RegistrationForm (*never* be null, because the ActionForm object
has
> > been created before by the ActionServlet object). Is it correct? Why has
the
> > author written this code? Can anyone help me?
> >
>
> The "form" object passed to an Action will indeed be null if the
> struts-config.xml file does not define an "input" attribute for this
particular
> action.
>
> Although that is not the case currently for the Struts example app,
consider me
> an old paranoid programmer about double checking the "it can never happen"
cases
> ... :-)
>
> >
> >  Regards,
> >  Thai
>
> Craig McClanahan
>
>



Re: Problem in Struts example (struts-example.war)

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

> Is this really true?  I have an Action that doesn't define an input
> attribute, but does specify a request scope ActionForm.  According to the
> log messages, Struts creates an instance of the form and stores it under
> the appropriate key before calling my Action.perform() method.  In
> addition, the code I have to handle the form == null case never seems to
> get called.
>

Sorry ... I was almost right.

Struts automatically creates an action form bean for you if your mapping
specifies the *name* attribute, which names the <form-bean> entry that is
relevant for this action. If this is omitted, no form bean will be created and
the form bean argument will be null.

Craig


>
> At 11:40 PM 3/4/2001, Craig McClanahan wrote:
> >The "form" object passed to an Action will indeed be null if the
> >struts-config.xml file does not define an "input" attribute for this
> >particular
> >action.
> >
> >Although that is not the case currently for the Struts example app,
> >consider me
> >an old paranoid programmer about double checking the "it can never happen"
> >cases
> >... :-)
>
> Mike


Re: Problem in Struts example (struts-example.war)

Posted by Michael McCallister <r2...@email.sps.mot.com>.
Is this really true?  I have an Action that doesn't define an input 
attribute, but does specify a request scope ActionForm.  According to the 
log messages, Struts creates an instance of the form and stores it under 
the appropriate key before calling my Action.perform() method.  In 
addition, the code I have to handle the form == null case never seems to 
get called.


At 11:40 PM 3/4/2001, Craig McClanahan wrote:
>The "form" object passed to an Action will indeed be null if the
>struts-config.xml file does not define an "input" attribute for this 
>particular
>action.
>
>Although that is not the case currently for the Struts example app, 
>consider me
>an old paranoid programmer about double checking the "it can never happen" 
>cases
>... :-)


Mike


Re: Problem in Struts example (struts-example.war)

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
Thai Thanh Ha wrote:

>  Hi all,
>
>  I have found this  code in the Struts example (file:
> EditRegistrationAction.java, line: 144)
>
>  if (form == null) {
>    ...
>  }
>
>  When EditRegistrationAction.perform() is called, form will be a reference
> to a RegistrationForm (*never* be null, because the ActionForm object has
> been created before by the ActionServlet object). Is it correct? Why has the
> author written this code? Can anyone help me?
>

The "form" object passed to an Action will indeed be null if the
struts-config.xml file does not define an "input" attribute for this particular
action.

Although that is not the case currently for the Struts example app, consider me
an old paranoid programmer about double checking the "it can never happen" cases
... :-)

>
>  Regards,
>  Thai

Craig McClanahan