You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Tom Holmes Jr." <to...@tomholmes.net> on 2004/09/10 01:33:00 UTC

Imports and Form Submits

I have a webpage called 'default.jsp' and it has three <c:import> tags.
One does the header, footer, and body.  The Header and Footer are fine, 
but the middle page is a 'jsp' page with nothing but a form in it ... I 
mean it starts out like <html:form ...>
It also has some taglibs designed, and a resource bundle.

What I want to happen is when this middle page is loaded, I want the 
form in the middle import <c:import url="myform.jsp"> to be 
automatically executed when the main default.jsp page loads.  The Header 
and Footer work fine for importing HTML, but the form in the middle I 
want to be run immediatley when the main page gets called.  Obviously, 
submitting the form would called the ActionBean and that is what I want 
to happen.

I've tried having the middle import call the 'myform.do' file directly, 
but then I get a JasperException Error.

Is there any way to do this?  An easy way to do this?  Do I need to do 
Javascript and an 'onload' function or,

Any help would be much appreciated.   Thanks.

           Tom


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


Re: Imports and Form Submits

Posted by Michael McGrady <mi...@michaelmcgrady.com>.
In other words, Tom, use the following (again assuming this is 
appropriate for <c:import/>) and have the Action class for listdata.do 
return listdata.jsp with all the appropriate values set in your 
ActionForm class.

>
>> <body>
>>     <c:import url="/myapp/includes/header.jsp" />
>>     <c:import url="/myapp/includes/listdata.do" />
>>     <c:import url="/myapp/includes/footer.jsp" />
>> </body>
>>

Michael


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


Re: Imports and Form Submits

Posted by Michael McGrady <mi...@michaelmcgrady.com>.
Tom Holmes Jr. wrote:

> <body>
>     <c:import url="/myapp/includes/header.jsp" />
>     <c:import url="/myapp/includes/listdata.jsp" />
>     <c:import url="/myapp/includes/footer.jsp" />
> </body>
>

Even though I don't use <c:import/> if you have propertly defined .do in 
your xml and listdata.do return a response with the proper HTML, then it 
should work okay.  Do you you have your action class for listdata.do 
forward to listdata.jsp?  I assume that <c:import url="whatever.do"/> is 
appropriate. 

Michael




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


Re: Imports and Form Submits

Posted by Wendy Smoak <ja...@wendysmoak.com>.
From: "Tom Holmes Jr." <to...@tomholmes.net>
> In my limited knowledge of Struts ... in order to execute this action
> which gets my data, it requires a submit to call the action.

No, it requires an HTTP request to the URL that's mapped to the action.
Typically http://www.example.com/myapp/something.do

That could be a click on a button, or just typing the URL into a browser, or
clicking on an <a href=...> link.

That HTTP request makes the Action code run.  Depending on what's in the
request (almost nothing, in the case of the initial request,) it either does
some setup work or processes the submitted data, and determines what
response to send.

There are ways to skip validation on the first request, so you don't show
the form with a bunch of errors.  You can check to see if the form was
POSTed to you, or else look for the presence of a hidden field on the form,
which won't be there unless it was POSTed.

-- 
Wendy Smoak


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


Re: Imports and Form Submits

Posted by "Tom Holmes Jr." <to...@tomholmes.net>.
I started out my knowledge of Struts with "Jakarta Struts for Dummies" 
and they have a sample application called "Music List Collection" that I 
am basing some this on.

Basically, all I want to do is get a list of data displayed on the 
screen.  If I include a submit button and hit it, then the action is 
called, the bean is called, a collection of data is returned, that 
collection is put into the session into the Action Servlet. And then we 
iterate through the data to display this information on the screen.

The form is not a form where the user is entering data ... however, we 
may want to add a record, we may want to delete a record, or we may want 
to select a record for editing, all depending on what SUBMIT button we 
click on.  So, that is the reason we have a form ... so that when we 
call the Action Servlet, that it determines what functionality we are 
doing.  Hence when we first call this form ... there doesn't need to do 
any validation.

In my limited knowledge of Struts ... in order to execute this action 
which gets my data, it requires a submit to call the action.

So, I have a default.jsp page with 3 imports simply by using <c:import> 
tags.

<body>
	<c:import url="/myapp/includes/header.jsp" />
	<c:import url="/myapp/includes/listdata.jsp" />
	<c:import url="/myapp/includes/footer.jsp" />
</body>

The "listdata.jsp" has 3 taglibs included, a resource bundle and then we 
have:

<html:form action="listdata.do"
	<html:hidden value="">
	<html:submit />
</html:form>

With these imports, the default page loads in all three pages and the 
listdata.jsp also loads ... but without calling the action first.  So, I 
tried something like this:

<body>
	<c:import url="/myapp/includes/header.jsp" />
	<c:import url="/myapp/includes/listdata.do" />
	<c:import url="/myapp/includes/footer.jsp" />
</body>

I figured this way, the action would be called whenever we come back to 
default.jsp.  But it seems like I get a JasperException Error when this 
happens.   Maybe what I did was an infinite loop because it kept calling 
the listdata.do and when it's done, the struts-config.xml says to go 
back to default.jsp.

So, again, I want to display a list of data from the database when the 
page is first called ... then I'll have the choice to choose a record 
for updating, deleting, viewing, or adding a new record ... and then go 
back to the list page so I can see the new record added.

I hope this helps with explaining what I am trying to do.   Thanks for 
you help.

                    Tom


Michael McGrady wrote:

> Tom Holmes Jr. wrote:
> 
>> I have a webpage
> 
> 
> 
> 
> Wendy is right.  We really need to know what you are trying to achieve 
> because an automatic submission of a form makes no apparent sense.  When 
> you say middle "page" do you mean like a tile?
> Michael
> 
> 
> ---------------------------------------------------------------------
> 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


Re: Imports and Form Submits

Posted by Michael McGrady <mi...@michaelmcgrady.com>.
Tom Holmes Jr. wrote:

> I have a webpage



Wendy is right.  We really need to know what you are trying to achieve 
because an automatic submission of a form makes no apparent sense.  When 
you say middle "page" do you mean like a tile? 

Michael


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


Re: Imports and Form Submits

Posted by Wendy Smoak <ja...@wendysmoak.com>.
From: "Tom Holmes Jr." <to...@tomholmes.net>
> What I want to happen is when this middle page is loaded, I want the
> form in the middle import <c:import url="myform.jsp"> to be
> automatically executed when the main default.jsp page loads.

Sounds like you shouldn't let them go to 'default.jsp' to begin with, you
should send them to myform.do, and have *that* forward to default.jsp.

That way, your Action code gets executed (which I assume is what you want to
happen) and then the form gets displayed.

If that doesn't help, please describe the problem you're trying to solve by
doing this, someone may have a different solution you can try.

It doesn't make sense to load a page and immediately submit the form... if
you're not going to give the user a chance to fill in the form before it
submits, you don't need to display it.

-- 
Wendy Smoak


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