You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Markus Herrmann <he...@fh-konstanz.de> on 2002/10/09 14:50:12 UTC

How to communicate between JavaBean and Struts ActionForm Bean?

Hello Struts users,

i have a JSP whose form data is stored in an ActionForm bean (as it should be). 
The ActionForm bean sets the form data to default values (e.g. it gets todays 
date). The JSP not only displays the form, but also displays data which comes 
from a DB bean. In the JSP I use the <jsp:useBean> tag to associate the DB bean 
with the JSP. The DB Bean connects to a DB and writes the data into a Vector, 
which is displayed by the JSP using the <logic:iterate> and <bean:write> tags. 
No problems until now.

Now i would like to select the data in the DB bean depending on two propertys 
in the ActionForm Bean. How can my DB bean read propertys from the ActionForm 
bean?

Note that until this point no user intaraction happens. This JSP is the entry 
point of the application. I decided not to post the whole code here, because i 
do not think that this helps to understand and answer my question. Correct me 
if i'm wrong.

Thanks for any help in advance!

Markus Herrmann, Germany


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: How to communicate between JavaBean and Struts ActionForm Bean?

Posted by Will Jaynes <ja...@umich.edu>.
So the form bean is in the session, right. If the db bean is going to be 
able to get at the form then you'll need to pass the session object to 
the db bean, then use the session object's getAttribute method to get 
the form. But you don't want to go there...


Markus Herrmann wrote:
> Will Jaynes <ja...@umich.edu> wrote:
> 
> 
>>Well, if you insist :-) Remember that you can include Java in a JSP, so 
>>after defining your form and the db bean you can write any Java that you 
>>want.
>>
>><jsp:useBean id="myForm" type="myPackage.MyForm"  />
>><jsp:useBean id="dbBean" type="myPackage.DbBean" />
>><%
>>dbBean.setSelectionCriteria( form.getSelectionCriteria() );
>>%>
> 
> 
> :-) Ok, that is the "do all in the jsp"-way. Isn't there a way to read the form 
> bean's propertys directly in my db bean? The form bean is somewhere in my 
> session, right? Or request? Just wondering it it works.
> 
> BTW: I implemented it now using the struts way you mentioned. It works fine.
> 
> Thanks,
> Markus
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: How to communicate between JavaBean and Struts ActionForm Bean?

Posted by Markus Herrmann <he...@fh-konstanz.de>.
Will Jaynes <ja...@umich.edu> wrote:

> Well, if you insist :-) Remember that you can include Java in a JSP, so 
> after defining your form and the db bean you can write any Java that you 
> want.
> 
> <jsp:useBean id="myForm" type="myPackage.MyForm"  />
> <jsp:useBean id="dbBean" type="myPackage.DbBean" />
> <%
> dbBean.setSelectionCriteria( form.getSelectionCriteria() );
> %>

:-) Ok, that is the "do all in the jsp"-way. Isn't there a way to read the form 
bean's propertys directly in my db bean? The form bean is somewhere in my 
session, right? Or request? Just wondering it it works.

BTW: I implemented it now using the struts way you mentioned. It works fine.

Thanks,
Markus


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: How to communicate between JavaBean and Struts ActionForm Bean?

Posted by Will Jaynes <ja...@umich.edu>.
Well, if you insist :-) Remember that you can include Java in a JSP, so 
after defining your form and the db bean you can write any Java that you 
want.

<jsp:useBean id="myForm" type="myPackage.MyForm"  />
<jsp:useBean id="dbBean" type="myPackage.DbBean" />
<%
dbBean.setSelectionCriteria( form.getSelectionCriteria() );
%>

Markus Herrmann wrote:
> On Wed, 09 Oct 2002, Will Jaynes wrote:
> 
> 
>>It seems to me that the problem is that you are trying to do everything 
>>in the JSP without benefit of using an Action. The Action is where this 
>>kind of processing should take place. (Some developers would push it 
>>further, into Business Objects, but they would still be called from the 
>>Action.) In the Action you have access to both the form and your DB bean 
>>and can handle interactions between them.
>>
>>So, I would make the entry point of your application an Action, not just 
>>a JSP.
> 
> 
> Will, thanks for your quick response.
> 
> Ok, that is a good idea. I will try it. You are right: My way is not the
> struts-like way to do it.
> 
> But still: Is there no way to get data out of the FormBean? Somewhere in
> my JVM this FormBean exists, and somehow I should be able to read data from it.
> Or am I wrong?
> 
> 
> 
>>Markus Herrmann wrote:
>>
>>>Hello Struts users,
>>>
>>>i have a JSP whose form data is stored in an ActionForm bean (as it should 
>>
> be). 
> 
>>>The ActionForm bean sets the form data to default values (e.g. it gets 
>>
> todays 
> 
>>>date). The JSP not only displays the form, but also displays data which 
>>
> comes 
> 
>>>from a DB bean. In the JSP I use the <jsp:useBean> tag to associate the DB 
>>
> bean 
> 
>>>with the JSP. The DB Bean connects to a DB and writes the data into a 
>>
> Vector, 
> 
>>>which is displayed by the JSP using the <logic:iterate> and <bean:write> 
>>
> tags. 
> 
>>>No problems until now.
>>>
>>>Now i would like to select the data in the DB bean depending on two 
>>
> propertys 
> 
>>>in the ActionForm Bean. How can my DB bean read propertys from the 
>>
> ActionForm 
> 
>>>bean?
>>>
>>>Note that until this point no user intaraction happens. This JSP is the 
>>
> entry 
> 
>>>point of the application. I decided not to post the whole code here, 
>>
> because i 
> 
>>>do not think that this helps to understand and answer my question. Correct 
>>
> me 
> 
>>>if i'm wrong.
>>>
>>>Thanks for any help in advance!
>>>
>>>Markus Herrmann, Germany
>>>
>>>
>>>--
>>>To unsubscribe, e-mail:   <mailto:struts-user-
>>
> unsubscribe@jakarta.apache.org>
> 
>>>For additional commands, e-mail: <mailto:struts-user-
>>
> help@jakarta.apache.org>
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Re: How to communicate between JavaBean and Struts ActionForm Bean?

