Use AJAX instead of TagLib?

I was thinking about the idea of using Ajax instead of TagLib. The most elegant way would be: Using Java Annotation. The idea is, designers or anybody can make the HTML without any taglib ,just using the "standard" HTML tags with id or name, and call the Javascript. That way any WYSIWYG can be used, developer don't have to care about HTML format or the way it's designed. In many (at least open-source) WYSIWYG don't show the taglibs in that final result (or have a template of it), so it's hard to "preview". Other reason is, developer should know Java and HTML/TagLibs should not be a must-have, since we got CSS and AJAX.

It should work just like that:

import ...

// Use the ResourceBundle resource[.{Locale}].properties
public class MyClass {
    private Integer age;
    private String name
    private Date dob;
    private salary;

    public String getName() {
    public void setName(String name) {
        if ( name.trim().equal("") ) {
            throw new Exception("Name is required");
    /* Getter and setter for age */
    // or you could use that to access a property of the ResourceBundle
    public Date getSalary() {
    /* Setter for salary and getter/setter for the rest */


     <form onload="Jay2J.formalize(this)">

of it can be a HTML with the fields filled; PageWithFields.html:

     <form action="myfavoritewaytopostthis" onsubmit="return Jay2J.validate(this)" onload="Jay2J.formalizeExistField(this)">
       <label>Name</label><input type="text" name="name" id="name" />
       <label>DOB</label><input type="text" name="dateOfBirth" id="dob" />
       <label>Salary</label><input type="text" name="salary" id="salary" />
       <input type="submit" />

That way the Annotation (no XML, it's like HTML in the way that it's only another file modify and XML is not Java) will define how the HTML will be treated. That way developer can stop developing in HTML and use just JAVA (or JavaScript), do you think that's a valid idea?

Asked by: Lily675 | Posted: 28-01-2022

Answer 1

When i see your topic title i thought:

You cant use Ajax in stead of a taglib. AJAX is javascript on the client and the taglib is java code on the server.

After reading your post i thought, ah he whats to do what [link text][1] does

But then not entrily the same.

[1]: GWT

Answered by: Melanie418 | Posted: 01-03-2022

Answer 2

First impression is ... yuck, someone who picks this up will have no idea what they're looking at without learning your (new, different, non-standard) way of doing things. You could do something similar by implementing a tag that takes a bean (value object) and maybe does some minor reflection/annotation inspection to emit the proper html, and you'll save yourself a lot of heartache down the line.

Make your value objects implement a simple interface that your tag will use to extract and format the html, and you can probably get 80-90% of where you're trying to go with 1/2 the work or less.

Answered by: Miller728 | Posted: 01-03-2022

Answer 3

First impression was, WTF. After reading further, I get a impression that you are trying to address the 'separation of concerns'problem in a different way. Some observations on your approach.

  1. Requires client side scripting to be enabled and hence fails accessibility guide lines.
  2. Reinventing the wheel: Many web frameworks like Tapestry, Wicket try to address these issues and have done a commendable work.
  3. On your comment on binding Java to HTML, the code example doesn't convey the idea very clearly. formalize() seems to create the UI, that implies you have UI (HTML) coded into java (Bad Idea? probably not NakedObjects attempts to you domain models for UI, probably yes if one were to write a page specific code)
  4. validate() is invoked on onSubmit(), Why would I want it to be processed asynchronously!! That aside, using obstrusive java script is way out of fashion (seperation of concerns again)
  5. Your argument on taglibs preventing WYSIWIG, though justifiable, is not entirely valid. Tags cannot be used to compose other tags, each tag is a unique entity that either deals with behaviour or emits some html code. Your argument is valid for the second case. However, if I understand your formalize() correctly, you are doing the same!

Nice to hear some new ideas and Welcome to SO. Also, please use the edit question option until you earn enough reputation to add comments. Adding answers is not the right way!

Answered by: Melissa692 | Posted: 01-03-2022

Answer 4

This idea has some merit, if I understand it correctly.

You could use AOP to modify a servlet that would actually be called for the page. The servlet would then return the html, using the annotations.

This way the programmers don't see the html generation, and if you have a standard javascript library for it, then it may work.

But, just because it works doesn't mean that you should do it.

As was mentioned, there are many frameworks out there that can hide the javascript from programmers, such as JSF, which is basically taglibs and a different navigation scheme.

I remember using the beehive project to do something similar, it was annotation driven so I could basically do everything in java and it generated the javascript, years ago. :)

Answered by: Aston166 | Posted: 01-03-2022

Similar questions

java - JSTL Taglib uri for Tomcat 6.0

Can anybody help me oput by letting me know the "taglib uri" for JSTL tags in TOMCAT 6.0

java - JSP what taglib should be added?

What lines starting with &lt;%@ should be added at the beginning of a JSP file to be able to make use of the tag. I have added the following line to the beginning of my jsp. &lt;%@ taglib prefix="html" uri="" %> But Eclipse IDE says The tag handler class for "html:link" (org.apache.struts.taglib....

TagLib port or similar audio tag reader for Java

Does anyone know if there is a TagLib port or similar audio tag reader for available for Java? I am currently using TagLibSharp on C#, but I'm looking to go cross-platform. I would really prefer to be using Mono, but I have

java - Taglib import in a JSP, how?

&lt;%@ taglib prefix="c" uri="http:" %&gt; this doesn't work. What is the new taglib import statement, and how can I find a reference of others to use, and what tags there are to use. Thanks!

java - taglib json create object from array

I am using json taglib in my jsp project. currently I am building my json object with this code: &lt;json:object prettyPrint="true"&gt; &lt;json:array name="categories" var="cat" items="${categories}"&gt; &lt;json:object&gt; &lt;json:property name="id" value="${cat.getId()}" /&gt; &lt;json:array name="languages" var="lang" items="${cat.getCategorieslanguageses()}"&gt; ...

java - How can i use taglib in JSP page

I know this problem has been posted many times but every solutions that have been posted didn't solve my problem whereas my issue is the same. I have a JSP page and i want to use taglib in. So i added this line in it : &lt;%@taglib uri="" prefix="c" %&gt; My project runs with maven 2 so i included in pom.xml that dependency too : &lt;depende...

java - Error when I try to read a taglib jar file

I try to use a jar file containing a taglib. I get a "Content is not allowed in prolog" error (in french in the stacktrace below): sept. 12, 2013 3:52:49 PM org.apache.catalina.startup.TldConfig tldScanWebXml Avertissement: Failed to process TLD with path [taglib-welcom-uri] and URI [/WEB-INF/lib/welcom-2.6.13-SNAPSHOT.jar] org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; ...

java - JSTL Taglib -error

i have the following pice of code: &lt;%@ taglib prefix="c" uri="" %&gt; If i want to run the programm i get the following error message: HTTP Status 500 - The absolute uri: cannot be resolved in either web.xml or the jar files deployed with this...

Java jsp taglib

I frequently saw links to "external tag libraries" in jsp Ex: &lt;%@ taglib uri="" prefix="sql"%&gt; But I couldn't find answers to these questions: Does use a tag library from an external web location? Does it query that location every time the tag is used? Does it download it only once? when does the download happen...

java - What is a taglib?

Can someone explain what a taglib is in respect to Java programming? It contains a prefix and uri...but what do each of these refer to? I looked up a number of different websites but am frankly am still confused about what it is and what it does.

Still can't find your answer? Check out these amazing Java communities for help...

Java Reddit Community | Java Help Reddit Community | Java Community | Java Discord | Java Programmers (Facebook) | Java developers (Facebook)