We help IT Professionals succeed at work.
Get Started

JSTL condition

aman0711
aman0711 asked
on
1,262 Views
Last Modified: 2013-11-24
Hello,

I have a dropdown which is being populated from an arraylist using JSTL.
There is an onchange event on this dropdown, which submits the form to the
server and returns the results.
Everything works fine, except for:
* When the page refreshs after onchange even triggers form submission, There
drop down value isnt restored. It basically defaults to the top one.

For example, if the dropdown has three options: AAA, BBB, CCC
and I pick BBB (which will submit the form with value BBB), Now on the refreshed page
I should see BBB as the dropdown value, where as its showing me AAA.

Below line of code will work fine, if I have the value hardcoded.

<option value="<c:out value='AAA'/>" ><c:if test="${transaction eq 'AAA'}"> selected='selected'</c:if>  ><c:out value='AAA'/></option>  

How do I achieve the same when dropdown is populated with a for loop.

# <c:forEach var="application" items="${applications}">  
#      <option value="<c:out value='${application}'/>" ><c:if test="${transaction eq '${application}'}"> selected='selected'</c:if>  ><c:out value='${application}'/></option>  
#   </c:forEach>  


this condition is causing the trouble for me

<c:if test="${transaction eq '${application}'}">  
Comment
Watch Question
Commented:
This problem has been solved!
Unlock 1 Answer and 21 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE