Return-Path: Delivered-To: apmail-struts-user-archive@www.apache.org Received: (qmail 28498 invoked from network); 6 Mar 2008 12:48:30 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 6 Mar 2008 12:48:30 -0000 Received: (qmail 21462 invoked by uid 500); 6 Mar 2008 12:48:17 -0000 Delivered-To: apmail-struts-user-archive@struts.apache.org Received: (qmail 21429 invoked by uid 500); 6 Mar 2008 12:48:17 -0000 Mailing-List: contact user-help@struts.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Struts Users Mailing List" Reply-To: "Struts Users Mailing List" Delivered-To: mailing list user@struts.apache.org Received: (qmail 21418 invoked by uid 99); 6 Mar 2008 12:48:17 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 06 Mar 2008 04:48:17 -0800 X-ASF-Spam-Status: No, hits=1.2 required=10.0 tests=SPF_HELO_PASS,SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: local policy) Received: from [212.227.126.187] (HELO moutng.kundenserver.de) (212.227.126.187) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 06 Mar 2008 12:47:41 +0000 Received: from [192.168.0.234] (host86-153-27-168.range86-153.btcentralplus.com [86.153.27.168]) by mrelayeu.kundenserver.de (node=mrelayeu8) with ESMTP (Nemesis) id 0ML31I-1JXFVl2jnO-0002jY; Thu, 06 Mar 2008 13:47:49 +0100 Message-ID: <47CFE7F5.4040501@cyberspaceroad.com> Date: Thu, 06 Mar 2008 12:47:49 +0000 From: Adam Hardy User-Agent: Icedove 1.5.0.14pre (X11/20080208) MIME-Version: 1.0 To: Struts Users Mailing List Subject: Re: [S2] Writing a simple interceptor that set a properties of the action. References: <866785e40803060406t33caa891lf3677f92701b6d9e@mail.gmail.com> In-Reply-To: <866785e40803060406t33caa891lf3677f92701b6d9e@mail.gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V01U2FsdGVkX19afh2QLAlQ82tVGSVB2945cJhg5BA3TswshWu NE+wGAfxbs8PwheGrIeligyWgCUOc9AepdOT9dvL+lYwbQiOuz oiz/PooU1BDNs35MdIKc+jbjxpsuBCb X-Virus-Checked: Checked by ClamAV on apache.org Unless you want to do it via introspection, then a good way would be to set the appropriate actions to implement an interface having that setter. Then you can use instanceof to see if the action in your interceptor implements your interface. If so, cast it to the interface and call the setter. I think this is generally the way that many S2 interceptors work. For instance, look at ValidationAware in ParametersInterceptor. HTH Adam GF on 06/03/08 12:06, wrote: > I want to do a simple thing, > I have an action like this > > public class MyAction { > private String myVar; > > public setMyVar(String myVar) { > this.myVar = myVar; > } > } > > Inside my Interceptor i want to put in my Action a string inside myVar > property of the Action. > In few words, I need to discover if the Action has that setter, and if > its parameter type is a "String", in this case I would call that > setter. > > I know how to write the interceptor but i don't know how to "try" to > set a property on the action. > > Can you give me any good link? > I tried to watch the source of : StaticParametersInterceptor that > should do something like I have to do. > > It does: > // for actions marked as Parameterizable, pass the static > parameters directly > if (action instanceof Parameterizable) { > ((Parameterizable) action).setParams(parameters); > } > > if (parameters != null) { > final ValueStack stack = ActionContext.getContext().getValueStack(); > > for (Iterator iterator = parameters.entrySet().iterator(); > iterator.hasNext();) { > Map.Entry entry = (Map.Entry) iterator.next(); > stack.setValue(entry.getKey().toString(), entry.getValue()); > Object val = entry.getValue(); > if (parse && val instanceof String) { > val = TextParseUtil.translateVariables((String) val, stack); > } > stack.setValue(entry.getKey().toString(), val); > } > } > > Where does it call the "action setters"? > Thanks > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org > For additional commands, e-mail: user-help@struts.apache.org > > --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@struts.apache.org For additional commands, e-mail: user-help@struts.apache.org