Hi.
How can I use utilities classes inside JSPs?
For instance, currently I'm using:
s:if test=#session.USER == null
for asking if user is in session, but I wan to use a Java method instead.
One option is defining a basic Action class and make all action extend it, but
in some cases I
Enable static method access:
constant name=struts.ognl.allowStaticMethodAccess value=true/
Then use OGNL's static method notation [1]:
s:if test=%{@Util@isUserInSession()}
Dave
[1]
http://struts.apache.org/release/2.3.x/docs/ognl-basics.html#OGNLBasics-Accessingstaticproperties
On
Thank you.
Is it discouraged or is it considered a bad practice to use static code in
OGNL? It is disallowed by default.
Actually, the code would be something like:
s:if test=%{@com.company.project.package.Util@isUserInSession()}
Do you think it is a better practice to use a base class
If you want to check if the user is in session, I would create for yourself
a BaseAction class which all your Actions extend. In Base Action, expose a
getter to do that calculation. It's sounds like you really have a case
where you want this property on the Value Stack on each invocation.
I use
I don't know if it's *explicitly* a bad practice, but it's pretty easy to
hose things up with arbitrary static method access.
Personally, I wouldn't, and would instead defer things like that to a
custom tag or, as you said, a method in the base class, properly named,
allowing simple getter access
Hello I had the same problem and i have solved this way
you may wish to override this message. You can do this by adding an i18n
key associated with just your action (Action.properties) using the pattern
invalid.fieldvalue.xxx, where xxx is the field name. It was the only way. I
know its too late
6 matches
Mail list logo