Zahary
Zahary

Reputation: 329

Use enum value for validation in JSP

I'm new in java web programming, servlet and also JSTL. What I'm trying to do is how to get value from enum and do some validation in my jsp page using JSTL;

here is my enum

package RenewalVo.common;

public enum RenewalConstant {

    //MODUL_TASK
    MT_REGISTRATION(46),
    MT_DISTRIBUTION(47),
    MT_ACTION_PLAN(70);

    private int constantId;

    private RenewalConstant(int s) {
        constantId = s;
    }        

    public int getConstantCode() {
        return constantId;
    }
}

here is the code in my jsp page let say validationpage.jsp

<c:choose>
    <c:when test="${drafId!=0 }">
        <c:choose>
            <c:when test="${modulTaskId== //here is which i would like to get the enum value for validation}">
                // do something here            
            </c:when>
            <c:when test="${modulTaskId== //here is which i would like to get the enum value for validation}">
                // do something here
            </c:when>
            <c:otherwise>
                //do something here
            </c:otherwise>
        </c:choose>
    </c:when>   
</c:choose>

for draftId and modulTaskId I retrieve from servlet, and forward through RequestDispatcher.

Here is the code in my servlet

request.setAttribute("modulTaskId",modulTaskId);
request.setAttribute("drafId",drafId);
RequestDispatcher view = request.getRequestDispatcher(/validationpage.jsp);                    
view.forward(request, response); 

Hope sumbody can help.

Thank you in advance.

Upvotes: 0

Views: 513

Answers (2)

Alex
Alex

Reputation: 11579

You can create custom JSP tags and then to use something like

<when test="${mytag:isAllowedSomething(modulTaskId)}" >
...
</when>

Upvotes: 0

Łukasz Dumiszewski
Łukasz Dumiszewski

Reputation: 3038

Try this:

<c:when test="${modulTaskId=='MT_REGISTRATION'}">          
</c:when>

(I assume moduleTaskId is an instance of RenewalConstant.MT_REGISTRATION)

Upvotes: 1

Related Questions