Combobox Woes

Thread Solved
Reply

Join Date: Apr 2007
Posts: 5
Reputation: iam_rob is an unknown quantity at this point 
Solved Threads: 0
iam_rob iam_rob is offline Offline
Newbie Poster

Combobox Woes

 
0
  #1
Apr 9th, 2007
Hi there all,

Apologies if something similar has been posted before but I tried a search and couldn't find anything.


I have a combobox with 2 options "OPEN" and "CLOSED".
Tied to this combo box I have a scriptlet which I want to select the appropriate value of the combo box depending on a database value.
I'm currently trying to get it working something like this:

if (incidents.getINC_STATUS() = "OPEN")
<option value="OPEN" Selected="true">
else
<option value="CLOSED" Selected="true">;


I'm still pretty new to java and JSP. I know it won't run the html option value's like that within a scriptlet but I'm not sure how to get around this.

If anyone has any ideas or can see another method, it would be most appreciated.

Kind regards,

Rob.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,145
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Combobox Woes

 
0
  #2
Apr 9th, 2007
well, for one thing you're using an assignment operation where you're probably intending to use a comparison operation.
And that comparison operation would also be incorrect as it's not the way to compare Strings in Java.

  1. <c:choose>
  2. <c:when test="incidents.INC_STATUS == 'open'">
  3. <option value="OPEN" selected="selected"/>
  4. <option value="CLOSED"/>
  5. </c:when>
  6. <c:otherwise>
  7. <option value="OPEN"/>
  8. <option value="CLOSED" selected="selected"/>
  9. </c:otherwise>
  10. </c:choose>

would be a proper way to do it in JSP (though there are some variations on the theme, like determining whether to set an option to true in that option, which is the best way if the number of options gets to be more than two or three).
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 5
Reputation: iam_rob is an unknown quantity at this point 
Solved Threads: 0
iam_rob iam_rob is offline Offline
Newbie Poster

Re: Combobox Woes

 
0
  #3
Apr 9th, 2007
Thanks jwenting for your reply. However I don't think i'm managing to implement your code corrctly. I've tried numerous times and methods but <c:choose> is always reported as "element choose not expected" so when run, currently the combo box presents 4 blank options. I've tried naming them too e.g.
  1. <option value="OPEN" selected="selected">OPEN</option>
but again I get presented by 4 options: OPEN, CLOSE, OPEN, CLOSE
This is how I have incorporated it currently:
  1. <td>
  2. <select size="1" name="INC_STATUS">
  3. <c:choose>
  4. <c:when test="incidents.INC_STATUS == 'OPEN'">
  5. <option value="OPEN" selected="selected">
  6. <option value="CLOSED"/>
  7. </c:when>
  8. <c:otherwise>
  9. <option value="OPEN"/>
  10. <option value="CLOSED" selected="selected">
  11. </c:otherwise>
  12. </c:choose>
  13. </select>
  14. </td>
If you could shed any light on where i'm making mistakes that would be great. As I said before I'm very new to this so I could be making some very stupid mistake!

Thanks,
Rob.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,145
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Combobox Woes

 
0
  #4
Apr 10th, 2007
You will need to add the correct declarations to the top of your JSP to enable JSTL.
That will have to be accompanied by a correctly versioned web.xml in order to get the servlet container to initialise support for JSTL correctly.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 5
Reputation: iam_rob is an unknown quantity at this point 
Solved Threads: 0
iam_rob iam_rob is offline Offline
Newbie Poster

Re: Combobox Woes

 
0
  #5
Apr 10th, 2007
Thanks for that jwenting, I have imported the JSTL library and now it appears to be working fine (except it doesnt seem to like the comparison- something i need to look into with my db i think)

Had to look around as i wasn't sure how to import it but as I say managed to do it in the end.

Thanks for your help
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the JSP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC