Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

another doubt

 
pradeep singh
Ranch Hand
Posts: 339
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which of the following correctly creates an HTML select box on the page?

1. <select name="Cities">
<%for(int i=0; i<cities.size(); i++) {%>
<option>${cities[<%=i%>]}</option>
<%}%>
</select>
.

2. <select name="Cities">
<%for(int i=0; i<cities.size(); i++) {%>
<option>${cities[i]}</option>
<%}%>
</select><br>

3. <select name="Cities">
<%for(int i=0; i<cities.size(); i++) {
<option>${cities[i]}</option>
}%>
</select><br>
4. <select name="Cities">
<%for(int i=0; i<cities.size(); i++) {%>
<option><%=cities.get(i)%></option>
<%}%>
</select>

My question is why option 2 is wrong.Please explain with depth.
Answer is given :4 option


I think that we can not access scripting variables directly through EL.First we must have to add as an attribute in some scope ,then only we can access it.Am i right?



Source is enthuware kit
 
Garlapati Ravi
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My question is why option 2 is wrong.Please explain with depth.
${cities[i]}, interpreter can't find 'cities' in any scope. how do you think it's correct. from where do 'i' gets value from ?
I think that we can not access scripting variables directly through EL

that's correct, that is why above option 2 is wrong.
First we must have to add as an attribute in some scope ,then only we can access it

you yourself had replied to your question.
 
Musab Al-Rawi
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It would help if you use better titles.
[ May 30, 2008: Message edited by: Christophe Verre ]
 
Amol Fuke
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
whats is the difference between option 2 and 3.They looks same to me.
 
Bk Jacky
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Amol,
check the {} brackets in the option 2 & 3.

2.option is outside scriplet <% %>
3. option is inside scriplet <% %>

[ June 05, 2008: Message edited by: Bhupinder Singh ]
 
Amol Fuke
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oops..Thanks Bhupen.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic