Ralf Fischer on 21/04/08 18:24, wrote:
On Mon, Apr 21, 2008 at 6:02 PM, Adam Hardy
<[EMAIL PROTECTED]> wrote:
Just had a long search through the struts source and can't see how this is
done.

 I want to obtain the ActionMapper so that I can get the URL for an action,
in the same way that the Form taglib does it:


 ActionMapping mapping = new ActionMapping(action, namespace, actionMethod,
parameters);
 String result =
UrlHelper.buildUrl(actionMapper.getUriFromActionMapping(mapping), request,
response, null);

 It seems to be injected into the Form taglib, but I can't see how or where.

Check out the setter...

    protected ActionMapper actionMapper;

<snip ... />

    @Inject
    public void setActionMapper(ActionMapper mapper) {
        this.actionMapper = mapper;
    }

So if you want your own "Component" to be injected with the
ActionMapper, annotate it to the setter. Your tag which creates the
component bean has to extend the ComponentTagSupport class, or you can
see how it's done in ComponentTagSupport.doStartTag().

Thanks - you made me look at that piece of code for the fourth or fifth time! But seriously, thank you because I looked closer at Container and found I can do this:

ActionMapper actionMapper = container.getInstance(ActionMapper.class);

which may not work perhaps if the actionMapper is the CompositeActionMapper - I'm not too sure, but it works for now and the testing isn't too difficult.

I really didn't want a setter for ActionMapper on the taglib, nor worse yet an annotation to go with it,

I have to say, sounding like an old man which I'm not yet, the insides of Struts/Xwork looks like under the bonnet / hood of some new car and makes me nostalgic for the old machines where everything is obvious. A carburetor was a carburetor. None of this fuel injection malarky!

Regards
Adam

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to