RE: how to access related ActionForm from within .jsp?

2001-04-05 Thread Daniel Toms

Thanks for your advice.  I really just wanted
to prevent having to duplicate hard coded form bean
names, i.e. in my jsps and in the config.xml.

I wrote a tag to get it from the action mapping,
but alas, that didn't work either.  For one, my
action mapping was null(probably some misconfig on
my part).  Secondly, it looks like when you
nest a custom tag within the attribute of another
custom tag, it doesn't get evaluated, so
doing 
won't work anyway.  Although this works fine for html tags.

thanks,

dan


> -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:
> >
> >   
> > 
> >
> >   
> >   
> >   
> >
> > 
> >
> > 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
> >
>




RE: how to access related ActionForm from within .jsp?

2001-04-05 Thread Scott Cressler

OK, problem solved!

The problem was a (for me) very esoteric aspect of Java.  The class loader
used when loading the class when it was created (within struts) was
*different* from the class loader used when attempting to load the class,
e.g., for casting, within my .jsp files.  This made a difference, *even
though* the class that was loaded was the same file from the *SAME*
directory!  Apparently, the internal identifier used to identify the class
is different depending on the class loader used.  The problem was that I had
put my /WEB-INF/classes directory in the class path used by resin
as well as the fact that it is the class directory used automatically to
find classes used by .jsp files.  So struts used one class loader and the
.jsp system used another.

The solution was to remove the classes from /WEB-INF/classes
directory.  Instead, I put it in the directory tree used to build our
product's jar file, which is already in the resin classpath.  So there was
only one way to find the class.

I don't much like this solution, because I think the actions are specific to
the particular application and so should fit in the
/WEB-INF/classes directory.  Unfortunately, if I remove them from
the resin classpath, struts can't find them.  I'll have to think some more
on how best to organize this.  Maybe I'll put them in a jar file that is
specific to the application, but which is not in the
/WEB-INF/classes directory.

If you are still having trouble getting access to the form bean, let me know
and I'll give you specific code examples of how I do it.

Scott

> -Original Message-
> From: Deadman, Hal [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, April 05, 2001 1:16 PM
> To: [EMAIL PROTECTED]
> Subject: RE: how to access related ActionForm from within .jsp?
> 
> 
> You are using redirect="false", correct? It shouldn't matter 
> what type is
> used when the action form is put in the request. setAttribute takes an
> Object so you can put anything in there but it will actually 
> be the type of
> the form bean specified in struts-config.xml. Can you submit 
> the section of
> the struts-config.xml file that contains the actions you are 
> using? There
> should be one action that forwards to the jsp with a 
> redirect=false. There
> should be another action that your jsp submits to. Both 
> actions should use
> the same form. You may want to submit part of the jsp that 
> tries to access
> the form bean. 
> 
> Hal
> 
> > -Original Message-
> > From: Scott Cressler [mailto:[EMAIL PROTECTED]]
> > Sent: Thursday, April 05, 2001 3:58 PM
> > To: '[EMAIL PROTECTED]'
> > Subject: RE: how to access related ActionForm from within .jsp?
> > 
> > 
> > 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
> >  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 
> >  tags, like
> > , 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  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
> >  on a bean that is my class?  For example, I 
> > (like Daniel?)
> > 

RE: how to access related ActionForm from within .jsp?

2001-04-05 Thread Deadman, Hal

You are using redirect="false", correct? It shouldn't matter what type is
used when the action form is put in the request. setAttribute takes an
Object so you can put anything in there but it will actually be the type of
the form bean specified in struts-config.xml. Can you submit the section of
the struts-config.xml file that contains the actions you are using? There
should be one action that forwards to the jsp with a redirect=false. There
should be another action that your jsp submits to. Both actions should use
the same form. You may want to submit part of the jsp that tries to access
the form bean. 

Hal

> -Original Message-
> From: Scott Cressler [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, April 05, 2001 3:58 PM
> To: '[EMAIL PROTECTED]'
> Subject: RE: how to access related ActionForm from within .jsp?
> 
> 
> 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
>  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 
>  tags, like
> , 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  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
>  on a bean that is my class?  For example, I 
> (like Daniel?)
> need to get data out of the bean outside of the  
> 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
> > >

RE: how to access related ActionForm from within .jsp?

2001-04-05 Thread Scott Cressler

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
 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  tags, like
, 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  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
 on a bean that is my class?  For example, I (like Daniel?)
need to get data out of the bean outside of the  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:
> > 
> >   
> > 
> > 
> >property="propertyName"/>
> >   
> >property="propertyValue"/>
> >
> > 
> > 
> > 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
> > 
> 



RE: how to access related ActionForm from within .jsp?

2001-04-05 Thread Deadman, Hal

Let me ammend my comment. The formbean will only be available in the jsp if
the action that forwards to that jsp specifies the form when it is defined
in struts-config.xml. Otherwise the formbean isn't created until the jsp
submits to the action that is defined as having the form. 

> -Original Message-
> From: Deadman, Hal 
> Sent: Thursday, April 05, 2001 3: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:
> > 
> >   
> > 
> > 
> >property="propertyName"/>
> >   
> >property="propertyValue"/>
> >
> > 
> > 
> > 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
> > 
> 



RE: how to access related ActionForm from within .jsp?

2001-04-05 Thread Deadman, Hal

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:
> 
>   
> 
> 
>   
>   
>   
>
> 
> 
> 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
> 



how to access related ActionForm from within .jsp?

2001-04-05 Thread Daniel Toms

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:

  


  
  
  
   


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