JavaServer Page

March 10, 2007

CHAPTER 9 Posing conditions with tags in testing

Filed under: JSP Tag Libraries — webmaster @ 4:06 pm

Improving our advanced condition tags B Points to the User-Agent header. C Informs the wrapper tag that we are going to allow the execution of multiple successful tests By setting the multichoice attribute to true, we indicate that all tests wrapped in this WithTag should be evaluated. For example, if you try to access this JSP fragment from Internet Explorer running on Win98, both the MSIE and 98 containment conditions will come up true and you will see the body of these tests in the response. If you wonder why someone would want to have several successful tests in the same JSP fragment, just picture some JSP code in which you want to adapt yourself to the browser as much as possible. In this case you will need to test the browser s capabilities over and over again. Using the multichoice option can give you this flexibility. D Execution of an if-else logic first test if the header contains MSIE and then check that it does not. E Provides an Integer as a second operand. F Checks if the User-Agent header does not start with a Mozilla/ prefix (most browsers do). Note from these two samples that using our tags is fairly straightforward; the tag attributes make sense and we ve kept the syntax to a minimum. It is also easy, using this library, to test the reference object and specify conditions; but aren t these conditions too elementary for many real-world uses? The next section will discuss this concern. 9.4 Improving our advanced condition tags The tags we ve built do a fair job of handling condition evaluation, so what s missing? The main shortcoming with our tag library is that many real applications have conditions that use more than two operands, which is the maximum our library can handle. In Java we can have conditions that look like: if(s.trim().equals( somevalue ) && someBoolean && otherBoolean) { // do something } Such a condition could not be represented using our current library. Does it mean that we cannot use condition tags in a real-world case? There are a number of possible ways to support these complex conditions within tags. Here are two of them: Invent a complex condition language to be used within the tags and extend the tags we developed to use this language. Have the user of the tags put all of the complex conditions inside a bean and use the bean s attributes to grab the condition s result inside the tags.

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Tomcat Web Hosting services

No Comments

No comments yet.

RSS feed for comments on this post. TrackBack URI

Sorry, the comment form is closed at this time.

Powered by Java Web Hosting