STRUTS/JSTL: Need Match \ Equals tag that compares multiple values

Discussion in 'Java' started by groovyjman21@gmail.com, Apr 23, 2007.

  1. Guest

    Hi all,

    Struts 1.3.8 Websphere 5.1 web app, wondering how to test my
    Customer bean properties in my JSP against multiple values.

    I have a business rule which reads "If (the customer is from AZ,
    CA, MS, NE, or WA), and (either their total sales or total credits are
    greater than zero) then display the following paragraph."

    Pseudocodishly:

    if((customer.state == AZ || customer.state == CA || customer.state ==
    MS || customer.state == NE || customer.state == WA) &&
    (customer.totalsales > 0 || customer.totalcredits > 0){
    showParagraph;
    }

    I can't find an efficient way to do this with struts as the equals and
    match tags only take one value at a time. I have read that JSTL might
    be a way to do this (ie <c:if test = ${...}>) but can't find
    sufficient documentation Any help greatly appreciated.
     
    , Apr 23, 2007
    #1
    1. Advertising

  2. Re: STRUTS/JSTL: Need Match \ Equals tag that compares multiplevalues

    wrote:

    > I have a business rule which reads "If (the customer is from AZ,
    > CA, MS, NE, or WA), and (either their total sales or total credits are
    > greater than zero) then display the following paragraph."

    ....
    > I can't find an efficient way to do this with struts as the equals and
    > match tags only take one value at a time. I have read that JSTL might
    > be a way to do this (ie <c:if test = ${...}>) but can't find
    > sufficient documentation Any help greatly appreciated.


    The nearest you would get would be the choose tag in JSTL. See
    http://java.sun.com/j2ee/1.4/docs/tutorial/doc/JSTL4.html#wp74001

    BUT if this is a business rule, it should be implemented in your
    business layer rather than in your presentation layer.

    Looking at your description I can't see what "location in (AZ, CA, MS,
    NE, WA) and (sales > 0 or credits > 0)" means from a business logic
    point of view. You'd probably comment it in your JSP.

    For the sake of argument, lets say it means it's an "important"
    customer. If you gave your customer bean a method like this:

    public boolean isImportant() {
    return ("AZ".equals(location) || ...
    }

    You get to (a) code your logic in Java, (b) keep your business logic in
    the model where it belongs, (c) re-use your logic elsewhere and (d)
    create a much more readable view:

    <c:if test="${customer.important}">
    ... do something important!
    </c:if>

    Regards,

    Richard
     
    Richard Senior, Apr 24, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Edward A Thompson
    Replies:
    4
    Views:
    532
    Tony Morris
    Feb 11, 2004
  2. =?Utf-8?B?RWQ=?=
    Replies:
    0
    Views:
    3,284
    =?Utf-8?B?RWQ=?=
    Apr 18, 2006
  3. Hole
    Replies:
    3
    Views:
    559
  4. DaFoot
    Replies:
    1
    Views:
    1,697
    DaFoot
    Oct 23, 2008
  5. Replies:
    3
    Views:
    120
    askMe
    Jul 22, 2005
Loading...

Share This Page