You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by j alex <st...@gmail.com> on 2008/02/03 03:47:44 UTC

S2 : Checking constants within JSP

Hi,

What's the best way to check constants in jsp using the s:if tag.

I've constants defined in a file like :

public class AppConstants {

    public static final String APPLICATION_CODE = "MYAPP";

    public static final String APPLICATION_VERSION = "1.2";

Now, in the JSP we need to use these constants within an s:if

Currently, i'm using

<s:if test="myapp.appCode == @com.abc.util.AppConstants@APPLICATION_CODE">


but this doesn't look clean ; is there a way to get rid of the @
com.abc.util.AppConstants import ?

Thanks,
Joseph

Re: S2 : Checking constants within JSP

Posted by Dave Newton <ne...@yahoo.com>.
--- j alex <st...@gmail.com> wrote:
> I assume it won't have any performance impact . Please confirm?

Won't have *any* performance impact? That doesn't seem possible; most any
time you're using a tag you're going to have some overhead. Scriptlets are
compiled directly into the servlet, tags make method calls.

*Significant* impact? Not likely, but you'd have to test it with your
specific use cases to know for sure, I suppose.

Dave


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


Re: S2 : Checking constants within JSP

Posted by j alex <st...@gmail.com>.
Thanks Dave, with just scriptlets we could do it with a single page import
on top
<%@ page
language="java"
contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"
import="com.abc.utils.AffinityConstants"

and in scriptlet as:

  <%   if(((AppConstants.APPLICATION_CODE.equals(appCode))  {%>

In S2, we are avoiding scriptlets as much as possible, and using S2 tags and
the @ format seemed a little repetitive when there are a bunch of checks in
the JSP . I assume it won't have any performance impact . Please confirm?



On Feb 2, 2008 9:57 PM, Dave Newton <ne...@yahoo.com> wrote:

> --- j alex <st...@gmail.com> wrote:
> > <s:if test="myapp.appCode == @com.abc.util.AppConstants@APPLICATION
> _CODE">
> >
> > but this doesn't look clean ; is there a way to get rid of the @
> > com.abc.util.AppConstants [import?]
>
> No; that's how OGNL accesses static data (and it's much cleaner than the
> way
> we have to do it with JSP 2.0, IIRC).
>
> Another option is to expose a static property by setting an action
> property
> to the static value, but IMO that's more trouble than it's worth.
>
> Dave
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: S2 : Checking constants within JSP

Posted by Dave Newton <ne...@yahoo.com>.
--- j alex <st...@gmail.com> wrote:
> <s:if test="myapp.appCode == @com.abc.util.AppConstants@APPLICATION_CODE">
> 
> but this doesn't look clean ; is there a way to get rid of the @
> com.abc.util.AppConstants [import?]

No; that's how OGNL accesses static data (and it's much cleaner than the way
we have to do it with JSP 2.0, IIRC).

Another option is to expose a static property by setting an action property
to the static value, but IMO that's more trouble than it's worth.

Dave



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