Jump to content

Manipulating Custom JSP Tag


Mixaalser684

Recommended Posts

I have the need to have custom JSP tags in my web application.My custom tag works well when I run the application.Since I use Ajax (Javascript + Servlet + JSON) i tried to create my custom tag as a DIV element child in my Ajax Callback function.I tried using innetHTML method and createElement methods, and none of them works.So, I was wondering is this possible to do (or not) and how if it is?Thank You.

Edited by Codenoobalser
Link to comment
Share on other sites

Do you have a code example to illustrate the problem?
Of course, here is the video clip.

Also, I have tried to create this element in Javascript callback function, but I'm getting DOM error no. 5.I know how to solve my problem (create a function that will hard code HTML elements as string) but I was wondering can this be solved via custom tags (if not then there is no need to use them, and they are really neat if you want to avoid code duplication).If You need some more information I'm at your disposal. Thank You. Edited by Codenoobalser
Link to comment
Share on other sites

The original custom tag gets rendered by JSP as a select element. You're trying to use Javascript to attach the custom tag to the page, but the browser doesn't know what that tag is. You need to have the server return the rendered select element HTML code, not the JSP code. The browser doesn't understand JSP, that runs on the server.

  • Like 1
Link to comment
Share on other sites

The original custom tag gets rendered by JSP as a select element. You're trying to use Javascript to attach the custom tag to the page, but the browser doesn't know what that tag is. You need to have the server return the rendered select element HTML code, not the JSP code. The browser doesn't understand JSP, that runs on the server.
So the custom tags are off then.If the only way is to return the rendered HTML elements (and not custom tags) then I don't need them at all (in their current form).There was one more mechanism, I thought of, that could involve using the custom tags, but in order to use it successfully I need to figure out how to refresh HTML elements without re-submitting the page.Can someone please write a JavaScript code example?I've tried some searching online but no luck.Thank You.
Link to comment
Share on other sites

"Refreshing" an element would mean getting the new markup for it from the server via ajax, and either removing the element from the DOM and adding the new one (or, more specifcally, inserting the new one before or after the old one, then removing the old one), or using innerHTML to replace the content if you're only returning the content and not the entire element. It would be faster to use innerHTML to just replace the content of the element. I don't see a problem with using the custom tags in JSP though, if you send a request to JSP then it should return valid HTML, it shouldn't return the actual JSP code. That's assuming that the request goes through the normal pipeline to convert the JSP tags to valid HTML that the browser will understand. The browser doesn't use or understand your custom tags, those are only used by JSP. Telling the browser to use a custom tag wouldn't have any effect, I'm not sure what you're trying to achieve that you thought that would solve the problem.

Link to comment
Share on other sites

"Refreshing" an element would mean getting the new markup for it from the server via ajax, and either removing the element from the DOM and adding the new one (or, more specifically, inserting the new one before or after the old one, then removing the old one), or using innerHTML to replace the content if you're only returning the content and not the entire element. It would be faster to use innerHTML to just replace the content of the element. I don't see a problem with using the custom tags in JSP though, if you send a request to JSP then it should return valid HTML, it shouldn't return the actual JSP code. That's assuming that the request goes through the normal pipeline to convert the JSP tags to valid HTML that the browser will understand. The browser doesn't use or understand your custom tags, those are only used by JSP. Telling the browser to use a custom tag wouldn't have any effect, I'm not sure what you're trying to achieve that you thought that would solve the problem.
I understand perfectly what You are saying here, and that would be one approach, but You missinterpret what I meant when I said "refresshing an element".Let me expalin a little bit more.If I choose to leave the custom tags on the page, I tought, instead of returning an HTML and updating the element,I could manipulate the custom tag attribute object, which is responsible for filling the custom tag with results (an array list like object), and that change would be propagated in already rendered HTML element.The only problem I ran on here is after I manipulate the object I need to refresh the page in order to se the changesin the rendered HTML tag.Watch the video carefully and You'll see exactly what I mean.
So this would be the second approach and my question is, is there a way to see these changes without manuallyrefreshing the page (if reloaded automatically with location.reload but it's not an elegant solution).The best solution would be if there was some function to reload rendered HTML element only and not the entire page?Is there such a thing in JavaScript or jQuery?Thank You.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...