Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

selected not setting with listbox  RSS feed

 
Mr.David Shapiro
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the following code. I was expecting when the user selects a hostname that that option would then be set as selected. It never does though. param.hostname is set by the checkbox, so I would expect it to match one of the choices. I put a <c ut value="${param.hostname}" /> between the Hostname  and <select> and validated it is set to one of the drop down options.

Hostname 
<select name="hostname">
<c:forEach var="row" items="${hostname.rows}">
<option value="${row.Hostname}"
${param.hostname "${row.Hostname}" ? "selected" : ""}>
<c ut value="${row.Hostname}" />
</option>
</c:forEach>
</select>

[ May 17, 2006: Message edited by: Mr.David Shapiro ]

[ May 17, 2006: Message edited by: Mr.David Shapiro ]

[ May 17, 2006: Message edited by: Mr.David Shapiro ]
[ May 17, 2006: Message edited by: Mr.David Shapiro ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
${param.hostname "${row.Hostname}" ? "selected" : ""}>



The following page has an example of how to use the ternary operator in EL:
http://java.sun.com/developer/EJTechTips/2004/tt0126.html
[ May 17, 2006: Message edited by: Ben Souther ]
 
Mr.David Shapiro
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, but my ternary use looks the same as the example at that link. I can only presume that param.hostname does not equal any of the row.Hostname values, which I do not understand because param.hostname is set by one of the row.Hostname values. Is this a typecasting issue? Is something different that is not visible?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, but my ternary use looks the same as the example at that link.



???
What comparison operator are you using in the example that you've posted?
In the example from the link, are there nested EL expressions?

Take a closer look.

[ May 17, 2006: Message edited by: Ben Souther ]
 
Mr.David Shapiro
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm, not sure why my posting did not put it, but let's try again without me moving things around to pretty it up:

Hostname 
<select name="hostname">
<c:forEach var="row" items="${sqlhostname.rows}">
<option value="${row.Hostname}" ${param.hostname == "${row.Hostname}" ? "selected" : ""}>
<c ut value="${row.Hostname}" />
</option>
</c:forEach>
</select>
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're still trying to nest expressions:
Look at the example again:
 
Mr.David Shapiro
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have two more selects in the code that do work. The only difference is they do not refer to a sql query row variable like ${row.Hostname}. For example:

Action <select name="action" >
<option value="Add" ${param.action == "Add" ? 'selected' : ''} >Add</option>
<option value="Delete" ${param.action == "Delete" ? 'selected' : ''} >Delete</option>
<option value="Display" ${param.action == "Display" ? 'selected' : ''} >Display</option>
<option value="Modify" ${param.action == "Modify" ? 'selected' : ''} >Modify</option>
</select>
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ben Souther:
You're still trying to nest expressions:

[ May 17, 2006: Message edited by: Ben Souther ]
 
Mr.David Shapiro
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Figured it out:
Changed the option line to not use ${ } around row.Hostname inside of the conditional:

<option value="${row.Hostname}" ${param.hostname == row.Hostname ? "selected" : ""}>
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm glad you've figured it out.
Congrats
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!