javastruts2taglibstruts2-jquerystruts2-jquery-plugin

Some doubts related to the meaning of Struts 2 UI tag library. What gives me more the Struts 2 UI tags?


I am very new in Struts 2 world and I have the following doubt related to the Struts 2 UI tag library, this: https://struts.apache.org/docs/ui-tag-reference.html

From what I have understand using it, it wrap some standard html tag and some common JQuery plugin?

My doubt is: what is the difference between using a specific Struts 2 tag from the UI tag library and use the equivalent html tag or the equivalent JQuery plugin? What gives me more the Struts 2 UI tags?


Solution

    1. Reusability: you don't need to rewrite every time the same code;

    2. Safety: code in Struts tag is tested, while your could have typos or other errors;

    3. Decoupling: to replicate the same functionality of a Struts tag, you need to know how it (and the framework) works internally. To use it, you only need to know its attributes;

    4. Standard (and compact): if someone needs to work on your code, he knows Struts2, not the patterns / tag structures / mind castles you're used to... it can be easy to spot what an HTML snippet is doing, but dozens/hundreds of HTML snippets (or includes) instead of tags can make a page huge and very messy; also you generally use HTML with some non-ui tags like <s:iterator>, and this:

      <select name="selectedId">
          <s:iterator value="people">
              <option value="<s:property value="id"/>">
                  <s:property value="name"/>
              </option>   
          </s:iterator>
      </select>
      

      is definitely worse than this:

      <s:select name="selectedId" list="people" listKey="id" listValue="name" />
      
    5. OGNL is your friend. And a good one...

    That said, if you learn the Struts2 way only, you'll be in trouble when in future you'll migrate to other technologies, so it would be better to learn both the ways and then using the more appropriate from project to project, page to page, tag to tag.

    There are sometimes cases where you have special needs and decide to use native HTML instead of Struts tags, or raw jQuery instead of Struts-jQuery-plugin tags, or JSTL (or even EL) instead of OGNL, and it's totally fine.

    But in my experience, most of them are usefull most of the times.

    Just remember: beware of the deprecated <sx: /> Dojo tags. There is Struts2-jQuery plugin for that, with its new and up-to-date <sj: /> tags.