• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Comparing values using JSTL

 
Ranch Hand
Posts: 477
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 .

 
Bartender
Posts: 543
4
Netbeans IDE Redhat Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:

 
Vic Hood
Ranch Hand
Posts: 477
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 543
4
Netbeans IDE Redhat Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you putting all when/otherwise combo's in their own choose tags?
 
Vic Hood
Ranch Hand
Posts: 477
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 543
4
Netbeans IDE Redhat Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well... the selected attribute of your --Select-- option is unchanged, is it?
 
Vic Hood
Ranch Hand
Posts: 477
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 543
4
Netbeans IDE Redhat Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 477
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 543
4
Netbeans IDE Redhat Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 477
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ?
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic