Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2007

Tip: Looking for answers? Try searching our database.

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

Thread view: 
groovyjman21@gmail.com - 23 Apr 2007 23:02 GMT
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.
Richard Senior - 24 Apr 2007 09:01 GMT
> 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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.