6 Replies Latest reply: Jun 24, 2011 4:38 PM by DrClap RSS

    if statement inconsistency?

      Yay! Another post from me!

      I've got an if statement in a bean that seems to be processing fine when I create a test java class, but doesn't work fine when the bean is invoked by a jsp.

      My code, let me shows you it:

      First, the test class:
      package com.serco.inquire;
      import java.util.*;
      import java.text.*;
      public class TestCollection {
           public static void main(String[] args) {
                IrCollection myCollection = new IrCollection();
                int endpoint = myCollection.getSize();
                for (int i=0;i<endpoint;i++) {
                     InquireRecord curRec = myCollection.getCurRecords(i);
                     Long milis = new Long(curRec.getSubmitDate());
                     Date theDate = new Date(milis);
                     Format formatter = new SimpleDateFormat("dd MMM yyyy");
                     String s = formatter.format(theDate);
                     System.out.println("ID: " + curRec.getID() + " | Subject: " + curRec.getSubject());
      a snippit from the IrCollection class it calls:
      private void processSort(String datum) {
                int LastChar = datum.length()-1;
                String colName = datum.substring(0, LastChar);
                if (datum=="none") {
                     this.fullSort  = " ORDER BY lastUpdated DESC";
                } else {
                     if (datum.endsWith("2")) {
                          this.fullSort = " ORDER BY " + colName + " ASC";
                     } else {
                          this.fullSort = " ORDER BY " + colName + " DESC";
      There's more code in another method that calls this particular method using:
      But the problem is that if (datum=="none") portion in the second code sample. Given that line 10 of the first class sets the member variable sort to "none", that processSort() method should set the member variable fullSort to " ORDER BY lastUpdated DESC"

      And if I use the class in the first sample, it does that.


      I have this custom tag:
      <%@ tag body-content="scriptless" import="com.serco.inquire.*" %>
      <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
      <%@ attribute name="mgr" required="true" %>
      <%@ attribute name="mkind" required="false" %>
      <%@ attribute name="sort" required="false" %>
      <c:if test="${empty mkind}">
        <c:set var="mkind" value="manager" />
      <c:if test="${empty sort}">
        <c:set var="sort" value="none" />
      <jsp:useBean id="irc" scope="page" class="com.serco.inquire.IrCollection">
        <jsp:setProperty name="irc" property="mgrtype" value="${mkind}" />
        <jsp:setProperty name="irc" property="sort" value="${sort}" />
        <jsp:setProperty name="irc" property="mgrid" value="${mgr}" />
      Which the .jsp file invokes with this:
      <c:set var="user" value="none" />    
      <c:set var="sort" value="none" />
        <jsp:attribute name="mgr">${user}</jsp:attribute>
        <jsp:attribute name="mkind">cotr</jsp:attribute>
        <jsp:attribute name="sort">${sort}</jsp:attribute>
      In other words, the exact same data is fed to the IrCollection bean. so I should get the same data, right?

      Except I get this:
      WHERE cotr = 'none' ORDER BY non DESC
      so when Java calls it, it thinks "none" == "none"
      but when jsp calls it, it thinks "none" != "none"