wood burning stoves 2.0*
The moose likes JSP and the fly likes JSTL eq condition Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "JSTL eq condition" Watch "JSTL eq condition" New topic
Author

JSTL eq condition

Aman Singh
Ranch Hand

Joined: Oct 30, 2008
Posts: 57
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



Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61092
    
  66

Your syntax is whacked. You don't nest an EL expression inside another.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Aman Singh
Ranch Hand

Joined: Oct 30, 2008
Posts: 57
whats the fix to make this work Bear?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61092
    
  66

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

Joined: Oct 30, 2008
Posts: 57
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
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61092
    
  66





What was all that extra punctuation about?
Aman Singh
Ranch Hand

Joined: Oct 30, 2008
Posts: 57
I apologize for the trouble. I am still a newbie

Thanks for the syntax, it isnt throwing any erros, but problem still persists
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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

Joined: Oct 30, 2008
Posts: 57
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
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61092
    
  66

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

Joined: Oct 30, 2008
Posts: 57
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
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61092
    
  66

If you have more than one selected option on a dropdown, the HTML is invalid.

There can be only one.
Aman Singh
Ranch Hand

Joined: Oct 30, 2008
Posts: 57
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
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61092
    
  66

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSTL eq condition