mercredi 25 avril 2018

JSP Design pattern to handle changes to JAVA enums

We are building a framework Java Spring Controllers that interact with .jsp. The Java Spring Controllers have many enum's. My problem is that I want to access the enum, their values and their ordinals in jsp just like access the in Java.

For my enum

public static enum CurrentPosition {
        ON_TIME, SLIGHT_DELAY, DELAYED, CANCELLED, REACHED, BREAKDOWN
    }

I tried

<%@ page
    import="com.mnox.corporate.controllers.livetracking.TableMetaData.CurrentPosition"%>

This does not give me access to methods like values() or the ordinal.

I also tried JSTL

data.put("currentPositionEnumList", Globals.getEnumStringList(CurrentPosition.class)) ;

But this gives me only access to the enum values, not their ordinals

Finally I am left with writing code like below, to get list of all ride's on a particular enum value. This makes the code not flexible. Everytime I create a new enum, I have to change this code aswell.

private List<Long> listRideTrackingCurrentPositionOnTime, listRideTrackingCurrentPositionSlightDelay, listRideTrackingCurrentPositionDelayed,
            listRideTrackingCurrentPositionReached, listRideTrackingCurrentPositionCancelled, listRideTrackingCurrentPositionBreakdown;

I am new to JSP, is there a technology out there that solves this problem for me. I need complete access of my enum in jsp and html.

Aucun commentaire:

Enregistrer un commentaire