You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Wes Wannemacher <we...@wantii.com> on 2009/09/29 21:11:14 UTC

Re: Struts 2 Custom Tags & Custom Actions

On Tue, Sep 29, 2009 at 4:03 PM, Roger <ro...@googlemail.com> wrote:
> Hi
>
> Apologies for the following, I hope it makes sense.
>
> I'm currently trying to develop a web-app that makes extensive use of
> <s:select> elements in the UI. As I handed coded my n'th jsp implementation of
> the same <select> today I thought I'd break out the tutorials and learn how to
> create a custom tag to do this for me. And that got me thinking ..
>
> What I would like to know is if I can also "attach" a custom action to my
> custom tag to populate the select options, without interfering with the rest
> of the flow? So I would have a self contained "component".  My limited
> understanding of the Struts cycle suggests  that once I'm into result
> processing when my custom tag is processed it's too late to have a new
> "action" on the stack.


Nah, your understanding is wrong here...  You in fact can execute
another action. Although I'm not a fan of it, check out the s:action
tag. It will execute an action (and place it on the stack) while
rendering the result of another action execution.


>
> I know that I could define a BaseAction that extends ActionSupport that my
> action classes extend to provide a method to populate the select options, but
> I'd end up with sub-classed actions that use the populate list method and some
> for which the method would be meaningless, which doesn't feel right, and
> having a BaseAction that is truely used by all actions (ie, setting up
> logging) and then extending again with a BaseActionWithLists seems messy to
> me, particularly when I have lists that are common to many actions, common to
> few actions and   those that are required by a single action.
>
> Of course, I could also have the design of the app horribly wrong ....
>

-Wes

-- 
Wes Wannemacher

Head Engineer, WanTii, Inc.
Need Training? Struts, Spring, Maven, Tomcat...
Ask me for a quote!

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


Re: Struts 2 Custom Tags & Custom Actions

Posted by Roger <ro...@googlemail.com>.
> 
> Another approach would be to populate your select with ajax or just
> use an ajax autocompleter. (just a thought)
> 
> -Wes
> 

OK - this is where I display the true depth of my ignorance - if I use an ajax 
call, how do I do that to an "independent" action?  

Regards
Roger

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


Re: Struts 2 Custom Tags & Custom Actions

Posted by Wes Wannemacher <we...@wantii.com>.
On Tue, Sep 29, 2009 at 4:27 PM, Roger <ro...@googlemail.com> wrote:
>> > What I would like to know is if I can also "attach" a custom action to my
>> > custom tag to populate the select options, without interfering with the
>> > rest of the flow? So I would have a self contained "component".  My
>> > limited understanding of the Struts cycle suggests  that once I'm into
>> > result processing when my custom tag is processed it's too late to have a
>> > new "action" on the stack.
>>
>> Nah, your understanding is wrong here...  You in fact can execute
>> another action. Although I'm not a fan of it, check out the s:action
>> tag. It will execute an action (and place it on the stack) while
>> rendering the result of another action execution.
>>
> Hi Wes
>
> Thanks for the quick response. Given that you're not a fan of the <s:action>
> tag, would you care to elaborate on why, pitfalls etc etc. Am I trying
> something unreasonable here and is there a better way of achieving what I'm
> trying to do.

My problem with s:action is that the implementation has been a buggy
in the past. It seems like it would be a simple task to place another
action invocation on the top of the stack, temporarily, execute it,
then pop it off the stack, but, like I said, it's been buggy in the
past.

Don't take that as a reason not to try it... It seems your use-case is
pretty simple and it is exactly the kind of use it was meant for.

> As an aside, if I do go down the <s:action> route to a custom
> "populate the list" action, what do I return as the result so I don't
> interfere with the flow.

I could be wrong, but isn't there an Action.NONE ? I would try that,
or SUCCESS. As long as you don't set 'executeResult="true"' then it
shouldn't interrupt the flow...

Another approach would be to populate your select with ajax or just
use an ajax autocompleter. (just a thought)

-Wes

-- 
Wes Wannemacher

Head Engineer, WanTii, Inc.
Need Training? Struts, Spring, Maven, Tomcat...
Ask me for a quote!

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


Re: Struts 2 Custom Tags & Custom Actions

Posted by Roger <ro...@googlemail.com>.
> > What I would like to know is if I can also "attach" a custom action to my
> > custom tag to populate the select options, without interfering with the
> > rest of the flow? So I would have a self contained "component".  My
> > limited understanding of the Struts cycle suggests  that once I'm into
> > result processing when my custom tag is processed it's too late to have a
> > new "action" on the stack.
> 
> Nah, your understanding is wrong here...  You in fact can execute
> another action. Although I'm not a fan of it, check out the s:action
> tag. It will execute an action (and place it on the stack) while
> rendering the result of another action execution.
> 
Hi Wes

Thanks for the quick response. Given that you're not a fan of the <s:action> 
tag, would you care to elaborate on why, pitfalls etc etc. Am I trying 
something unreasonable here and is there a better way of achieving what I'm 
trying to do. As an aside, if I do go down the <s:action> route to a custom 
"populate the list" action, what do I return as the result so I don't 
interfere with the flow.

Regards

  

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