• 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

JSP/HTML/Javascript/XML task: Need Consultation

 
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Greetings. I hope I have selected the correct forum to post this thread. If not I'm sure the sheriff will correct my ways.

We've heard the adage: Be carefull what you ask for as you just may get it. Well, its happend to me.

I took a position as a contractor for a large company and now I find myself working on a project whereby I have limited technical experience or it has been several years since I last used the technologies required (see title of this thread for the technologies I am referring to). To make matters worse I have very little time to complete the task. On the good side, I am finally working with the technologies that I've wanted to work with for some time now.

I am writing this thread because I could really use some consultation with my task. Here are the specifics. The task as a whole is quite simple. Picture a completely blank web page. Now split that web page in two vertically down the middle. On the left hand side of this web page will be about twenty something text fields for the user to enter all sorts of numeric and text data. On the right side of the web page there will exist a checkbox treeview control from which the user can click on certain checkboxes. The objective of this web page is to build an XML file which will contain data from all of the entries made on the left hand side of the page and all of the nodes that were selected in the checkbox treeview control on the right hand side of the page. The user simply enters all of the fields on the left hand side of the page and clicks on the desired elements in the checkbox treeview control on the right side of the page that are to be included in the XML file. The user then clicks a "Go" or "Apply" or "Submit" button and the web page will build the XML file and park it in some directory on the server to be used downstream.

Technically, here is what I am doing. The checkbox treeview control is a very nifty one written in Javascript. It provides exactly the service that I need. Within this control there exists code whereby clicking on a link I am delivered selected attributes of the nodes that were clicked on. I need that function. I have allready embedded this checkbox treeview javascript control and mapped out all of the text boxes and buttons on a JSP page. I decided to build this web page as a JSP because I know I can implement the combined HTML code and that javascript checkbox treeview control as well as other javascript code needed to validate all of those enterable text fields, and I can call one or more java classes to build the output XML file, using a JSP.

I hope I've made my task clear as well as my build out strategy. Now here is where I could really use some technical consultation. See that checkbox treeview control needs to be populated before the page is rendered. The data that is to populate that control will come from a web service request. I have never coded a web service request but in my research I see that this can be done using java classes. Ok, so can my JSP page embed some java code that will call a java class that will invoke that web service? I'm thinking that that java class will invoke that web service request which will return some XML data. Then that java class will build a temporary XML file from the data returned from the web service request. This same temporary XML file built by this java class will then be accessed by that javascript checkbox treeview control and populate itself with that data.

So, here are my questions. First, am I on the right track with the technologies I have selected to complete this task? I'm sure you can combine javascript on a JSP page but I am confused about something. When you have a JSP page that includes javascript and embeds calls to java classes what is the sequence whithin which the page renders out? In other words does the web application server build the web page reading commands found in the jsp page from top to bottom? If so, in my JSP page, can I simply embed a java call to my java class that calls the web service to get the data required to populate that treeview control before (or above) the lines of javascript code that populates and displays the checkbox treeview control? Is this OK? If not, or if there is a better, simpler, more efficient way to complete my task then please advise. I am certainly open to alternatives to this approach.

Thank you all for your time in reading this lengthy post and addressing my questions. My humble apologies if this is something that is so elementary. As stated, either I lack the skill or it has been quite some time.

Please help. Gary

 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Holy wall of text batman!

>When you have a JSP page that includes javascript and embeds calls to java classes what is the sequence whithin which the page renders out?

Request is received by server.
All java/jsp code is executed, and emits html/javascript (javascript is just template text at this point)
page is received by client (view source to see what was generated by the jsp)
javascript starts running.

So yes, you can execute java code to call your web service, and then emit javascript to initialize your component correctly.
ie you use java/jsp to create javascript code that will be executed on the client.


It does sound like you are on the right track.
Just remember that javascript code is NOT java code.
javascript can not invoke java code directly - only by making an HTTP request to the server.
You might want to check out this article just for a quick overview.

You will probably want to query your webservice from a servlet. Process the results of that webservice call into a java object of some sort, and then forward it on to your jsp to render. That would be the standard pattern. It depends what your checkbox control on the page is expecting.

 
Sheriff
Posts: 67746
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
Just to emphasize a few of the excellent points that Stefan made to make sure that they are understood:

  • All non-JSP markup in a JSP page is template text. HTML, CSS, and yes, JavaScript, mean nothing to the JSP engine. It might as well be Swahili, or random text created by an iguana walking across the keyboard for all the JSP engine cares.


  • In modern JSPs, there should be no Java code. None. Nada. Zero.


  • Do read the article Stefan linked to. I wrote it, and it will give you a good grounding in what JSP is all about.
     
    Gary Marshall
    Ranch Hand
    Posts: 122
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Thank you Mr. Evans and Mr. Bibeault for your time and your suggestions and comments. And thank you, Mr. Bibeault, for writing that article about JSP pages. Reading that certainly helped me understand the nature of what a JSP page is used for.

    As a reminder, I have to call a web service which will respond with some XML data that I will have to massage a bit and then create an XML file with that data. The XML file must be created and made available for my treeview component on my rendered page. There is JavaScript code that populates that treeview control using the data in that XML file.

    So, now that I know that JavaScript will be the last code to run before the page is rendered in the browser here's what I am thinking: I would create a utility wrapper class that completes the web service call. This utility class will be called by my JSP page. Once the utility class has completed, it will have returned the XML data it obtained via the web service call it executed back to the JSP page. Now the JSP page has the XML data. This XML data has to be made available to the JavaScript code to find when it executes. So this XML data has to be sent down to the browser, since it is at the browser where the JavaScript will run to populate that treeview control.

    It is at this point where my lack of experience really kicks in. How can I do this? How can I make data created on the server using server side code (java, JSP, web service call) available to the JavaScript code that will run on the client? How do I do this? Is there some kind of special area in the HTML/JavaScript page that is available to me where I can store the XML data that the JavaScript code for the treeview control will have access to when it executes? If not, then the treeview JavaScript code will have to open the XML file that will be parked on the server, since that is where the server side code will have to park the file (I believe I read this in another posting in this forum). If that is the case, then can JavaScript code open and read a file on a server, even if it has been granted all the necessary permissions to do so? And if it can, that would seem to cause so much overhead.

    Thank you again for your time and suggestions. Any links you can provide that offer suggested solutions or further learning, of course, is also appreciated.
    Gary
     
    Author and all-around good cowpoke
    Posts: 13078
    6
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    I have to call a web service which will respond with some XML data that I will have to massage a bit and then create an XML file with that data. The XML file must be created and made available for my treeview component on my rendered page. There is JavaScript code that populates that treeview control using the data in that XML file.



    First question: What information do you have on this web service? Is it a SOAP or a RESTful service?

    I would certainly get this web service call/xml creation working as a separate class or set of classes which can be tested outside the servlet/jsp environment

    Bill
     
    Gary Marshall
    Ranch Hand
    Posts: 122
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Bill:

    I believe this will be a SOAP call. I have already created the web service client with the Apache CXF tool (here is the link).

    I agree with you and will be testing this web service client call separately from my JSP page. Before I do I need to get some additional required information from the tech lead and update the "...._Client.java" modules. I hope to have that information by the end of our next business day.

    What is it that you are thinking?

    Thank you for your time.
    Gary
     
    Don't get me started about those stupid light bulbs.
    reply
      Bookmark Topic Watch Topic
    • New Topic