struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alberto A. Flores" <>
Subject Re: Runtime Expressions within Tag
Date Mon, 10 Dec 2007 20:13:26 GMT
Thanks Wes,

I understood what you meant in your first reply and I appreciate it. 
However I'm used to doing simple calculations on a JSP (like just adding 
a 1 to a guaranteed numeric value), independent of the Action class. I 
guess this is part of my coding techniques in using non-thread safe 
Struts 1.x Action classes vs the thread-safe nature of Struts 2.x (since 
each action is instantiated per request). I must admit I'm still getting 
used to it and their advantages.

I supposed I took advantage of the weak typing occurred in EL 
expressions. My questions was more oriented in whether such weak typing 
can be achieved using Struts 2.x tags. Adding a property to my action 
seemed like too much of an overhead to my action. My first guess would 
be no, since OGNL is meant to encourage strong typing, but thought of 

In general, I try to keep my JSPs as readable as they can be and adding 
a non-string variable to the JSP by virtue of the Action class didn't 
seem right. Furthermore, it seemed to me like everytime I wanted to do a 
similar computation on the fly, I would need to add a property to my 
action(s) so that i can compute something on a JSP (e.g. looping over a 
collection, etc). But if there is no other way, I'll be adding the 
setter/getter to my Action (I agree with you on the Exception issue).

Thanks for your help!

Wes Wannemacher wrote:
> I don't think you are understanding what I am telling you... When you
> read a parameter directly, it will be a string. It's pretty much the
> same as calling -
> request.getParameter("paramName");
> (
> Since that returns a String, it will be treated like a String. Adding
> a getter to your action will pass it through the converters, etc. so
> that you can treat it like a number. My second suggestion is to do
> some OGNL scripting to convert it, but I would advise to add
> getter/setter to your action since a NumberFormatException can be
> raised (that could be silently swallowed).
> On 12/10/07, Alberto A. Flores <> wrote:
>> Thanks Wes,
>> No offense to this approach, but is this the only way to do additions
>> (and for this matter, any other operations) within a struts2 tag?. This
>> is simply not clean (e.g. adding a property to my action for a counter,
>> etc).
>> Thanks anyway!
>> Alberto
>> Wes Wannemacher wrote:
>>> is going to evaluate as a j.l.String. If your action has
>>> a getter for foo, then just refer to it as "%{foo + 1}", conversely,
>>> if you are feeling confident, you can make a static call to parse it -
>>> "%{@java.lang.Integer@parseInt( +1}"
>>> -Wes
>>> On 12/10/07, Alberto A. Flores <> wrote:
>>>> I'm currently migrating an app from Struts 1.x to 2.x and encounter this
>>>> situation where I was calculating the tabIndex of a JSP on the fly
>>>> (reusable JSP). In struts 1.x this was done using
>>>> <c:set var="tabIndexCount" value="<%= request.getParameter("foo") %>"/>
>>>> ...
>>>> <html-el:text tabIndex="${tabIndexCount + 1}" ... />
>>>> According to the Struts2 documentation, non-string attributes are
>>>> evaluated as expressions, so the following:
>>>> <s:textInput tabIndex=""%{ + 1}/>
>>>> should do the work, but instead the above code is *appending* a 1
>>>> (string concatenation). Am I missing something or this is a bug? Any ideas!
>>>> --
>>>> Alberto A. Flores
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail:
>>>> For additional commands, e-mail:
>> --
>> Alberto A. Flores
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail:
>> For additional commands, e-mail:


Alberto A. Flores

View raw message