Results 1 to 12 of 12
  1. #1
    newto is offline Member
    Join Date
    May 2010
    Posts
    17
    Rep Power
    0

    Default populating combo box

    Hi
    I am doing a java program.
    In which I have a jsp page, and on that I have two combobox.
    I have a create a java bean, in which I write a method "result" which return a arraylist.

    I want to populate the combobox by extracting data from database. which I have extarcted from in javabean.

    <select name="day">
    <option value="<%= JdbcQueryBean.result() %>"><%=JdbcQueryBean.result()%></option>
    </select>

    But this command showing all the value in one row, not in the from of list.

    Please help.

    can anyone suggest me some JSTL for this
    Thanks in advance

  2. #2
    tashimoto is offline Member
    Join Date
    Sep 2010
    Location
    Oregon, usa
    Posts
    69
    Rep Power
    0

    Default

    Is your returned value a String?? If it is, you could use the String method .split and create a String Array and then populate your combo box using the array.

    Read here about split method: String (Java Platform SE 6)

    I did something like this to read from a file to populate a combo box:

    Java Code:
    String file = rf.ReadTXT(fileName);
    String[] values = file.split(",");  //uses comma as a delimiter in the file
    comboBox.setModel(new javax.swing.DefaultComboBoxModel(values));
    Hope this helps!
    Chris

    MY APOLOGIES! I missed your reference to JSTL. I am very sorry, I am not familiar with JSTL. Again I am very sorry for responding, and I hope that someone can help you with an answer!
    Last edited by tashimoto; 11-23-2010 at 12:41 AM. Reason: Missed the JSTL reference

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

  4. #4
    newto is offline Member
    Join Date
    May 2010
    Posts
    17
    Rep Power
    0

    Default

    Hi
    I have write a jstl code like this, but still it not displaying the value.

    Java Code:
    <c:forEach var="st" items="<%=JdbcQueryBean.result()%>">
                <option value='<c:out value="${st}"/>'><c:out value="${st}"/></option>
           </c:forEach>
    I have cross checked, that the method result extracting the value properly.

    Please advice

  5. #5
    newto is offline Member
    Join Date
    May 2010
    Posts
    17
    Rep Power
    0

    Default

    Hi sorry, I don't know if it is not allowed to post in two forum

  6. #6
    newto is offline Member
    Join Date
    May 2010
    Posts
    17
    Rep Power
    0

    Default

    Quote Originally Posted by Darryl.Burke View Post
    Hi I agree that I cross posted, as i need that urgently.

    So you please help me now, rather than cursing me

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default

    Corss posting isn't a problem if you inform everyone where else you have posted the question. That way we can avoid duplication of effort. It's about being polite, essentially.

    Is the return value of result() an array or collection of some sort?
    What does it contain?
    What happens with the foreach? "not displaying value" isn't a terribly useful thing to say...what does it do?

  8. #8
    newto is offline Member
    Join Date
    May 2010
    Posts
    17
    Rep Power
    0

    Default

    I am returning an arraylist from the class and providing as a input to the combo box.

    For each doesn't displaying any value in the combo box.
    I am not very know to JSTL, I found that code in net and applied.

    Sorry for if I am not being polite

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default

    OK, so what sort of array list is being returned?
    Are they all Strings?
    If so then that foreach should work, I think.
    So what do you see when you run this?
    Any errors on the tomcat server?

  10. #10
    newto is offline Member
    Join Date
    May 2010
    Posts
    17
    Rep Power
    0

    Default

    Hi,
    thank you all.
    I have solved it

    Java Code:
    <select id="day" name="day" >
    
          <c:forEach var="datItem" items="<%= JdbcQueryBean.result() %>">
    
          <option value='<c:out value="${datItem}" />'>
    
          <c:out value="${datItem}" /></option>
    
          </c:forEach>
    
          </select>

  11. #11
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default

    Was it because you were missing the <select> then?

  12. #12
    newto is offline Member
    Join Date
    May 2010
    Posts
    17
    Rep Power
    0

Similar Threads

  1. Need help: Populating data
    By rahul202 in forum Java Servlet
    Replies: 0
    Last Post: 10-25-2010, 07:16 PM
  2. populating a JList
    By hariza in forum AWT / Swing
    Replies: 2
    Last Post: 09-30-2010, 03:53 AM
  3. Populating a JTable
    By toymachiner62 in forum New To Java
    Replies: 2
    Last Post: 10-13-2009, 05:56 AM
  4. Replies: 11
    Last Post: 02-20-2009, 02:10 AM
  5. creation of one combo box form another combo box
    By er.tyagigaurav in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 12-09-2008, 03:14 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •