I was just looking at this code to try to figure out my problem (Problem
finding classes after forward (resend)).  I have learned some things,
although I wouldn't say I really understand all of them, yet.

When you go into the ActionServlet and are being directed to an Action, if
there is a formbean associated with the action (the "name=" attribute of the
action tag in the struts-config.xml file), the ActionServlet will try to get
such a named object from the request.  If it doesn't find it, it creates an
instance of the class you specified in the form-bean tag (also in the
struts-config.xml file) and then puts it in the request under the name you
specified in the action tag.  So, theoretically, you should just be able to
pull it out of the request in your .jsp file and use it, either using
<jsp:useBean> or scriptlet code that uses request.getAttribute().

Okay, here's the bad news...it doesn't work for me.  I found that the reason
it doesn't work is that the ActionServlet code is referring to the formbean
object as an ActionForm at the time that it puts it into the request.  I'm
not sure why, but when you take it out, using one of the above techniques,
it can only be cast to be an ActionForm!  The reason the <html:*> tags, like
<html:text>, work is because they don't try to cast to your class.  Instead,
they use introspection to call the getter for the property.

It may be possible to use the <bean:*> tags to access that bean, but our ISP
is currently having problems, so I can't check....  :-(

Does anyone else think this is a problem?  Shouldn't I be able to do a
<jsp:useBean> on a bean that is my class?  For example, I (like Daniel?)
need to get data out of the bean outside of the <html:form> context (e.g.,
to display the user's name when editing the address)?

BTW, I may have some configuration problem that is making this not work for
me...so it might work for you.  I'm going to try something else and will
report if it works.

Scott

> -----Original Message-----
> From: Deadman, Hal [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, April 05, 2001 12:11 PM
> To: [EMAIL PROTECTED]
> Subject: RE: how to access related ActionForm from within .jsp?
> 
> 
> The form bean is associated with an action, not a jsp. The 
> jsp may contain
> an html:form which references an action, thereby gaining 
> access to the form
> associated with that action. A jsp could have multiple html:forms. 
> 
> The form bean associated with the action is available in 
> request scope for
> the jsp but I don't know how you would get access to it 
> without using the
> name of the form. Is there a struts tag that will get 
> actionmapping values
> when given the name of the action? That would allow you to 
> get the form bean
> name using the same action used by the html:form. 
> 
> Maybe you could use the bean:struts tag to get the action 
> mapping and then
> get the form from that. 
> 
> Hal
> 
> > -----Original Message-----
> > From: Daniel Toms [mailto:[EMAIL PROTECTED]]
> > Sent: Thursday, April 05, 2001 2:50 PM
> > To: Struts-User
> > Subject: how to access related ActionForm from within .jsp?
> > 
> > 
> > I am having a common problem all over the place.
> > Struts allows you to associate a bean(the ActionForm)
> > with a given .jsp.  It then magically gets and sets
> > input fields for you.  Great.
> > 
> > But all of the other struts tags require a reference
> > to a bean by name, using the name="foo" argument
> > to the tag.
> > 
> > My problem is, I want to reference the bean associated
> > with my jsp, so that when I want to iterated over a collection
> > it contains, I can do so without having to know the bean's name.
> > 
> > example:
> > 
> > 
> > public final class FooForm extends ActionForm
> > {
> >     public Collection bar;
> > 
> >     public Collection getBar()
> >     {
> >             return bar;
> >     }
> > 
> >     public void setBar(Collection b
> >     {
> >             this.bar = b;
> >     }
> > }
> > 
> > then in my jsp:
> > 
> >   <logic:iterate name="???" id="criterion">
> >     <TR>
> > 
> >       <TD><bean:write name="criterion" 
> property="propertyName"/></TD>
> >       <TD><bean:write name="criterion" property="operator"/></TD>
> >       <TD><bean:write name="criterion" 
> property="propertyValue"/></TD>
> >    </TR>
> >     </logic:iterate>
> > 
> > So the iterate tag doesn't work because it wants a bean by 
> > name, but is
> > there something I haven't gotten that will make struts use the bean 
> > associated with the jsp and not one specified by name?  
> > 
> > thanks,
> > 
> > dan
> > 
> 

Reply via email to