Posted by Markus Herrmann <he...@fh-konstanz.de>.
On Wed, 09 Oct 2002, Will Jaynes wrote:

> It seems to me that the problem is that you are trying to do everything 
> in the JSP without benefit of using an Action. The Action is where this 
> kind of processing should take place. (Some developers would push it 
> further, into Business Objects, but they would still be called from the 
> Action.) In the Action you have access to both the form and your DB bean 
> and can handle interactions between them.
> 
> So, I would make the entry point of your application an Action, not just 
> a JSP.

Will, thanks for your quick response.

Ok, that is a good idea. I will try it. You are right: My way is not the
struts-like way to do it.

But still: Is there no way to get data out of the FormBean? Somewhere in
my JVM this FormBean exists, and somehow I should be able to read data from it.
Or am I wrong?


> Markus Herrmann wrote:
> > Hello Struts users,
> > 
> > i have a JSP whose form data is stored in an ActionForm bean (as it should 
be). 
> > The ActionForm bean sets the form data to default values (e.g. it gets 
todays 
> > date). The JSP not only displays the form, but also displays data which 
comes 
> > from a DB bean. In the JSP I use the <jsp:useBean> tag to associate the DB 
bean 
> > with the JSP. The DB Bean connects to a DB and writes the data into a 
Vector, 
> > which is displayed by the JSP using the <logic:iterate> and <bean:write> 
tags. 
> > No problems until now.
> > 
> > Now i would like to select the data in the DB bean depending on two 
propertys 
> > in the ActionForm Bean. How can my DB bean read propertys from the 
ActionForm 
> > bean?
> > 
> > Note that until this point no user intaraction happens. This JSP is the 
entry 
> > point of the application. I decided not to post the whole code here, 
because i 
> > do not think that this helps to understand and answer my question. Correct 
me 
> > if i'm wrong.
> > 
> > Thanks for any help in advance!
> > 
> > Markus Herrmann, Germany
> > 
> > 
> > --
> > To unsubscribe, e-mail:   <mailto:struts-user-
unsubscribe@jakarta.apache.org>
> > For additional commands, e-mail: <mailto:struts-user-
help@jakarta.apache.org>

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


FreeMarker and Struts

Posted by Patria Lukman <lu...@yahoo.ca>.
Hi guys

has anyone used Freemarker and Struts together?
i would appreciate it very much any hint on this.
We're evaluating the possibility of using both
technologies.I used already Struts, but am newbie on
Freemarker...
thanks in advance
Patria


______________________________________________________________________ 
Post your free ad now! http://personals.yahoo.ca

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: How to communicate between JavaBean and Struts ActionForm Bean?

Posted by Will Jaynes <ja...@umich.edu>.
It seems to me that the problem is that you are trying to do everything 
in the JSP without benefit of using an Action. The Action is where this 
kind of processing should take place. (Some developers would push it 
further, into Business Objects, but they would still be called from the 
Action.) In the Action you have access to both the form and your DB bean 
and can handle interactions between them.

So, I would make the entry point of your application an Action, not just 
a JSP.

Will

Markus Herrmann wrote:
> Hello Struts users,
> 
> i have a JSP whose form data is stored in an ActionForm bean (as it should be). 
> The ActionForm bean sets the form data to default values (e.g. it gets todays 
> date). The JSP not only displays the form, but also displays data which comes 
> from a DB bean. In the JSP I use the <jsp:useBean> tag to associate the DB bean 
> with the JSP. The DB Bean connects to a DB and writes the data into a Vector, 
> which is displayed by the JSP using the <logic:iterate> and <bean:write> tags. 
> No problems until now.
> 
> Now i would like to select the data in the DB bean depending on two propertys 
> in the ActionForm Bean. How can my DB bean read propertys from the ActionForm 
> bean?
> 
> Note that until this point no user intaraction happens. This JSP is the entry 
> point of the application. I decided not to post the whole code here, because i 
> do not think that this helps to understand and answer my question. Correct me 
> if i'm wrong.
> 
> Thanks for any help in advance!
> 
> Markus Herrmann, Germany
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>