You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Marc Gibert Ginestà <ma...@cometatech.com> on 2003/07/17 19:15:32 UTC

Struts + EJB

Hi!

We're starting a project based on Struts with EJBs for the business 
logic and JSPs for the view.

So far, we've successfully coded Actions that call stateful Session EJBs 
that talk to Entity EJBs.

The problem we have is on the view (JSPs). How is the JSP supposed to 
talk to the Session EJB instantiated by the Action class?

One solution we see is to put the instantiated Session EJB in the HTTP 
session and then call its getters from the JSP. This works.

Another solution would be to code a sort of DTO between the Action and 
the EJB so the Action talks to the DTO, the DTO to the EJBs, and then 
the JSP could do a jsp:useBean on the DTO. This seems a lot overkill and 
bloat.

I've seen on some pages talk about some Struts taglibraries specific to 
EJB, but couldn't find them. Would these solve our problems? Where are they?

Is there a better way of doing this?
Has anybody had the same doubt?

Thanks in advance.

-- 
Sincerely,
Marc Gibert Ginestà               e-mail: marcg@cometatech.com
Cometa Technologies, S.L.         URL: http://www.cometatech.com
Telf.: 93 231 84 90               Fax: 93 245 93 43

Re: Struts + EJB

Posted by Erik Price <ep...@ptc.com>.

Marc Gibert Ginestà wrote:
> Hi!
> 
> We're starting a project based on Struts with EJBs for the business 
> logic and JSPs for the view.
> 
> So far, we've successfully coded Actions that call stateful Session EJBs 
> that talk to Entity EJBs.
> 
> The problem we have is on the view (JSPs). How is the JSP supposed to 
> talk to the Session EJB instantiated by the Action class?

<http://java.sun.com/blueprints/corej2eepatterns/Patterns/TransferObject.html>



Erik


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


RE: Struts + EJB

Posted by Varun Garg <va...@yahoo.com>.
You should create a actionform with all the incoming parameters and
whatever values that you might need to pass back.

Then in the action you can check for those values.
Say the ActionForm would contain a property called "category" and you
would have getter and setter for that. Then in the Action instead of
doing request.getParameter("category"); you would just do a
form.getCategory(); and also for outgoing values just create another
property for example if you have a collection that you want to pass to
the jsp page, say the jsp page wants to show a list of something.

You can then create a property in the form for that collection say
"coll" and then in the Action after getting the values from the
SessionEJB set them in the form. Then you can access them on the page
using the standard tags from struts.
form.setColl(lsb.getCollection(form.getCategory());

Varun

-----Original Message-----
From: Marc Gibert Ginestà [mailto:marcg@cometatech.com] 
Sent: Thursday, July 17, 2003 1:04 PM
To: Struts Users Mailing List
Subject: Re: Struts + EJB


Varun Garg wrote:
> I would call the SessionEJB from the actions and copy over the 
> contents that need to be displayed either in the ActionForm or a 
> VO/DTO in the form and then use that to display the information in the

> JSP.
> 
> What is the SessionEJB returning you?? It should be some object 
> serializable and that should be able to fit in the ActionForm.

The sessionEJB could return anything, depending on the method called. 
 From a Collection to a single value. The initial idea was to make 
getters for each value to be seen on the view.

We weren't planning on using ActionForms from the start. At the moment 
we're using URLs to pass parameters, like "showdetails.do?category=3" 
and getting the value of the parameter passed, in the Action with a 
request.getParameter("category");

I like your solution (use the ActionForm), could you provide an example 
of getting the category parameter from it and then add the result values

in the ActionForm?

Thanks in advance.

-- 
Sincerely,
Marc Gibert Ginestà               e-mail: marcg@cometatech.com
Cometa Technologies, S.L.         URL: http://www.cometatech.com
Telf.: 93 231 84 90               Fax: 93 245 93 43



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


Re: Struts + EJB

Posted by Marc Gibert Ginestà <ma...@cometatech.com>.
Varun Garg wrote:
> I would call the SessionEJB from the actions and copy over the contents
> that need to be displayed either in the ActionForm or a VO/DTO in the
> form and then use that to display the information in the JSP.
> 
> What is the SessionEJB returning you?? It should be some object
> serializable and that should be able to fit in the ActionForm.

The sessionEJB could return anything, depending on the method called. 
 From a Collection to a single value. The initial idea was to make 
getters for each value to be seen on the view.

We weren't planning on using ActionForms from the start. At the moment 
we're using URLs to pass parameters, like "showdetails.do?category=3" 
and getting the value of the parameter passed, in the Action with a 
request.getParameter("category");

I like your solution (use the ActionForm), could you provide an example 
of getting the category parameter from it and then add the result values 
in the ActionForm?

Thanks in advance.

-- 
Sincerely,
Marc Gibert Ginestà               e-mail: marcg@cometatech.com
Cometa Technologies, S.L.         URL: http://www.cometatech.com
Telf.: 93 231 84 90               Fax: 93 245 93 43

RE: Struts + EJB

Posted by Varun Garg <va...@yahoo.com>.
I would call the SessionEJB from the actions and copy over the contents
that need to be displayed either in the ActionForm or a VO/DTO in the
form and then use that to display the information in the JSP.

What is the SessionEJB returning you?? It should be some object
serializable and that should be able to fit in the ActionForm.

Varun

-----Original Message-----
From: Marc Gibert Ginestà [mailto:marcg@cometatech.com] 
Sent: Thursday, July 17, 2003 12:16 PM
To: 'Struts Users Mailing List'
Subject: Struts + EJB


Hi!

We're starting a project based on Struts with EJBs for the business 
logic and JSPs for the view.

So far, we've successfully coded Actions that call stateful Session EJBs

that talk to Entity EJBs.

The problem we have is on the view (JSPs). How is the JSP supposed to 
talk to the Session EJB instantiated by the Action class?

One solution we see is to put the instantiated Session EJB in the HTTP 
session and then call its getters from the JSP. This works.

Another solution would be to code a sort of DTO between the Action and 
the EJB so the Action talks to the DTO, the DTO to the EJBs, and then 
the JSP could do a jsp:useBean on the DTO. This seems a lot overkill and

bloat.

I've seen on some pages talk about some Struts taglibraries specific to 
EJB, but couldn't find them. Would these solve our problems? Where are
they?

Is there a better way of doing this?
Has anybody had the same doubt?

Thanks in advance.

-- 
Sincerely,
Marc Gibert Ginestà               e-mail: marcg@cometatech.com
Cometa Technologies, S.L.         URL: http://www.cometatech.com
Telf.: 93 231 84 90               Fax: 93 245 93 43



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