0

I am trying to take author information from my database and use it to populate a drop down list in a form for creating books. I have tried:

<select name="authorId">
     <c:forEach items="${dropDownAuthors}" var="items">                                       
          <option value="${items.authorId}">${items.authorName}</option>
     </c:forEach>
</select>

But my drop-down is empty, I did an alert of the drop-down authors and that works fine, I am really confused as what the problem is. edit: ok guys I feel really stupid now, because of your comments I double checked and i forgot the tag libraries which was my only problem and it works fine now.

2 Answers 2

1

If your are using JSF (and you will when you have setup an actual JEE App Webprofile like Version 6 or 7) then you can use the selectOneMenu tag to create a form select field.

Example:

<h:selectOneMenu value="#{user.favCoffee2}">
  <f:selectItems value="#{user.favCoffee2Value}" />
</h:selectOneMenu>

Copied from: http://www.mkyong.com/jsf2/jsf-2-dropdown-box-example/

And make sure that you have registered the namespaces

xmlns:h="http://java.sun.com/jsf/html"

xmlns:f="http://java.sun.com/jsf/core"

Sign up to request clarification or add additional context in comments.

1 Comment

I tried but it didnt work but then i realized i didnt have taglib so now the way i had it works
0

It looks like you really want forTokens here rather than forEach....

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title><c:forTokens> Tag Example</title>
</head>
<body>
<c:forTokens items="Zara,nuha,roshy" delims="," var="name">
   <c:out value="${name}"/><p>
</c:forTokens>
</body>
</html>

From http://www.tutorialspoint.com/jsp/jstl_core_foreach_tag.htm.

2 Comments

I tried but it didnt work but then i realized i didnt have taglib so now the way i had it works
Awesome. Glad my answer helped you :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.