aspose file tools*
The moose likes JSP and the fly likes Using Javascript, ajax and submit button in Custom tag file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Using Javascript, ajax and submit button in Custom tag file" Watch "Using Javascript, ajax and submit button in Custom tag file" New topic
Author

Using Javascript, ajax and submit button in Custom tag file

Harish Moolchandani
Greenhorn

Joined: Mar 12, 2010
Posts: 23
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:
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61434
    
  67

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Harish Moolchandani
Greenhorn

Joined: Mar 12, 2010
Posts: 23
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.
 
 
subject: Using Javascript, ajax and submit button in Custom tag file