JSP expression language and stripes framework

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

JSP expression language and stripes framework

krick
In a JSP, I can do something like this to display a value from the action bean...

<h2>Hello ${actionBean.person.name} </h2>


I'm trying to figure out how to display alternate text in the jsp if the value from the actionBean is null, but I can't figure out any syntax that works.  I was expecting something like this to work, but that doesn't seem to be the case...


<h2>Hello ${ (actionBean.person.name != null) ? actionBean.person.name : 'valued customer'} </h2>


Is something like this possible, or do I need to write a method in the actionBean that does this logic and returns the appropriate string?

------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users
Reply | Threaded
Open this post in threaded view
|

Re: JSP expression language and stripes framework

Joaquin Valdez-2
I do this using JSTL but I am sure there is a better way:

<c:if test="${actionBean.context.user != null}”>
// do stuff
</c:if>

You could also do this:

<c:choose>
    <c:when test="${actionBean.context.user != null}”>
       // do something...
    </c:when>
    <c:when test="${actionBean.context.user == null}”>
       // do another thing…
    </c:when>
    <c:otherwise>
       // or do something completely different.
    </c:otherwise>
</c:choose>
-Joaquin





On Nov 21, 2014, at 2:12 PM, William Krick <[hidden email]> wrote:

In a JSP, I can do something like this to display a value from the action bean...

<h2>Hello ${actionBean.person.name} </h2>


I'm trying to figure out how to display alternate text in the jsp if the value from the actionBean is null, but I can't figure out any syntax that works.  I was expecting something like this to work, but that doesn't seem to be the case...


<h2>Hello ${ (actionBean.person.name != null) ? actionBean.person.name : 'valued customer'} </h2>


Is something like this possible, or do I need to write a method in the actionBean that does this logic and returns the appropriate string?
------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users


------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users
Reply | Threaded
Open this post in threaded view
|

Re: JSP expression language and stripes framework

Mike McNally-3
In reply to this post by krick
Yes, you can do that. Personally I'd write

    <h2>Hello ${ empty actionBean.person.name ? "valued customer" :
actionBean.person.name }</h2>

Of course you want to prevent XSS attacks too:

    <h2>Hello ${ empty actionBean.person.name ? "valued customer" :
fn:escapeXml(actionBean.person.name) }</h2>


On Fri, Nov 21, 2014 at 4:12 PM, William Krick <[hidden email]> wrote:

> In a JSP, I can do something like this to display a value from the action
> bean...
>
> <h2>Hello ${actionBean.person.name} </h2>
>
>
> I'm trying to figure out how to display alternate text in the jsp if the
> value from the actionBean is null, but I can't figure out any syntax that
> works.  I was expecting something like this to work, but that doesn't seem
> to be the case...
>
>
> <h2>Hello ${ (actionBean.person.name != null) ? actionBean.person.name :
> 'valued customer'} </h2>
>
>
> Is something like this possible, or do I need to write a method in the
> actionBean that does this logic and returns the appropriate string?
>
> ------------------------------------------------------------------------------
> Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
> from Actuate! Instantly Supercharge Your Business Reports and Dashboards
> with Interactivity, Sharing, Native Excel Exports, App Integration & more
> Get technology previously reserved for billion-dollar corporations, FREE
> http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk
> _______________________________________________
> Stripes-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/stripes-users
>



--
Turtle, turtle, on the ground,
Pink and shiny, turn around.

------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users
Reply | Threaded
Open this post in threaded view
|

Re: JSP expression language and stripes framework

krick
In reply to this post by Joaquin Valdez-2
I hadn't thought about using JSTL.

Then I could also do something like this (using "empty" in the test as suggested by Mike McNally)...

<c:out value="${ empty actionBean.person.name ? 'valued customer' : actionBean.person.name }"/>

On Fri, Nov 21, 2014 at 5:38 PM, Joaquin Valdez <[hidden email]> wrote:
I do this using JSTL but I am sure there is a better way:

<c:if test="${actionBean.context.user != null}”>
// do stuff
</c:if>

You could also do this:

<c:choose>
    <c:when test="${actionBean.context.user != null}”>
       // do something...
    </c:when>
    <c:when test="${actionBean.context.user == null}”>
       // do another thing…
    </c:when>
    <c:otherwise>
       // or do something completely different.
    </c:otherwise>
</c:choose>
-Joaquin





On Nov 21, 2014, at 2:12 PM, William Krick <[hidden email]> wrote:

In a JSP, I can do something like this to display a value from the action bean...

<h2>Hello ${actionBean.person.name} </h2>


I'm trying to figure out how to display alternate text in the jsp if the value from the actionBean is null, but I can't figure out any syntax that works.  I was expecting something like this to work, but that doesn't seem to be the case...


<h2>Hello ${ (actionBean.person.name != null) ? actionBean.person.name : 'valued customer'} </h2>


Is something like this possible, or do I need to write a method in the actionBean that does this logic and returns the appropriate string?
------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users


------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users



------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users