struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fzli...@omnytex.com
Subject Re: Accessing my form from an included page
Date Wed, 22 Dec 2004 19:48:49 GMT
On Wed, December 22, 2004 1:56 pm, Dakota Jack said:
> Plasma TV?  Not a new copy of Java Today?  LOL  ;-)

No self-respecting geek would choose the magazine! :)

(self-respecting geek... talk about an oxymoron!)

> The form has a name from the mapping.  Whatever servlet, html, etc.
> you have is going to reflect that form, right?  What you want to do is
> manage the RESPONSE not the REQUEST, right?  The form is not in the
> request but in the response.

Let's ignore any taglibs for the moment because it lets us get to the core of what's going
on...

If in a JSP I have the following scriplet:

<%
SearchForAssetActionForm form = (SearchForAssetActionForm)request.getAttribute("SearchForAssetActionForm");
%>

This gets me a reference to the form for this page (assuming everything else is right... this
is right out of a current production app, so it is).  Also assume Struts 1.1, since I don't
know what may or may not have changed since then.

As you can see, I have to know the exact name of the attribute in request (I did mean request)
to get a reference to it.

Now, if we assume, using the example I had the last post in this thread, that this scriptlet
were to be in header.jsp, which is going to be included in a number of different pages, obviously
this is going to be a problem (null pointer... would it throw an exception?  Not actually
sure, but I digress...)  This code really only should be in the page1.jsp (searchForAsset.jsp
in this case), the header shouldn't know anything about the page it's being included in. 
In fact, it can't not specifically.

So, how to let the code in header.jsp get a reference to the above variable, assuming the
above scriplet is NOT in header.jsp?  Three ways that I can see:

(a) Make sure the above scriplet appears BEFORE the include of header.jsp.  So when the servlet
is constructed, the variable is already declared when the code in header.jsp might make use
of it.  So now header.jsp just knows about a variable named form, and assuming it calls methods
that would be common to all forms, no problem.

(b) header.jsp can look at the ActionMapping, which I *believe* is in request as well, and
use that to determine the actual name of the attribute to retrieve(SearchForAssetActionForm
here).

(c) In all Actions always be sure to put a copy of the form in request under a standard name
(like "form") and header.jsp can always go after that.

>> We might be saying the same thing in the end anyway :)
> 
> 
> We might be.  It looks as if you might be confusing the request with
> the response, but that seems unlikely.  Are you having a "brain f__ t"
> ?  lol  ;-)  I AM KIDDING!  You know that, I am sure.

Me?!?  A brain-fart?!?  Surely you jest! ;)

Seriously though, I wasn't confused... Now, you may have an argument that I've been doing
things in an odd way all along, I'm perfectly willing to entertain taht thought.
 
> If an included file simply accesses the form in the page it is on,
> that works.  Think of how easy this all will be with Tiger.  I cannot
> wait for Tiger.

This is the part I don't understand... not the part about Tiger (although I'm not sure where
you were going with that, but that's another discussion)... My whole point is that the name
of the attribute the form is stored under, forget about where that attribute actually is,
is dependent on the page, usually anyway... For any code in header.jsp to be able to access
it, it has to somehow know the name of the attribute.  It can't usually know this except to
know it for ALL pages, which means a giant branch logic, unless the element always has the
same name, either by virtue of it beign declared that way in struts-config or by the Actions
putting a copy somewhere under that common name.

> Jack

-- 
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com

> ------------------------------
> 
> "You can lead a horse to water but you cannot make it float on its back."
> 
> ~Dakota Jack~
> 
> "You can't wake a person who is pretending to be asleep."
> 
> ~Native Proverb~
> 
> "Each man is good in His sight. It is not necessary for eagles to be
> crows."
> 
> ~Hunkesni (Sitting Bull), Hunkpapa Sioux~
> 
> -----------------------------------------------
> 
> "This message may contain confidential and/or privileged information.
> If you are not the addressee or authorized to receive this for the
> addressee, you must not use, copy, disclose, or take any action based
> on this message or any information herein. If you have received this
> message in error, please advise the sender immediately by reply e-mail
> and delete this message. Thank you for your cooperation."
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 


Mime
View raw message