jspelequalsandromda

How to compare values in jsp using JSP Expression Language (EL)


I have this check in my jsp:

<logic:equal name="${product.status}" value="${ProductStatuses.SOLD}"> 
   // do something
</logic:equal>

<logic:equal name="${product.status}" value="${ProductStatuses.IN_STOCK}"> 
   // do something else
</logic:equal>

Both checks return true, so obviously something is not OK. The product's status is of type int and here is my ProductStatuses class which is automatically generated by AndroMDA and hence is in a .jar:

public interface ProductStatuses {
    /**
     * @author andromda
     */
    int SOLD = 1;

    /**
     * @author andromda
     */
    int IN_STOCK = 2;

    /**
     * @author andromda
     */
    int N_A = 0;
}

What can be wrong?


Solution

  • Ok, I have a solution. The comparaison in the jsp wasn't good. Here is how it works:

    <logic:equal name="product" property="status" value="<%=String.valueOf(ProductStatuses.SOLD)%>">   
        // do something
    </logic:equal>
    
    <logic:equal name="product" property="status" value="<%=String.valueOf(ProductStatuses.IN_STOCK)%>">   
        // do something else
    </logic:equal>