Custom Tag or Javabean?


Web tier: servlets, JSP, Web frameworks: Custom Tag or Javabean?

  1. Custom Tag or Javabean? (3 messages)

    When's best to use which?


    Threaded Messages (3)

  2. Custom Tag or Javabean?[ Go to top ]

    As a general rule, I would divide JSP Tag libraries and JavaBeans as so:
    <li>JavaBeans are used to encapsulate the "model" of you application. They contain the data and business logic. From a Model 2 perspective - this is what the servlet is placing in the request/session for the JSP to display. The JavaBeans themselves should have no "knowledge" they are being used in a JSP. In fact, the mechanism in how they are displayed should be comletely transparent to the JavaBean class.</li>
    <li>Tag libraries are used to remove Java code from the JSP. Some very common uses of them are to perform boolean and null tests and iterations. In fact, if you have Tag libraries that perform these functions, you can probably remove 80% of the scriplet code from our JSPs! However, it is better if the JSP Tags do not contain any display logic, only logic that help the JSP display the corrent information. Basically - they support the JSP to keep them as "clean" as possible</li>
  3. Custom Tag or Javabean?[ Go to top ]

  4. Custom Tag or Javabean?[ Go to top ]

    more advice: resist the urge to put display logic into the taglib. display logic meaning HTML text. HTML is much better off in its own file .. so you can use WYSIWYG editors like dreamweaver. but this is usually difficult to do and is the first thing to be abandoned when the schedule gets tight.