• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JSTL eq condition

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.



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



this condition is causing the trouble for me



 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your syntax is whacked. You don't nest an EL expression inside another.
 
Aman Singh
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
whats the fix to make this work Bear?
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Fix your syntax. You never need to nest ${} inside another ${}.

It's not a "fetch operator" -- it encloses the entire EL expression.
 
Aman Singh
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am sorry bear, I am confused here. if I take out ${application} from

<c:if test="${transaction eq '${application}'}">

then how would I do the comparison?
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator




What was all that extra punctuation about?
 
Aman Singh
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I apologize for the trouble. I am still a newbie

Thanks for the syntax, it isnt throwing any erros, but problem still persists
 
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So you think that A should equal B, but in your code, A doesn't equal B? Then the next step would be to look at A and B and see for yourself why they are different.
 
Aman Singh
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Paul,

Thats not the problem. Lets say, if I picked CCC from the dropdown, so this will trigger the form to submit, which in turn returns some data back on the page. After this refresh, I want the same CCC value to be highlighted in the dropdown.
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's his point.

If selected appears, the option will be selected. Did you check the HTML being sent to the browser? Is the attribute in the right place? If not, why not?

Start learning to debug.
 
Aman Singh
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I apologize Paul. I didnt get, what you meant earlier.

Bear, I am trying to debug. I just checked the HTML, it is being passed perfectly.

One thing I didnt mention before.

There is one option which is hardcorded in the HTML.

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

and this is the one its always defaulting too.
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you have more than one selected option on a dropdown, the HTML is invalid.

There can be only one.
 
Aman Singh
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Bear.

HTML is flawed then. None of the option is showing selected.

Now the question, why? I have the exact same condition on another page and it works fine, only difference, dropdown in hardcoded there and in this case if generated from a loop.
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the HTML is invalid, you cannot predict the outcome.

I'd fix the other location too or it's likely to stop working at the least opportune time.
 
He repaced his skull with glass. So you can see his brain. Kinda like this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic