Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Not able set the different values for the html:option using EL

 
akkina sathish
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi look at my sample code jsp.

<html:select property="dd" >
<c:forEach items="${students}" var="student">
<html ption value="${student.RollNo}">${student.Name}</html ption>
</c:forEach>
</html:select>

Only for the selected option value is not generating properly

see the generated servlet code:

<select name="dd" ">
<option value=" ">Name1</option>

<option value="11">Name2</option>

<option value="26">Name3</option>

<option value="51">Name4</option>
</select>

Why only for the first option it is saving as empty string
Other students (options) have proper student numbers.?.

Can anyone suggest some solution for this problem? Or Give any other way to do, I want to set roll nmbers as their option values.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One way to do it would be to remove the c:forEach tag and use the htmlptionsCollection tag. Example:

I also noticed that your properties start with upper-case letters, which goes against the JavaBean convention. The property "rollNo" causes Struts to call the method "getRollNo".
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic