2 Replies Latest reply: Oct 27, 2011 2:36 AM by Hjava RSS

    select box problem

      I have a simple drop down box with the select item out of db
      like if the value in my db is i then the user will see two line of <option value="1">1</option>,
      is that a simple way to handle this problem?
      <select name="year">
                                              <option selected value="${found.year}"> <c:out value="${found.year}"/></option>
                                              <option  value="1">1</option>
                                              <option value="2">2</option>
                                              <option value="3">3</option>
                                              <option value="4">4</option>
                                              <option value="5">5</option>
                                              <option value="6">6</option>
      I don't want to use the method
      <c:if test="${found.year=='1'}">
      <option value="1" selected>1</option>
      <c:if test="${found.year!='1'}">
      <option value="1" >1</option>
      since if the select list is long , like to 100 then the code will turn to every long , should be have a better way , is that right??
        • 1. Re: select box problem
          I try the follow, but the value out of my db never get select , what is wrong in the if condition??
          <%ArrayList<Integer> tyear = new ArrayList<Integer>();
                              for (int i = 1; i <= 10; i++) {
          <select name="year">
                                                  <% for (Integer num : tyear) {
                                                                  String aY = Integer.toString(num);%>
                                                  <c:if test="${found.year==aY}">
                                                      <option selected value="${found.year}"> <c:out value="${found.year}"/></option>
                                                  <c:if test="${found.year!=aY}">
                                                      <option value="<%= aY%>"><% out.println(aY);%></option>
          Edited by: Hjava on Oct 26, 2011 11:27 PM
          The problem on this line , I don't get why is wrong!
          <c:if test="${found.year==aY}">
          • 2. Re: select box problem
            I get it , cause by jsp and JstL have different scoped, haha!!