About Struts 2 params and prepare interceptors

5 messages Options
Embed this post
Permalink
Dhanakumar

About Struts 2 params and prepare interceptors

Reply Threaded More More options
Print post
Permalink
Hi Matt,

in struts.xml, i can see the order of interceptor references, like as follows
...
<interceptor-ref name="prepare" />
<interceptor-ref name="params" />
...
in prepare method, my code is
public void prepare() {
          if(null != getRequest.getParameter("id")) {
                  Employee = employeeManager.get(Long.parseLong(getRequest.getParameter("id"));
          }
}

if i change the order of interceptors to be called, such as follows.
<interceptor-ref name="params" />
<interceptor-ref name="prepare" />

First params interceptor is called and then prepare interceptor.

Then my code in prepare method would be simple,like as follows.

public void prepare() {
          if(null != id) {
                  Employee = employeeManager.get(id);
          }
}

because of params interceptor, setter methods fo request parameters are called, and hence I am able to check for null of id.

Is this the Good approach to change the interceptors order in struts.xml ?

Thanks,
Dhana kumar Anem.
Kannan Ekanath

Re: About Struts 2 params and prepare interceptors

Reply Threaded More More options
Print post
Permalink
Dhanakumar,
1) Struts offers various sets of interceptors. One of them must be params-prepare-params (params is called twice). For these requests in question you could use that interceptor stack.
2) It is not advisable to change the struts.xml for standard interceptor sets. Instead create another stack "my-stack" and change whatever you want with it :) 

Helps?

2009/7/6 Dhanakumar <[hidden email]>

Hi Matt,

in struts.xml, i can see the order of interceptor references, like as
follows
...
<interceptor-ref name="prepare" />
<interceptor-ref name="params" />
...
in prepare method, my code is
public void prepare() {
         if(null != getRequest.getParameter("id")) {
                 Employee =
employeeManager.get(Long.parseLong(getRequest.getParameter("id"));
         }
}

if i change the order of interceptors to be called, such as follows.
<interceptor-ref name="params" />
<interceptor-ref name="prepare" />

First params interceptor is called and then prepare interceptor.

Then my code in prepare method would be simple,like as follows.

public void prepare() {
         if(null != id) {
                 Employee = employeeManager.get(id);
         }
}

because of params interceptor, setter methods fo request parameters are
called, and hence I am able to check for null of id.

Is this the Good approach to change the interceptors order in struts.xml ?

Thanks,
Dhana kumar Anem.

--
View this message in context: http://www.nabble.com/About-Struts-2-params-and-prepare-interceptors-tp24353771s2369p24353771.html
Sent from the AppFuse - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]




--
Regards,
Kannan Ekanath
Kannan Ekanath

Re: About Struts 2 params and prepare interceptors

Reply Threaded More More options
Print post
Permalink
FWIW, these are all specific Struts 2 issues and not appfuse issues per se. So you are better off asking in Struts 2 mailing lists?

2009/7/6 Kannan Ekanath <[hidden email]>
Dhanakumar,
1) Struts offers various sets of interceptors. One of them must be params-prepare-params (params is called twice). For these requests in question you could use that interceptor stack.
2) It is not advisable to change the struts.xml for standard interceptor sets. Instead create another stack "my-stack" and change whatever you want with it :) 

Helps?

2009/7/6 Dhanakumar <[hidden email]>


Hi Matt,

in struts.xml, i can see the order of interceptor references, like as
follows
...
<interceptor-ref name="prepare" />
<interceptor-ref name="params" />
...
in prepare method, my code is
public void prepare() {
         if(null != getRequest.getParameter("id")) {
                 Employee =
employeeManager.get(Long.parseLong(getRequest.getParameter("id"));
         }
}

if i change the order of interceptors to be called, such as follows.
<interceptor-ref name="params" />
<interceptor-ref name="prepare" />

First params interceptor is called and then prepare interceptor.

Then my code in prepare method would be simple,like as follows.

public void prepare() {
         if(null != id) {
                 Employee = employeeManager.get(id);
         }
}

because of params interceptor, setter methods fo request parameters are
called, and hence I am able to check for null of id.

Is this the Good approach to change the interceptors order in struts.xml ?

Thanks,
Dhana kumar Anem.

--
View this message in context: http://www.nabble.com/About-Struts-2-params-and-prepare-interceptors-tp24353771s2369p24353771.html
Sent from the AppFuse - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]




--
Regards,
Kannan Ekanath



--
Regards,
Kannan Ekanath
Dhanakumar

Re: About Struts 2 params and prepare interceptors

Reply Threaded More More options
Print post
Permalink
In reply to this post by Kannan Ekanath
Thanks Kannan Ekanath,

The issue is, in AppFuse struts 2.0,
default package extends struts-default
My requirment is, it would be nice if params interceptor is just before the prepare interceptor. to make condition check in prepare method easier.

when I look on struts-default.xml, there is the correct order as I required.i.e., params-prepare.

I realized from your post, that creating a new stack is a very good idea. for example, I can use MenuInterceptor in the new interceptor stack.

Thanks for your reply.

Kannan Ekanath wrote:
Dhanakumar,1) Struts offers various sets of interceptors. One of them must
be params-prepare-params (params is called twice). For these requests in
question you could use that interceptor stack.
2) It is not advisable to change the struts.xml for standard interceptor
sets. Instead create another stack "my-stack" and change whatever you want
with it :)

Helps?

2009/7/6 Dhanakumar <dhana.anem@gmail.com>

>
> Hi Matt,
>
> in struts.xml, i can see the order of interceptor references, like as
> follows
> ...
> <interceptor-ref name="prepare" />
> <interceptor-ref name="params" />
> ...
> in prepare method, my code is
> public void prepare() {
>          if(null != getRequest.getParameter("id")) {
>                  Employee =
> employeeManager.get(Long.parseLong(getRequest.getParameter("id"));
>          }
> }
>
> if i change the order of interceptors to be called, such as follows.
> <interceptor-ref name="params" />
> <interceptor-ref name="prepare" />
>
> First params interceptor is called and then prepare interceptor.
>
> Then my code in prepare method would be simple,like as follows.
>
> public void prepare() {
>          if(null != id) {
>                  Employee = employeeManager.get(id);
>          }
> }
>
> because of params interceptor, setter methods fo request parameters are
> called, and hence I am able to check for null of id.
>
> Is this the Good approach to change the interceptors order in struts.xml ?
>
> Thanks,
> Dhana kumar Anem.
>
> --
> View this message in context:
> http://www.nabble.com/About-Struts-2-params-and-prepare-interceptors-tp24353771s2369p24353771.html
> Sent from the AppFuse - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@appfuse.dev.java.net
> For additional commands, e-mail: users-help@appfuse.dev.java.net
>
>


--
Regards,
Kannan Ekanath
mraible

Re: About Struts 2 params and prepare interceptors

Reply Threaded More More options
Print post
Permalink
If you think this is a bug, please enter an issue in JIRA.


Thanks,

Matt

On Mon, Jul 6, 2009 at 5:54 AM, Dhanakumar <[hidden email]> wrote:

Thanks Kannan Ekanath,

The issue is, in AppFuse struts 2.0,
default package extends struts-default
My requirment is, it would be nice if params interceptor is just before the
prepare interceptor. to make condition check in prepare method easier.

when I look on struts-default.xml, there is the correct order as I
required.i.e., params-prepare.

I realized from your post, that creating a new stack is a very good idea.
for example, I can use MenuInterceptor in the new interceptor stack.

Thanks for your reply.


Kannan Ekanath wrote:
>
> Dhanakumar,1) Struts offers various sets of interceptors. One of them must
> be params-prepare-params (params is called twice). For these requests in
> question you could use that interceptor stack.
> 2) It is not advisable to change the struts.xml for standard interceptor
> sets. Instead create another stack "my-stack" and change whatever you want
> with it :)
>
> Helps?
>
> 2009/7/6 Dhanakumar <[hidden email]>
>
>>
>> Hi Matt,
>>
>> in struts.xml, i can see the order of interceptor references, like as
>> follows
>> ...
>> <interceptor-ref name="prepare" />
>> <interceptor-ref name="params" />
>> ...
>> in prepare method, my code is
>> public void prepare() {
>>          if(null != getRequest.getParameter("id")) {
>>                  Employee =
>> employeeManager.get(Long.parseLong(getRequest.getParameter("id"));
>>          }
>> }
>>
>> if i change the order of interceptors to be called, such as follows.
>> <interceptor-ref name="params" />
>> <interceptor-ref name="prepare" />
>>
>> First params interceptor is called and then prepare interceptor.
>>
>> Then my code in prepare method would be simple,like as follows.
>>
>> public void prepare() {
>>          if(null != id) {
>>                  Employee = employeeManager.get(id);
>>          }
>> }
>>
>> because of params interceptor, setter methods fo request parameters are
>> called, and hence I am able to check for null of id.
>>
>> Is this the Good approach to change the interceptors order in struts.xml
>> ?
>>
>> Thanks,
>> Dhana kumar Anem.
>>
>> --
>> View this message in context:
>> http://www.nabble.com/About-Struts-2-params-and-prepare-interceptors-tp24353771s2369p24353771.html
>> Sent from the AppFuse - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>>
>
>
> --
> Regards,
> Kannan Ekanath
>
>

--
View this message in context: http://www.nabble.com/About-Struts-2-params-and-prepare-interceptors-tp24353771s2369p24354096.html
Sent from the AppFuse - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]