• Post Reply Bookmark Topic Watch Topic
  • New Topic

JSTL tag to select dropdown value

 
SachinJ Joshi
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have for values in drop down:


When I am getting value = "a" from ProductDefBean, In the dropdown 'A1' should get selected. This is not happening.
Could you please let me know what I need to modify?

Note** When I am doing view Source of my JSP, I am getting value='a'
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no value attribute on a select. That's not how a selected option is specified.

Please look up the proper HTML means to specify which option is to be selected.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
P.S. I'm trying to get the OP to leaner something from the is exercise, please do not post with his answer until he's had a chance to look it up himself.
 
SachinJ Joshi
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:P.S. I'm trying to get the OP to leaner something from the is exercise, please do not post with his answer until he's had a chance to look it up himself.

Here is the updated code:



How to do this using JSTL?
 
SachinJ Joshi
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
SachinJ Joshi wrote:
Bear Bibeault wrote:P.S. I'm trying to get the OP to leaner something from the is exercise, please do not post with his answer until he's had a chance to look it up himself.

Here is the updated code:



How to do this using JSTL?



I modified code as below



In above code for any value coming from back end always A1 is getting selected. even when b its selecting A1.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remember JSP is just a template for creating HTML. If you don't know what HTML you want to create, you can't write a JSP to create it.

So correct, putting the selected attribute on the option to be selected is the right approach.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Btw, you should consistently lowercase your HTML code.
 
SachinJ Joshi
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Btw, you should consistently lowercase your HTML code.

Ok. Will take care.
But my issue is still there...
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you do a View Source at the browser to see the actual HTML? Looking at the JSP markup isn't going to tell you what the browser is seeing.
 
SachinJ Joshi
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Did you do a View Source at the browser to see the actual HTML? Looking at the JSP markup isn't going to tell you what the browser is seeing.

yes. I did view source also.
The value I am getting is either a , b, c or d. However for all values always first value is getting selected in dropdown ie A1.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
SachinJ Joshi wrote:yes. I did view source also.

Keeping it a secret doesn't help us help you.

If the page isn't acting right, there's a good chance that the HTML is wrong. But since you've decided not to show it to us...
 
Paul Clapham
Sheriff
Posts: 21878
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then the way you test that is to display ${ProductDefBean.productCodeDefault} somewhere in your JSP's output. That way you'll know whether "the value I am getting" is the value produced by that expression.
 
SachinJ Joshi
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:Then the way you test that is to display ${ProductDefBean.productCodeDefault} somewhere in your JSP's output. That way you'll know whether "the value I am getting" is the value produced by that expression.


Its a client code so I am not pasting here.
As i said earlier I am getting value for ${ProductDefBean.productCodeDefault} depending upon databse record.
So its eithet a or b or c or d but dropdown is always giving me first values ie A1

it should give me ..
for a --> A1
b --> B1
c --> C1
d --> D1

This is not happening. I guess its JSTL compare issue. Please help.
 
Paul Clapham
Sheriff
Posts: 21878
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
SachinJ Joshi wrote:As i said earlier I am getting value for ${ProductDefBean.productCodeDefault} depending upon databse record.


And as I said earlier

Paul Clapham wrote:Then the way you test that is to display ${ProductDefBean.productCodeDefault} somewhere in your JSP's output. That way you'll know whether "the value I am getting" is the value produced by that expression.
 
SachinJ Joshi
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:
SachinJ Joshi wrote:As i said earlier I am getting value for ${ProductDefBean.productCodeDefault} depending upon databse record.


And as I said earlier

Paul Clapham wrote:Then the way you test that is to display ${ProductDefBean.productCodeDefault} somewhere in your JSP's output. That way you'll know whether "the value I am getting" is the value produced by that expression.


I did below


I could see that I am printing correct values every time.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
SachinJ Joshi wrote:Its a client code so I am not pasting here.

No. You're not.

If the JSTL and EL markup are being sent to the browser, then your app is not configured correctly, and then of course, nothing is going to work right.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!