Discussion:
[Struts2] "scope" attribute for Action configuration in struts.xml file
Sébastien LABEY
2006-10-11 11:16:06 UTC
Permalink
Hi,

I was used to specify a scope (request or session) for in the action
configuration in struts-config.xml with struts1.x, and I used it to know
where to store some parameters. So my struts-config.xml was like this :
<action path="/login"
type="xxx.xxx.LoginAction"
name="indexForm"
scope="request"
input="/common/index.jsp"
validate="false"
parameter="synthesize">
<forward name="success" path="/common/welcome.jsp"/>
<forward name="failure" path="/common/error.jsp"/>
</action>

But I can't find the "scope" attribute in the DTD for struts.xml in
Struts2... Is it available in a different way or no more available?

Thanks for your answers.

Sebastien
Dave Newton
2006-10-11 11:31:45 UTC
Permalink
Post by Sébastien LABEY
I was used to specify a scope (request or session) for in the action
configuration in struts-config.xml with struts1.x, and I used it to know
where to store some parameters.
My understanding (as a Struts2 n00b) is that since there are no form beans in Struts2 the 'scope' attribute would no longer make sense.

Dave
Sébastien LABEY
2006-10-11 12:17:50 UTC
Permalink
Yes, I understand that, but it can be useful to specify the scope of an
action. For example, you could have to search for a list of objects in DB to
help the user to select the right item (let's imagine there are too much
items to have them in one time on your page), and you would like to save
your actual navigation, so you specify it a scope="session"... With this,
you know where too search for the objects you have save, you simply search
in the scope specified with the action.
So it seems I have to find another solution...
Anyway, thanks for your answer.

Sebastien
Post by Dave Newton
Post by Sébastien LABEY
I was used to specify a scope (request or session) for in the action
configuration in struts-config.xml with struts1.x, and I used it to know
where to store some parameters.
My understanding (as a Struts2 n00b) is that since there are no form beans
in Struts2 the 'scope' attribute would no longer make sense.
Dave
---------------------------------------------------------------------
Ted Husted
2006-10-13 02:03:44 UTC
Permalink
A simple way to do this is to define a Spring bean and then expose
that as an Action property. Struts will automatically inject the
Spring bean into the Action if the Action property name matches the
Spring Bean ID.

* http://jroller.com/page/TedHusted?entry=struts_2_spring_love_fest

As others have mentioned, the scope parameter in Struts 1 refers to
the FormBean, not the Action. All Struts 1 Actions are "application
scope". In Struts 2, any POJO can serve as a "formbean" via Model
Driven, any POJO can be injected into an Action via Spring.

-- HTH, Ted.
* http://www.husted.com/struts/
Post by Sébastien LABEY
Yes, I understand that, but it can be useful to specify the scope of an
action. For example, you could have to search for a list of objects in DB to
help the user to select the right item (let's imagine there are too much
items to have them in one time on your page), and you would like to save
your actual navigation, so you specify it a scope="session"... With this,
you know where too search for the objects you have save, you simply search
in the scope specified with the action.
So it seems I have to find another solution...
Anyway, thanks for your answer.
Sebastien
Post by Dave Newton
Post by Sébastien LABEY
I was used to specify a scope (request or session) for in the action
configuration in struts-config.xml with struts1.x, and I used it to know
where to store some parameters.
My understanding (as a Struts2 n00b) is that since there are no form beans
in Struts2 the 'scope' attribute would no longer make sense.
Dave
Dave Newton
2006-10-11 12:32:05 UTC
Permalink
Post by Sébastien LABEY
Yes, I understand that, but it can be useful to specify the scope of an
action. For example, [...]
I understand what you're saying, but you were never specifying the scope of an action. You could *use* it as that, but that wasn't its original purpose.

IIRC you can set arbitrary params on an action in the struts config via the param element (although so far I am unable to retrieve these params within an interceptor, which is killing me for role-based authentication: if anybody has a canonical answer for this let me know.)

Dave
Don Brown
2006-10-11 20:40:34 UTC
Permalink
It is possible for scoped "forms", when using a ModelDriven action.
Simply implement ScopedModelDriven and use the
ScopedModelDrivenInterceptor to manage the form's scope. See the
Struts 1 example in the showcase, where we use a session-scoped
ActionForm without modifying the code at all. This technique can be
used for any ScopedModelDriven action, not just Struts 1 actions.

Don
Post by Dave Newton
Post by Sébastien LABEY
Yes, I understand that, but it can be useful to specify the scope of an
action. For example, [...]
I understand what you're saying, but you were never specifying the scope of an action. You could *use* it as that, but that wasn't its original purpose.
IIRC you can set arbitrary params on an action in the struts config via the param element (although so far I am unable to retrieve these params within an interceptor, which is killing me for role-based authentication: if anybody has a canonical answer for this let me know.)
Dave
---------------------------------------------------------------------
Loading...