JSP Tag Libraries

Скачать в pdf «JSP Tag Libraries»


Based on these complications, it would appear that our initial ifTag is too simplistic to be properly built upon and extended. We can conclude from this that we should implement a new set of tags to cope with complex conditions (including else clauses). Building this more flexible tag library is the subject of the next section.

9.3 The advanced condition tag family


Following the discussion in the previous section, an advanced condition tag should:


■    Allow the developer to create the equivalent of a chain of Java if-eise-if statements that are based on the same object.


   Provide a straightforward syntax for the JSP developer (for example, obviate the entering of needless IDs and object references, even if they want to query a certain object more than once).


■ Eliminate the simple and sometime useless conversion of the conditioned object to a boolean, and let the developer specify a more exact condition (such as: the object is a String that contains the sub-string “MSIE”).


Considering these requirements, it is clear that what we are looking for is not a single complex tag but a family of tags working together. A single tag, as powerful as it might be, is going to be too complex to develop and use. The library we will develop, which we’ll call the advanced condition tags, will have to obtain the Java object on which we want to perform conditions, and evaluate various conditions on the object’s values. Also, we want it to have more than one conditional fragment of JSP to be evaluated if its condition is true. For example, we want to have the following ability as demonstrated in this pseudo JSP fragment:

Скачать в pdf «JSP Tag Libraries»