| Author |
binding data in portlet jsp using drop down list
|
|
|
| newbie.. sorry..
I have a portlet that contains the following for the view jsp
<% for (Iterator catIter = sessionBean.getCategories().iterator(); catIter.hasNext();) { %>
<% Category cat = (Category) catIter.next(); %>
<% String catName = cat.getName(); %>
<tr>
<td>
<%=catName%>
</td>
</tr>
This lists the categories I have stored on the view in a single column It seems to work...
I was hoping that someone could show me how to create a drop down list that does the same thing.
e.g. <select name="selcat">
option1
option2
option3
</select>
| |
| Jessica Garcia-Glennie 2007-05-16, 1:20 pm |
| You should really consider using JSTL tags for things like this.
Chaper 14: http://java.sun.com/j2ee/1.4/docs/tutorial/doc/
<select name="dropDownList">
<option value="">Please select a category</option>
<c:forEach var="category" items="${sessionScope.categories}">
<option value='<c:out value="${category.name}"/>'>
<c:out value="${category.name}"/>,
</option>
</c:forEach>
</select>
Good luck,
Jaye
| |
|
| thanks jessica.. I certainly need get familiar with JSTL ..
I did get things working .. at least as displaying the list of categories I had available.
<select name="dropDownList">
<option value="">Please select a category</option>
<% for (Iterator categoryIter = sessionBean.getCategories().iterator(); categoryIter.hasNext();) { %>
<% Category category = (Category) categoryIter.next(); %>
<% String catName = category.getName(); %>
<option>
<%=catName %>
</option>
<% } %>
</select>
Now I need to figure out how selecting a category is done and how to associate a list of items for each category
e.g. select a category.. then list the items in that category
<% for (Iterator itemIter = category.getItems().iterator(); itemIter.hasNext();) { %>
<% Item item = (Item)itemIter.next(); %>
<% String itemName = item.getName(); %>
<!-- DISPLAY ITEMS IN TABLE -->
Thanks for you help...
| |
| Jessica Garcia-Glennie 2007-05-17, 7:17 am |
| Honestly, your JSPs will be a lot cleaner and your life a lot more zen if you can spend an hour or two to pull JSTL into your app. In any case, you said that you're a newbie. Have you learned about portlet actions (events) yet? Have a look at the info
center. Whenever a user chooses a category, that should fire an action to populate a list of items that can be put on the request or session and then redisplayed.
Good luck,
Jaye
| |
|
| Hi Jaye...
Yes, you are absolutely right.. I will take a closer look.. Lots of stuff to know...
Thanks for your help.
Mark
|
|
|
|