0

I have a list populated from my xml. This contains set of values say A,B,C,D and E. I am using this list to come up in my drop down menu in the JSP. Is there anyway where in i can make only A,B,C and D populate in the drop down and not 'E' without modifying the xml?

  <% List services = AccountingCRCWrapper.getInstance().getServicesList();%>
            <td width="60%"class="value">
            <select name ="service"  id="service">
            <%if (services!=null && services.size()>0){
                 LabelValueBean service = null;
                 String value = "";
                 String text   = "";

                    for (int i=0; i<services.size(); i++){

                        String Selected = "";
                        service = (LabelValueBean)services.get(i);
                         value  = service.getLabel();
                         text   = service.getValue();
                         if (value.equalsIgnoreCase(AccountingConstants.IWF_SERVICE)){
                            Selected = "selected";
                         }
                            if(value.equalsIgnoreCase("b2b_analytics_si"){
                                continue;
                            }

                %>
            <option value="<%=value%>" <%=Selected%> ><%=text%></option>
            <%} }%>
            </select>
            </td>
          </tr>

2 Answers2

0

For a note, Scriptlet tag in jsp file is discouraged. See BalusC Answer - How to avoid Java code in JSP files?

You should add one more if condition before displaying the options

<% if(!value.equalsIgnoreCase("value_to_be_hide"){%>
     <option value="<%=value%>" <%=Selected%> ><%=text%></option>
<%}%>
Community
  • 1
  • 1
Vinoth Krishnan
  • 2,925
  • 6
  • 29
  • 34
0

you can hide any rows using C:if tag available in core library

Here is the example code:

<form:select path="comboBox">
    <form:option value="-1">&nbsp;</form:option>
    <c:forEach var="val" begin="1" end="12">
        <c:if test="${val < 10}">
            <c:set var="val" value="0${val}"></c:set>
        </c:if>
        <form:option value="${val}">${val}</form:option>
    </c:forEach>
</form:select>
Mallikarjuna Reddy
  • 1,212
  • 2
  • 20
  • 33