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

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

  1. groovyjman21

    groovyjman21 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.
     
    groovyjman21, Apr 23, 2007
    #1
    1. Advertisements

  2. 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. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.