aspose file tools*
The moose likes JSP and the fly likes Comparing values using JSTL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Comparing values using JSTL" Watch "Comparing values using JSTL" New topic
Author

Comparing values using JSTL

Vic Hood
Ranch Hand

Joined: Jan 05, 2011
Posts: 477

Hi All ,
Im trying to set a value for a dropdown using JSTL, I want to set the value for the dropdown based on the value selected in the previous screen , however it should load the "-1" defualt value when the screen loads for the first time .


When I try running this , I get the error as below .

org.apache.jasper.JasperException: javax.servlet.ServletException: javax.servlet.jsp.JspTagException: Illegal use of <when>-style tag without <choose> as its direct parent
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:491)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:401)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)


Any ideas on how I could implement my logic?
Thanks a lot .


Learning and Learning!-- Java all the way!
Dieter Quickfend
Bartender

Joined: Aug 06, 2010
Posts: 543
    
    4

First of all, putting logic in your JSP is discouraged. It is not proper design.

Secondly, you need to do exactly what the error message says. when and otherwise tags need to be in a choose parent tag. Like this:



Oracle Certified Professional: Java SE 6 Programmer && Oracle Certified Expert: (JEE 6 Web Component Developer && JEE 6 EJB Developer)
Vic Hood
Ranch Hand

Joined: Jan 05, 2011
Posts: 477

I got rid of the error , but its not serving my purpose , Im trying to set the value of the dropdown to retain. However that is not happening , its being set to default value of -1, when the page submits . Any clues as to where I could be going wrong?
Dieter Quickfend
Bartender

Joined: Aug 06, 2010
Posts: 543
    
    4

Are you putting all when/otherwise combo's in their own choose tags?
Vic Hood
Ranch Hand

Joined: Jan 05, 2011
Posts: 477

Yes Dieter ,
Thanks a lot for your reply !
My code doesnt show any runtime errors and this is the corrected version,

My code above seems to be an overkill of a sort . But my status now is that it works perfectly when the screen loads initially and then when I select a value from the dropdown to populate a list which works fine too , but I have a functionality where Im supposed to be able to edit a particular record from the result set, for which I need to send the value selected from the dropdown to the servlet , when I try this functionality im able to pass the valueselected from the dropdown to the backend , but am not being able to display this value in the jsp(as the page submits) .ie. the drop down value is set to the default "--Select-- " value . Any clue as to what I could be missing?
.
Hope Im being clear.
Dieter Quickfend
Bartender

Joined: Aug 06, 2010
Posts: 543
    
    4

Well... the selected attribute of your --Select-- option is unchanged, is it?
Vic Hood
Ranch Hand

Joined: Jan 05, 2011
Posts: 477

Uhh I understand , the well.. Hope I wasnt confusing you completely
. When I click on the edit hyperlink associated to a particular row , the page submits and it is expected to populate the values corresponding to the selected row in the fields . ie . set the value in the dropdown and also populate the fields .
However when I click this edit hyper link, all I see now is a blank form and the dropdown being set to "--Select". Am I being clear enough or should I re- explain . ? .
Dieter Quickfend
Bartender

Joined: Aug 06, 2010
Posts: 543
    
    4

Well I can't really know why without seeing your servlet code, and the resulting JSP... Show your code, and make sure you use XML/java code tags and use correct indentation as well, because your XML is quite annoying to read.
Vic Hood
Ranch Hand

Joined: Jan 05, 2011
Posts: 477

Thanks for replying Dieter!
"your xml is quite annoying" Im sorry , I didnt quite get that .
Any ways , these are my jsp and servlet files.
Servlet .

My Jsp ..POC.jsp


Dieter Quickfend
Bartender

Joined: Aug 06, 2010
Posts: 543
    
    4

Alright. I think you're gonna have to go back to the drawing board for your application.

You've got no separation of concerns in your servlet, which means spaghetti code. One giant method in your servlet, one small setback for the human mind.
You're using instance variables in your servlet, which means none of it's thread safe.

It's time to learn object oriented programming.

And it's also time to learn about the scopes.

Also, don't use DAO's as value objects.
Vic Hood
Ranch Hand

Joined: Jan 05, 2011
Posts: 477

Dieter Quickfend wrote:Alright. I think you're gonna have to go back to the drawing board for your application.

You've got no separation of concerns in your servlet, which means spaghetti code. One giant method in your servlet, one small setback for the human mind.
You're using instance variables in your servlet, which means none of it's thread safe.

It's time to learn object oriented programming.

And it's also time to learn about the scopes.

Also, don't use DAO's as value objects.



Ow! .
Well , I need to solve this app to be working asap .Could you suggest anything I should correct/implement in my code ?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Comparing values using JSTL