You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Biggie Bendra <bi...@yahoo.com> on 2004/10/19 04:38:18 UTC

help with actionform issue (page refresh)

Hello,

I'm having trouble doing what I want with a struts;
I've read through the documentation and examples but
haven't found anything quite like what I want to do. 
However, it seems like a common problem so perhaps
someone can help me.

I have two pages, one of which I will call query.jsp,
and the other report.jsp; I have action mappings for
them that I will call getQueryPage.do and getReport.do
respectively.  The getQueryPage.do is a
org.apache.struts.actions.ForwardAction, the
getReport.do is an action of my own with does the
actual work to generate the report.

I have a set of select boxes on query.jsp, and also
some text boxes.  I am using a DynaValidatorForm to
encapsulate these values; I will call this ActionForm
queryForm.  I am using the html:form and html:text
tags, and some custom tags to render the select boxes
(there is some slightly complicated logic to get the
collections for the other select boxes that is
encapsulated in the java code for the tags); so
query.jsp looks something like (greatly simplified;
not actual code)

<script>
function refreshPage( form )
{
   form.action = 'getQueryPage.do';
   form.submit();
}
</script>

<html:form action="getReport.do">
  <html:text property="startDate" />
  <html:text property="endDate" />
  <mytags:companyselect onchange="refreshPage(
this.form )" />
  <mytags:branchselect />
  <mytags:codeselect code="outletType" />
  <mytags:codeselect code="status" />
</html:form>

So this works fine for the initial page viewing; also
it works if validation fails; the html:text tags
remember their values, and I've written my tags to do
so as well.

When the value of the companyselect changes, the page
gets refreshed and my branchselect and codeselect
tages are updated as appropriate; however of course
the html:text values get lost. :-(

What I want is to be able to re-present the query.jsp,
but instead of re-initializing queryForm to use the
existing form in the request, like what happens when
validation fails (but without an error message, and
preferably using the same URL getQueryPage.do).

I'm new to struts, so I may be going about this all
wrong; it seems there must be an easy way to do this
since it seems like a pretty common requirement. 
Right now I can think of three approaches:

1) Don't use the html:text stuff at all, instead write
my own tag that looks first in the ActionForm for a
value, and if none is there looks in the http request
directly (this is basically what I am doing in the
mytags.branchselect and mytags.codeselect ).  Seems
wasteful.

2) in javascript refreshPage(), instead of changing
the action of the form set some dummy value to cause a
message-less validation error on the server, so that
the query page will get re-presented.  Seems awfully
hacky.

3) SOMEHOW tell struts not to create a new form for
the html:form tag if one already exists in the
request...this is what I really want to do but I don't
see a way to do it.

Or am I going about this all wrong?

Thanks in advance for any help you can give.  If there
is an example that I have overlooked that does this I
would appreciate being directed to it.

bye-Ben


		
_______________________________
Do you Yahoo!?
Declare Yourself - Register online to vote today!
http://vote.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: help with actionform issue (page refresh)

Posted by Biggie Bendra <bi...@yahoo.com>.
Yep, that did it.  Thank you very much!

bye-Ben

--- Hubert Rabago <hr...@gmail.com> wrote:

> Try modifying the mapping of /getQueryPage to
> include your form, but
> also not to validate it.  Also, make sure that the
> form is placed on
> the same scope as that for /getReport.
> 
> So, something like this:
> 
> <action path="/getQueryPage"
>     type="org.apache.struts.actions.ForwardAction"
>     form="whateverFormYoureUsingForGetReport"
>     validate="false"
>     scope="whateverScopeYoureUsingForGetReport"
>     parameter="query.jsp"/>
> 
> What I think will happen on initial load is Struts
> will create the
> form but will have no values to populate it with,
> and your form will
> show with empty values.  When refreshPage() gets
> called, it submits to
> this mapping, Struts will create the form, populate
> the values, and
> have it available for when query.jsp gets redrawn.
> 
> If it doesn't work, post here what happened.  You
> may have to put an
> Action in place of the ForwardAction to handle the
> form.
> 
> Hubert




		
_______________________________
Do you Yahoo!?
Declare Yourself - Register online to vote today!
http://vote.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: help with actionform issue (page refresh)

Posted by Hubert Rabago <hr...@gmail.com>.
Try modifying the mapping of /getQueryPage to include your form, but
also not to validate it.  Also, make sure that the form is placed on
the same scope as that for /getReport.

So, something like this:

<action path="/getQueryPage"
    type="org.apache.struts.actions.ForwardAction"
    form="whateverFormYoureUsingForGetReport"
    validate="false"
    scope="whateverScopeYoureUsingForGetReport"
    parameter="query.jsp"/>

What I think will happen on initial load is Struts will create the
form but will have no values to populate it with, and your form will
show with empty values.  When refreshPage() gets called, it submits to
this mapping, Struts will create the form, populate the values, and
have it available for when query.jsp gets redrawn.

If it doesn't work, post here what happened.  You may have to put an
Action in place of the ForwardAction to handle the form.

Hubert


On Mon, 18 Oct 2004 19:38:18 -0700 (PDT), Biggie Bendra
<bi...@yahoo.com> wrote:
> Hello,
> 
> I'm having trouble doing what I want with a struts;
> I've read through the documentation and examples but
> haven't found anything quite like what I want to do.
> However, it seems like a common problem so perhaps
> someone can help me.
> 
> I have two pages, one of which I will call query.jsp,
> and the other report.jsp; I have action mappings for
> them that I will call getQueryPage.do and getReport.do
> respectively.  The getQueryPage.do is a
> org.apache.struts.actions.ForwardAction, the
> getReport.do is an action of my own with does the
> actual work to generate the report.
> 
> I have a set of select boxes on query.jsp, and also
> some text boxes.  I am using a DynaValidatorForm to
> encapsulate these values; I will call this ActionForm
> queryForm.  I am using the html:form and html:text
> tags, and some custom tags to render the select boxes
> (there is some slightly complicated logic to get the
> collections for the other select boxes that is
> encapsulated in the java code for the tags); so
> query.jsp looks something like (greatly simplified;
> not actual code)
> 
> <script>
> function refreshPage( form )
> {
>   form.action = 'getQueryPage.do';
>   form.submit();
> }
> </script>
> 
> <html:form action="getReport.do">
>  <html:text property="startDate" />
>  <html:text property="endDate" />
>  <mytags:companyselect onchange="refreshPage(
> this.form )" />
>  <mytags:branchselect />
>  <mytags:codeselect code="outletType" />
>  <mytags:codeselect code="status" />
> </html:form>
> 
> So this works fine for the initial page viewing; also
> it works if validation fails; the html:text tags
> remember their values, and I've written my tags to do
> so as well.
> 
> When the value of the companyselect changes, the page
> gets refreshed and my branchselect and codeselect
> tages are updated as appropriate; however of course
> the html:text values get lost. :-(
> 
> What I want is to be able to re-present the query.jsp,
> but instead of re-initializing queryForm to use the
> existing form in the request, like what happens when
> validation fails (but without an error message, and
> preferably using the same URL getQueryPage.do).
> 
> I'm new to struts, so I may be going about this all
> wrong; it seems there must be an easy way to do this
> since it seems like a pretty common requirement.
> Right now I can think of three approaches:
> 
> 1) Don't use the html:text stuff at all, instead write
> my own tag that looks first in the ActionForm for a
> value, and if none is there looks in the http request
> directly (this is basically what I am doing in the
> mytags.branchselect and mytags.codeselect ).  Seems
> wasteful.
> 
> 2) in javascript refreshPage(), instead of changing
> the action of the form set some dummy value to cause a
> message-less validation error on the server, so that
> the query page will get re-presented.  Seems awfully
> hacky.
> 
> 3) SOMEHOW tell struts not to create a new form for
> the html:form tag if one already exists in the
> request...this is what I really want to do but I don't
> see a way to do it.
> 
> Or am I going about this all wrong?
> 
> Thanks in advance for any help you can give.  If there
> is an example that I have overlooked that does this I
> would appreciate being directed to it.
> 
> bye-Ben
> 
> _______________________________
> Do you Yahoo!?
> Declare Yourself - Register online to vote today!
> http://vote.yahoo.com
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org