• 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

Calling DB onSelectRadio and populating another table in the same JSP page

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

Am new to JSP & Java Script.

I have a following scenario
A table with certain customer Ids, each row has a radio button and on click of it I should populate another table to fetch the customer details (on the same page)

I have declared 2 page level variables in my jsp

<%!
private boolean showtable = false;
private String selectedId = "";
%>

<script type="text/javascript">
function setId(idVal)
{
alert(idVal);
<% selectedId="<script>document.writeln(selectedId)</script>";%>
}
</script>

<form>
<table>
This table has every Id and few meta data and a radio button on each row which calls the java script on click
</table>

<table>
I need to populate this table based on the jsp variable selectedId that is set in the java script.
I call my Java function here passing the parameter ' selectedId' and then filling the table.
</table>

</form>

My problem is I need to call the DB and get the 2nd table details. How do I do it?
Please help me!

Thanks
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Firstly, your JSP knowledge is over 10 years old. Java code hasn't been appropriate to put into a JSP since 2002. Read this JspFaq entry.

Secondly, you'd use Ajax to make a request to the server.
 
Kuppuraj Gunasekaran
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have worked on Struts, Ice faces JSF and many other MVC framework and am pretty much aware of the fact that writing Java code in JSP is bad.
But now am working on a project where only JSP and Java Scripting are being used and not any advanced framework.

In struts, JSF you follow the MVC pattern properly and you can redirect as per your needs but in case of JSP I need to refresh the page or try using Ajax as you say.
I ll try to explore AJAX option which is better than reloading the page.

Thanks
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kuppuraj Gunasekaran wrote:I have worked on Struts, Ice faces JSF and many other MVC framework and am pretty much aware of the fact that writing Java code in JSP is bad.
But now am working on a project where only JSP and Java Scripting are being used and not any advanced framework.


No framework is needed to use JSPs properly. It's no excuse to create shoddy work.
 
Kuppuraj Gunasekaran
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok. So can you brief me about the right approach using JSP?
Or can you point me to some good material that explains the right approach?

Thanks for the Help
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kuppuraj Gunasekaran wrote:Ok. So can you brief me about the right approach using JSP?


No scriptlets. Use the JSTL and EL.

see this article for an article on properly structuring a web app (no framework needed).
 
Kuppuraj Gunasekaran
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks again!

I will go through it and get back in case I have any questions.
 
Kuppuraj Gunasekaran
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I modified my JSP to not have any scriptlets and I tried using jQuery for the asynchronous call, but I am not seeing any call happening to my servlet.

Here is what am doing

My jQuery funcion to make a servlet call to get the data when the radio button is selected




My JSP code





Servlets doGet method






web.xml




Can somebody help me... is something wrong with my code??

Thanks
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you used the browser's debugger to see if the request is being issued or not?
 
Kuppuraj Gunasekaran
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Its not being issued.
I tried putting alert boxes to alert the values I pass.
Even the alert boxes are not popping up. So am very confused.
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Time to set breakpoints and see where the code is going wrong. Is the change handler even called?
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic