struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Antonio Sánchez <juntandolin...@gmail.com>
Subject Re: Using Util class inside JSP
Date Wed, 24 Jul 2013 13:04:20 GMT
Thank you both.

In the future, whenever possible, I'll try to put this logic in a base class.

Kind regards. 

El Martes, 23 de julio de 2013 12:59:06 Dave Newton escribió:
> 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 without the parens.
> 
> Dave
> 
> 
> 
> On Tue, Jul 23, 2013 at 12:48 PM, Antonio Sánchez
> <juntandolineas@gmail.com>wrote:
> 
> > 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 whenever possible?
> >
> > <s:if test="%{userInSession()}"> looks simpler.
> >
> >
> >
> > El Martes, 23 de julio de 2013 07:37:17 Dave Newton escribió:
> > > 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 Tue, Jul 23, 2013 at 7:27 AM, Antonio Sánchez
> > > <juntandolineas@gmail.com>wrote:
> > >
> > > > 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 rather prefer something like:
> > > >
> > > > Util.instance().isUserInSession() or
> > > >
> > > > Util.isUserInSession(),
> > > >
> > > > and
> > > >
> > > > <s:if test="isUserInSession()">
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > ---------------------------------------------------------------------
> > > > 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
> >
> >
> 
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message