| | |
Combobox Woes
Please support our JSP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved
![]() |
•
•
Join Date: Apr 2007
Posts: 5
Reputation:
Solved Threads: 0
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.
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.
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.
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).
And that comparison operation would also be incorrect as it's not the way to compare Strings in Java.
JSP Syntax (Toggle Plain Text)
<c:choose> <c:when test="incidents.INC_STATUS == 'open'"> <option value="OPEN" selected="selected"/> <option value="CLOSED"/> </c:when> <c:otherwise> <option value="OPEN"/> <option value="CLOSED" selected="selected"/> </c:otherwise> </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.
•
•
Join Date: Apr 2007
Posts: 5
Reputation:
Solved Threads: 0
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.
but again I get presented by 4 options: OPEN, CLOSE, OPEN, CLOSE
This is how I have incorporated it currently:
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.
JSP Syntax (Toggle Plain Text)
<option value="OPEN" selected="selected">OPEN</option>
This is how I have incorporated it currently:
JSP Syntax (Toggle Plain Text)
<td> <select size="1" name="INC_STATUS"> <c:choose> <c:when test="incidents.INC_STATUS == 'OPEN'"> <option value="OPEN" selected="selected"> <option value="CLOSED"/> </c:when> <c:otherwise> <option value="OPEN"/> <option value="CLOSED" selected="selected"> </c:otherwise> </c:choose> </select> </td>
Thanks,
Rob.
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.
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.
•
•
Join Date: Apr 2007
Posts: 5
Reputation:
Solved Threads: 0
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
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
![]() |
Similar Threads
- Filling a ComboBox.... (Java)
- ComboBox woes (C#)
Other Threads in the JSP Forum
- Previous Thread: insert data from one form into two diffent database table
- Next Thread: ArrayList is best ,why
| Thread Tools | Search this Thread |
apache backbutton combobox connection database development directorystructure dynamicpagetitles eclipse frames glassfish imagetodatabse imageupload internet java javaee javascript jsf jsp jsppagetitles levels mvc2 mvcmodel2 network parameters passing ping printinserverinsteadofclient redirect request.getparameter response servlet servletdopost()readxml sessions software ssl state_saving_method stocks sun tomcat tutorial video web






