You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Raquel Pau Fernández <ra...@gmail.com> on 2008/12/07 16:32:53 UTC

JSP tags calling action directives

Hello,

I'm thinking about calling actions code (that perhaps they are not an URL
and then they don't appear in the struts.xml) from JSP pages.
Is it possible? I'd want to separate the workflow (success, error, input,
etc..) from the necessary business logic for rendering a JSP page.

For instance, in more than one page I could need the list of users in
different formats (combobox, lists and so on) and perhaps I don't need to
list them alone as an url 'userList.action'. Therefore I think that creating
the action code, calling them from the JSP,  putting the necessary
parameters from the request or the session (in general from the value
stack), execute it and get the result would be useful. (I don't want to pass
for each interceptor... because it is unnecessary)
The code will be:

<s:necessarytagRepresentation actionClass="package1.package2.userList"
property="userList" />

It's easy using the BeanUtils library, but I am not sure if struts offers me
some util classes to implement it or it is already created...
Comment: It's like the action tag but without declaring it in the
struts.xml.

Any suggestion or advice?

Thanks.

-- 
Raquel Pau

Re: JSP tags calling action directives

Posted by Raquel Pau Fernández <ra...@gmail.com>.
2008/12/8 Dave Newton <ne...@yahoo.com>

> --- On Mon, 12/8/08, Raquel Pau Fernández wrote:
> > Excuse me for insisting, but the problem of using <s:action> is that
> > you need to offer always it as url...
>
> Using Codebehind you don't need to configure it via XML; I don't see any
> practical difference between using URLs or classnames to access an action.


An URL can be accessible from the browser but not a class. Codebehind offers
automatically an URL...but I don't want it.
All is for security reasons...
Is the same reason that you don't have to permit access directly to your
JSPs.. For instance, you only want to show this data under some conditions
(submit an specific form). In order to satisfy it, the people puts the
service call code in the previous action but it produces a dependency
between what do you want to show and what do you need perform under a
submit.


>
> > [...] but also perhaps is necessary pass some request or session
> > parameters to this service and they have not been necessary for the
> > executed action.
>
> Another reason I think it's a bad idea and more trouble than it's worth.


I only need to execute the logic of Params interceptor...or getting all the
parameters and using BeanUtils to put their value to the action.

>
> IIRC the action tag uses the current value stack (which includes the
> request and session maps) for the action being executed, so (if that's
> correct) the only thing you're asking for is the ability to instantiate the
> action based on its classname rather than a URL?


Yes because my action may not be an URL.

>
>
> > Therefore, using Spring or any other IoC framework having
> > Struts2 is unnecessary and you lost a lot of performance [...]
>
> S2 uses (a version of) Guice to do its IoC/DI by default. I also think
> you're over-estimating the performance penalties of Spring (for example).


Anyway, you need to call two java reflections..


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


-- 
Raquel Pau

Re: JSP tags calling action directives

Posted by Dave Newton <ne...@yahoo.com>.
--- On Mon, 12/8/08, Raquel Pau Fernández wrote:
> Excuse me for insisting, but the problem of using <s:action> is that 
> you need to offer always it as url... 

Using Codebehind you don't need to configure it via XML; I don't see any practical difference between using URLs or classnames to access an action.

> [...] but also perhaps is necessary pass some request or session 
> parameters to this service and they have not been necessary for the
> executed action.

Another reason I think it's a bad idea and more trouble than it's worth. 

IIRC the action tag uses the current value stack (which includes the request and session maps) for the action being executed, so (if that's correct) the only thing you're asking for is the ability to instantiate the action based on its classname rather than a URL?

> Therefore, using Spring or any other IoC framework having 
> Struts2 is unnecessary and you lost a lot of performance [...]

S2 uses (a version of) Guice to do its IoC/DI by default. I also think you're over-estimating the performance penalties of Spring (for example).

Dave


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


Re: JSP tags calling action directives

Posted by Raquel Pau Fernández <ra...@gmail.com>.
Dave,

Excuse me for insisting, but the problem of using <s:action> is that you
need to offer always it as url... In other words, 'yes' i need to call a
service from the JSP without an action mapping that serves it and skip the
intermediate layer, but also perhaps is necessary pass some request or
session parameters to this service and they have not been necessary for the
executed action. Any solution?

I would want to insist that with Struts2 (as main difference with Struts1)
you do not need an intermediate layer.. It has become unnecessary because
you have lost the coupling with the kind of communication interface (in this
case HTTP) and you could use your actions for instance, in a swing
application. Therefore, using Spring or any other IoC framework having
Struts2 is unnecessary and you lost a lot of performance because you need to
use reflection twice (one for the action and another one for the service).
In fact, when I used Struts1, I used the commons-chain library to make the
same task as Struts 2 to call the command passing a map with all request and
session parameters. Therefore, in general, only one action class was
necessary in all the configuration, because this default action returns the
result (put by the command) than gives the forward..

Thank you very much

2008/12/8 Dave Newton <ne...@yahoo.com>

> --- On Mon, 12/8/08, Raquel Pau Fernández wrote:
> > I want to call services, but if I put the service in the
> > action, at code level, the action must know(implicitly)
> > what is the following content page.
>
> IMO the action should always be responsible for what's available in the
> view, but that may just be me.
>
> I'm still not sure I like the idea of calling *action* code to get the data
> that you want, though--I think it would be much cleaner to provide a
> mechanism for accessing service instances in the JSP and skip the
> intermediate layer.
>
> > I need to call an action code from a JSP page without
> > becoming it an URL. I've not found that the framework
> > could provide it because always calls an action that
> > must be an URL.
>
> Again, while I don't think this is a good idea, it'd be easy enough to use
> Codebehind and the <s:action...> tag to do this, although there are a few
> potential "gotchas" with the action tag.
>
> > PD: Excuse me for my poor English.
>
> It's better than mine ;)
>
> Dave
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


-- 
Raquel Pau

Re: JSP tags calling action directives

Posted by Dave Newton <ne...@yahoo.com>.
--- On Mon, 12/8/08, Raquel Pau Fernández wrote:
> I want to call services, but if I put the service in the
> action, at code level, the action must know(implicitly) 
> what is the following content page.

IMO the action should always be responsible for what's available in the view, but that may just be me.

I'm still not sure I like the idea of calling *action* code to get the data that you want, though--I think it would be much cleaner to provide a mechanism for accessing service instances in the JSP and skip the intermediate layer.

> I need to call an action code from a JSP page without
> becoming it an URL. I've not found that the framework 
> could provide it because always calls an action that 
> must be an URL.

Again, while I don't think this is a good idea, it'd be easy enough to use Codebehind and the <s:action...> tag to do this, although there are a few potential "gotchas" with the action tag.

> PD: Excuse me for my poor English.

It's better than mine ;)

Dave


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


Re: JSP tags calling action directives

Posted by Raquel Pau Fernández <ra...@gmail.com>.
Yes,

I want to call services, but if I put the service in the action, at code
level, the action must know(implicitly) what is the following content page.
In addition, if an action code has two URL and for each URL has to send
different JSP content, your code must change or yo have to produce redundant
code in other action. It produces that if the workflow changes, your code
changes. You could also produce a chain of actions, but in my expirience, it
produces a bad maintenance because, for instance, you loss the traceability
between the code and the URL. Struts tutorials also says that it could
produce an spagetti code.

Consequently, I think that separating the workflow (actions) and the view
(calling it in some way, the service) is better . (I have solved it in
Struts 1 using a controller (now presented as view preparer) of the tiles
framework).

However, Struts2/Xwork implements the Command pattern without coupling with
the HTTP interface. For this reason, I think that it is unnecessary two
layers because the same framework offers the HTTP presentation/interface
layer, and then the action is a service.

Following these arguments, I need to call an action code from a JSP page
without becoming it an URL. I've not found that the framework could provide
it because always calls an action that must be an URL..

MAIN USE CASES:

-Each action that produces a forward to the same JSP does not need to know
what data is necessary to load for creating the page.
-The action code can be used in any URL without changing the code to show
any JSP.

Thank you in advance.

PD: Excuse me for my poor English.

2008/12/7 Dave Newton <ne...@yahoo.com>

> --- On Sun, 12/7/08, Raquel Pau Fernández wrote:
> > I'm thinking about calling actions code (that perhaps they are not
> > an URL and then they don't appear in the struts.xml) from JSP
> > [...]
> > For instance, in more than one page I could need the list
> > of users in different formats (combobox, lists and so on)
> > and perhaps I don't need to list them alone as an url
> > 'userList.action'.
> > [...]
>
> I'm not entirely sure I understand where you're coming from.
>
> The use-cases you describe sound like services. Service instances can be
> properties of actions, thus exposed to the JSP. Arbitrary methods can be
> called on action properties already.
>
> I'm not saying it's a bad idea, I just don't understand it or, so far, see
> a need for it.
>
> Dave
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


-- 
Raquel Pau

Re: JSP tags calling action directives

Posted by Dave Newton <ne...@yahoo.com>.
--- On Sun, 12/7/08, Raquel Pau Fernández wrote:
> I'm thinking about calling actions code (that perhaps they are not 
> an URL and then they don't appear in the struts.xml) from JSP
> [...]
> For instance, in more than one page I could need the list
> of users in different formats (combobox, lists and so on) 
> and perhaps I don't need to list them alone as an url 
> 'userList.action'.
> [...]

I'm not entirely sure I understand where you're coming from.

The use-cases you describe sound like services. Service instances can be properties of actions, thus exposed to the JSP. Arbitrary methods can be called on action properties already.

I'm not saying it's a bad idea, I just don't understand it or, so far, see a need for it.

Dave


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