Discussions

Web tier: servlets, JSP, Web frameworks: Struts and comparison of multiple values

  1. Struts and comparison of multiple values (2 messages)

    Hello,

    I have two values I would like to compare to a bean value. How can I impelement this with the struts tag library in stead of inline JSP? Below is an excerpt of my code:
      <code>
        <bean:define id="selectionBean" name="selectionBean" type="SelectionBean" />
        <%
        if(selectionBean.getActiveItem().equals("duplicates") || selectionBean.getActiveItem().equals("noDuplicates")) {
          // Some logic here
        }
        %>
      </code>

    Can this if-test be replaces by Struts tags? The logic:equal tag can, as far as I know, only compare one value in the value-attribute.

    Any input will be appreciated!

    Cheers,
    Kari
  2. Hi Kari,

    you can also use the jstl-TagLibrary like this:<br/>

    <c:if
    test="${selectionBean.activeItem == 'duplicates' || selectionBean.activeItem == 'noDuplicates' }"><br/>
      // Some logic here<br/>
    </c:if><br/>

    <br>In your JSP import define a taglib:<br/>
    <tt><%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %></tt>

    You also need the libraries <code>standard.jar</code> and <code>jstl.jar</code>. <br/>
    Look on the following page for download:<br/>
    http://jakarta.apache.org/taglibs/doc/standard-doc/intro.html<br/>

    Regards<br/>
    Bodo
  3. Hi Bodo,

    Of course, why diden't I think of that? Thank you very much!

    Regards,
    Kari =)