0

I am using following code to retain the previous selected value from combo box after page refresh. Please suggest the error in the following code . its working fine when both variable are from jsp but not working in case of comparing ctr1 ==tractor.tractorid;

<%
ArrayList<DozerSelection> tractorInfoList=     (ArrayList<DozerSelection>)request.getAttribute("tractorInfoList");
 int ctr1=1;
 int ctr2=1
%>
 <c:when test="${tractorInfoList.size() != 0}">
 <p style="float:left;">Tractor Name</p><select name="tractor" onChange="search()">
     <c:forEach items="${tractorInfoList}" var="tractor">

 // in this case working fine 
     <option value="${tractor.tractorname}" ${ctr1 ==ctr2  ? 'selected' : ''}>${tractor.tractorname}</option>

 // in this case not working
  <option value="${tractor.tractorname}" ${ctr1 ==tractor.tractorid  ? 'selected' : ''}>${tractor.tractorname}</option>

    </c:forEach>
    </select>
    </c:when>
BalusC
  • 1,040,783
  • 362
  • 3,548
  • 3,513
adesh singh
  • 1,690
  • 9
  • 38
  • 69
  • instead `tractor.tractorid` use `tractorInfoList.tractorid`. – SatyaTNV Sep 21 '15 at 06:26
  • no its not working mr satya – adesh singh Sep 21 '15 at 06:34
  • whats the `tractorid` type. is it having value first? – SatyaTNV Sep 21 '15 at 06:43
  • its integer value either 0 or 1 and its adding the value if i add on option button. – adesh singh Sep 21 '15 at 06:45
  • Get rid of whole `` block. It's not used in any way. Use `` instead. You don't need to copy `tractorInfoList`, EL can already find it all by itself. Just stop using ``. [It's officially discouraged since 2003](http://www.oracle.com/technetwork/articles/javase/code-convention-138726.html). Make sure you're reading right and up to date resources to learn JSP. – BalusC Sep 21 '15 at 07:14

0 Answers0