• 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

Using Javascript, ajax and submit button in Custom tag file

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
At first, I decided to accept login input from HTML controls and then it will send the data to the LoginServlet which will checks the database and logs in the user and redirect to its homepage view.
But now, I'm thinking to make login tag file.
But should I include a submit button inside the tag file or I should keep use it outside.
Also I have to use javascript for validating empty textboxes. So should I put javascript in tag file or not?

There's more, I will use a html tag(label or div) inside tag file for displaying errors, this will be mostly used for ajax purpose (such as "username is in use"). So I need to specify a javascript function. But where will I put this javascript function. And if I put it outside the tag file (i.e. in a jsp page), then I have to declare an attribute in the tag file, so that I can call the javascript function from within the tag file.

Although, I can simply put a call to javascript function inside a tag file without an attribute, but that doesn't seem right thing to do.

:confused:
 
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
What's the point of creating a tag file at all unless you are going to make it self-contained? If you're going to spread things all over the place, what's the gain?

And I have absolutely no idea at all what you mean by this:

Although, I can simply put a call to javascript function inside a tag file without an attribute, but that doesn't seem right thing to do.

 
Harish Moolchandani
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I mean that, I can directly specify a javascript function call to a html tag inside Tag file
such as



And specify the validate function in JSP page which uses the tag, since the output of tag file is going to merge into jsp page, it will work. But I don't think its right thing to do.

Should I code it like this:



--OR--



I'm still confused with the displaying of ajax content. If I use Login tag in index.jsp, I want when user clicks on submit, it will go to LoginServlet. If user is not existing in database, it will redirect it to index.jsp(since I cannot redirect it to tag) passing errorMessage in Query String. Now how will I show this message in my tag, since tag is already rendered by JSP.

Only way I see to do this is to call LoginServlet and it will then forward the errorMessage to another JSP page called ErrorPage and it will just display the errorMessage recieved. Now when the response is sent, it contains this errorMessage and ajax will reflect it to the desired location. So, I'll have to make a seperate JSP page just to display a message :shock:
(I know the concept of error pages, but they are used to display a user friendly error message if any exception occurs in our JSP. I'm using it to build an ajax response). Am I on the right track or not.
reply
    Bookmark Topic Watch Topic
  • New Topic