There's no reason it couldn't work in a "helper class", though; you can define arbitrary beans etc. inside the config.
Dave On Sat, Dec 18, 2010 at 3:12 PM, Chris Pratt <[email protected]>wrote: > I assume what you want to do is turn an action name into a URL. Here's > what > I've used before, I'm not sure if there's a better way, but this was > adapted > from code inside struts. You could put it in your action's super class to > make it more reusable, but because of the injection required it wouldn't > really work in a helper class. > (*Chris*) > > /** > * Struts: Inject a flag as to whether Dynamic Method Invocation is > enabled > * > * @param enable "true" to enable > */ > @Inject(StrutsConstants.STRUTS_ENABLE_DYNAMIC_METHOD_INVOCATION) > public void setEnableDynamicMethodInvocation (String enable) { > enableDynamicMethodInvocation = Boolean.parseBoolean(enable); > } //setEnableDynamicMethodInvocation > > /** > * Struts: Inject the Struts Configuration for looking up the proper > Action > * > * @param configuration The Struts Configuration > */ > @Inject > public void setConfiguration (Configuration configuration) { > this.configuration = configuration; > } //setConfiguration > > /** > * Struts: Inject the Action Mapper > * > * @param actionMapper The Action Mapper > */ > @Inject > public void setActionMapper (ActionMapper actionMapper) { > this.actionMapper = actionMapper; > } //setActionMapper > > /** > * Process the Action Attribute > * > * @param ctx The Action Context > * @param stack The Value Stack > * @param action The action attribute value > * @param namespace The namespace attribute value > * @return The action attribute of the generated form > */ > protected String processAction (ActionContext ctx,ValueStack > stack,String action,String namespace) { > HttpServletRequest req = (HttpServletRequest)pageContext.getRequest(); > HttpServletResponse res = > (HttpServletResponse)pageContext.getResponse(); > if(action == null) { > // no action supplied, default to the current request > ActionInvocation invoke = > (ActionInvocation)stack.getContext().get(ActionContext.ACTION_INVOCATION); > if(invoke != null) { > ActionProxy proxy = invoke.getProxy(); > action = proxy.getActionName(); > namespace = proxy.getNamespace(); > } else { > String uri = req.getRequestURI(); > action = uri.substring(uri.lastIndexOf('/')); > } > } > String method = ""; > if(enableDynamicMethodInvocation) { > int bang; > if((bang = action.lastIndexOf('!')) != -1) { > method = action.substring(bang + 1); > action = action.substring(0,bang); > } > } > if(namespace == null) { > namespace = ""; > } > ActionConfig config = > configuration.getRuntimeConfiguration().getActionConfig(namespace,action); > if(config != null) { > return UrlHelper.buildUrl(actionMapper.getUriFromActionMapping(new > ActionMapping(action,namespace,method,null)),req,res,null); > } else if(action != null) { > return UrlHelper.buildUrl(action,req,res,null); > } > return null; > } //processAction > > > > On Fri, Dec 17, 2010 at 1:58 PM, Ken McWilliams <[email protected] > >wrote: > > > I want <s:url> tag like functionality from within my action, so I can > > build a url with parameters so I can return it as a JSON result. > > > > So is there a method I can call from perhaps an AwareInterface that can > > accomplish this? > > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: [email protected] > > For additional commands, e-mail: [email protected] > > > > >

