This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JSP and the fly likes JSP Component? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "JSP Component?" Watch "JSP Component?" New topic
Author

JSP Component?

Alex Kravets
Ranch Hand

Joined: Jan 24, 2001
Posts: 476
Hi guys,
I am writing a dynamic JSP page in which I want to use elements of HTML forms. One of the elements is NumericField which is just a <input type="text
"> with javascript that restricts entering any characters except numeric. I read about HTML Components (HTC) introduced by Microsoft, but there hardly any information about how to implemented. Is there any way I create a JSP component that will have an HTML element and some JavaScript that is also will be able to communicate with a server using Java syntax. I was thinking about creating a JSP page that will have all this information, but is this an efficient way to do this? Is there a way I can write a class that will return a String that represents HTML element and has parameters such as size and name based on parameters I send to this class, and also can proccess input from this element?
I am totally clueless here, any help is appreciated.
thanks,
Alex


All right brain, you don't like me and I don't like you, but let's just do this one thing so I can get back to killing you with beer.<br /> <br />- Homer Simpson
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60794
    
  65

Is there a way I can write a class that will return a String that represents HTML element and has parameters such as size and name based on parameters I send to this class, and also can proccess input from this element?

I do this quite successfully using custom actions -- which, I might add, is way simpler to do (especially for the type of purpose being discussed here) using JSP 2.0 tag files.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Alex Kravets
Ranch Hand

Joined: Jan 24, 2001
Posts: 476
You mean JSTL? Where is the best place to learn more about this?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60794
    
  65

No. JSTL is an example of custom actions. I'm talking about writing your own.
For example, I have created a button component that emits an HTML button tag along with all the javascript that controls its semantics (roll-overs, active/inactive states, onclick execution, and so on). On the JSP page it's a simple little tag -- it turns into all the necessary goo on the HTML pages sent to the browser*.
* Since I have a lot of the button goo factored out into a Javascript class, even all the emitted goo isn't all that horrible. But the point is, the JSP pages look fabulous!
Alex Kravets
Ranch Hand

Joined: Jan 24, 2001
Posts: 476
got it. Can you give an example or point to the right direction where I can learn more about this?
Alex Kravets
Ranch Hand

Joined: Jan 24, 2001
Posts: 476
may be this is it?
http://today.java.net/pub/a/today/2003/11/14/tagfiles.html
I tried implementing example in this article but every time I run jsp page that uses a tag I get this error:

Have no idea what it means...
[ March 26, 2004: Message edited by: Alex Kravets ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60794
    
  65

Yes. But bear in mind that tag files are just one means to create custom actions. You can also code them in Java which is sometimes preferable.
In order to utilize tag files, you need to be running a JSP 2.0 engine (Tomcat 5, Resin 3) and have your web application delcared as a servlet 2.4 web app. Otherwise, you'll need to use JSP 1.2-style custom actions which must be implemented as Java classes.
Alex Kravets
Ranch Hand

Joined: Jan 24, 2001
Posts: 476
Ok, then another question. How do I check which Servlet version I am running? With java it easy java -version, but what about servlets?
Also, you said:

Otherwise, you'll need to use JSP 1.2-style custom actions which must be implemented as Java classes.

Is this the same as using <jsp:useBean> ?
Finally,

Yes. But bear in mind that tag files are just one means to create custom actions. You can also code them in Java which is sometimes preferable.

What do you mean here? Have Java Classes that reside in WEB-INF?
[ March 26, 2004: Message edited by: Alex Kravets ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60794
    
  65

How do I check which Servlet version I am running?

Depends upon your container. Which are you using? If Tomcat, you need Tomcat 5. If Resin, the Resin 3. I'm not sure what rev the other containers are up to.
Is this the same as using <jsp:useBean> ?

No, that's a whole different mechanism. If you want to be using custom actions, you've got a lot of reading ahead of you. But it'll be well worth it; custom actions (formerly known as tag libraries) are by far the best way to create resuable JSP components.
Visit the JavaRanch Bunkhouse for reading recommendations. Or search the web for a tutorial on "custom tags".
What do you mean here? Have Java Classes that reside in WEB-INF?

Yes. Non-tag-file custom actions are implemented via Java classes that you write that extend and implement classes and interfaces provided by the javax.servlet.jsp.tagext package.
[ March 26, 2004: Message edited by: Bear Bibeault ]
Alex Kravets
Ranch Hand

Joined: Jan 24, 2001
Posts: 476
thank you very much for the info Bear!
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
There's information about HTC coding on the MSDN website, http://msdn.microsoft.com
Sorry, don't have the exact URL, you'll need to search.
That site is a true treasuretrove of HTML and Javascript (plus of course everything Microsoft specific) information.


42
Alex Kravets
Ranch Hand

Joined: Jan 24, 2001
Posts: 476
Unfortunately it's only a reference, sort of API. There is no good tutorial on HTC...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSP Component?
 
Similar Threads
How to get Events associated with DOM elements ?
Showing Hiding <s:div> tag in Struts2
javascript function for time... need suggestion
order of retreiving form parameters using javascript
Accessing indexed properties in Javascript