SigmaInfoSolution_Hussain Akhtar Wahid

Embed Size (px)

Citation preview

  • 8/2/2019 SigmaInfoSolution_Hussain Akhtar Wahid

    1/31

    A Presentation On

    Struts Taglib

    By :-

    Hussain Akhtar WahidASE(Sigma InfoSolutions)

    Emp Id : 335

  • 8/2/2019 SigmaInfoSolution_Hussain Akhtar Wahid

    2/31

    IntroductionStrut Taglib is the new library of tags as an

    advanced version of the JSP Taglib .It hassome extra features and also immutablecompatibility with all the action forms ,

    specially required for nested action formor action form series.

  • 8/2/2019 SigmaInfoSolution_Hussain Akhtar Wahid

    3/31

    Types

    1. HTML

    2. Bean

    3. Logic

    4. Nested

  • 8/2/2019 SigmaInfoSolution_Hussain Akhtar Wahid

    4/31

    HTML

    This taglib contains tags used tocreate struts input forms, as well

    as other tags generally useful inthe creation of HTML-based user

    interfaces.

  • 8/2/2019 SigmaInfoSolution_Hussain Akhtar Wahid

    5/31

  • 8/2/2019 SigmaInfoSolution_Hussain Akhtar Wahid

    6/31

    Bean

    1 : Some features are also in the JSPStandard Tag Library (JSTL).

    2 : Standard tags over the Struts specifictags are encouraged3 : easy accessing beans and their

    properties4 : defining new beans5 : easy bean creationon the value of

    request cookies, headers, and

  • 8/2/2019 SigmaInfoSolution_Hussain Akhtar Wahid

    7/31

    Bean

    cookie define

    header include

    message page

    parameter resource

    size struts

    write

  • 8/2/2019 SigmaInfoSolution_Hussain Akhtar Wahid

    8/31

    Logic

    This tag library contains tags that are useful inmanaging conditional generation of output

    text, looping over object collections forrepetitive generation of output text, andapplication flow management.

  • 8/2/2019 SigmaInfoSolution_Hussain Akhtar Wahid

    9/31

    Logic cont...1

    Rules for Comparison Tags1: Automatic type comparison2: The variable to be compared to is retrieved, based on theselector attribute3: Null will be coerced to a zero-length string before the

    comparison4: Tags perform from out to in

    Rules For substring matching tags1: The variable to be compared to is retrieved, based on theselector attribute2: Null is thrown as request time Exception

  • 8/2/2019 SigmaInfoSolution_Hussain Akhtar Wahid

    10/31

    Logic

    empty equal forward

    greaterEqual greaterThan iterate

    lessEqual lessThan match

    messagesNotPresent messagesPresent notEmpty

    notEqual notMatch notPresent

    present redirect

  • 8/2/2019 SigmaInfoSolution_Hussain Akhtar Wahid

    11/31

    Nested

    This tag library brings a nested context to thefunctionality of the Struts custom tag library.

    It's written in a layer that extends the currentStruts tags, building on their logic andfunctionalityThe layer enables the tags to be aware of the

    tags which surround them so they can correctlyprovide the nesting property reference to theStruts system

  • 8/2/2019 SigmaInfoSolution_Hussain Akhtar Wahid

    12/31

    Nested cont...

    It's all about nesting beans...A bean holds a reference to another bean internally, andall access to that bean is handled through the current

    bean. This act of having one bean's access go throughanother bean is known as "nesting beans". The first beanis known as the parent bean. The bean which it references,is known as a child bean. The terms "parent" and "child"

    are commonly used to describe the model's hierarchy.most parent class is calles root class

  • 8/2/2019 SigmaInfoSolution_Hussain Akhtar Wahid

    13/31

    Nestedcheckbox define empty equal

    errors file form greaterEqual

    greaterThan hidden image img

    iterate lessEqual lessThan link

    match message messages messagesNotPresent

    messagesPresent multibox nest notEmpty

    notEqual notMatch notPresent options

    optionsCollection password present radio

    root select size submit

    text textarea write writeNesting

  • 8/2/2019 SigmaInfoSolution_Hussain Akhtar Wahid

    14/31

    Nested cont...

    It's all about nesting beans...A bean holds a reference to another bean internally, andall access to that bean is handled through the current

    bean. This act of having one bean's access go throughanother bean is known as "nesting beans". The first beanis known as the parent bean. The bean which it references,is known as a child bean. The terms "parent" and "child"

    are commonly used to describe the model's hierarchy.parent-most class is called root class

  • 8/2/2019 SigmaInfoSolution_Hussain Akhtar Wahid

    15/31

    tag base1: Renders an HTML element with an href attribute

    pointing to the absolute location of the enclosing JSP page.

    2: This tag is valid only when nested inside an HTML element.

    3: This tag is useful because it allows you to use relative URL

    references in the page that are calculated based on the URL ofthe page itself, rather than the URL to which the most recentsubmit took place (which is where the browser would normallyresolve relative references against).

  • 8/2/2019 SigmaInfoSolution_Hussain Akhtar Wahid

    16/31

    Tag cancel

    Render a Cancel Button

    Renders an HTML element of type submit. This

    tag is only valid when nested inside a form tag body.Pressing of this submit button causes the action servlet tobypass calling the associated form bean validate()method. The action is called normally.

  • 8/2/2019 SigmaInfoSolution_Hussain Akhtar Wahid

    17/31

    Tag errorsConditionally display a set of accumulated error messages.

    Displays a set of error messages prepared by a business logic component and storedas an ActionMessages object, an ActionErrors object, a String, or a String array in anyscope. If such a bean is not found, nothing will be rendered.In order to use this tag successfully, you must have defined an application scopeMessageResources bean under the default attribute name, with optional definitionsof message keys specified in the following attributes:

    header - Text that will be rendered before the error messages list. Typically, thismessage text will end with to start the error messages list (default

    "errors.header").footer - Text that will be rendered after the error messages list. Typically, thismessage text will begin with to end the error messages list (default"errors.footer").prefix - Text that will be rendered before each individual error in the list (default"errors.prefix").

    suffix - Text that will be rendered after each individual error in the list (default"errors.suffix" .

  • 8/2/2019 SigmaInfoSolution_Hussain Akhtar Wahid

    18/31

    Tag javascript

    Render JavaScript validation based on the validation rules loaded by theValidatorPlugIn.

    Render JavaScript validation based on the validation rules loaded by theValidatorPlugIn. The set of validation rules that should be generated isbased on the formName attribute passed in, which should match the nameattribute of the form element in the xml file.

    The dynamicJavascript and staticJavascript attributes default to true, but ifdynamicJavascript is set to true and staticJavascript is set to false then onlythe dynamic JavaScript will be rendered. If dynamicJavascript is set to falseand staticJavascript is set to true then only the static JavaScript will berendered which can then be put in separate JSP page so the browser cancache the static JavaScript.

  • 8/2/2019 SigmaInfoSolution_Hussain Akhtar Wahid

    19/31

    Tag messages

    Conditionally display a set of accumulated messages.

    Displays a set of messages prepared by a business logic

    component and stored as an ActionMessages object,ActionErrors object, a String, or a String array in any scope. Ifsuch a bean is not found, nothing will be rendered. Themessages are placed into the page scope in the body of this tag

    where they can be displayed by standard JSP methods. (Forexample: ,)

    In order to use this tag successfully, you must have defined anapplication scope MessageResources bean under the default

    attribute name.

  • 8/2/2019 SigmaInfoSolution_Hussain Akhtar Wahid

    20/31

    Tag header

    Define a scripting variable based on the value(s) of thespecified request header.

    Retrieve the value of the specified request header (as a singlevalue or multiple values, depending on the multiple attribute),and define the result as a page scope attribute of type String (ifmultiple is not specified) or String[] (if multiple is specified).

    If no header with the specified name can be located, and nodefault value is specified, a request time exception will bethrown.

  • 8/2/2019 SigmaInfoSolution_Hussain Akhtar Wahid

    21/31

    Tag cookie

    Define a scripting variable based on the value(s) of thespecified request cookie.

    Retrieve the value of the specified request cookie (as a singlevalue or multiple values, depending on the multiple attribute),and define the result as a page scope attribute of type Cookie (ifmultiple is not specified) or Cookie[] (if multiple is specified).

    If no cookie with the specified name can be located, and nodefault value is specified, a request time exception will bethrown.

  • 8/2/2019 SigmaInfoSolution_Hussain Akhtar Wahid

    22/31

    Tag size

    Define a bean containing the number of elements in a Collection orMap.

    Given a reference to an array, Collection or Map, creates a new bean,of type java.lang.Integer, whose value is the number of elements inthat collection. You can specify the collection to be counted in anyone of the following ways:

    As a runtime expression specified as the value of the collectionattribute.As a JSP bean specified by the name attribute.As the property, specified by the property attribute, of the JSP beanspecified by the name attribute.

  • 8/2/2019 SigmaInfoSolution_Hussain Akhtar Wahid

    23/31

    Tag struts

    Expose a named Struts internal configuration object as a bean.

    Retrieve the value of the specified Struts internal configuration

    object, and define it as a scripting variable and as a page scopeattribute accessible to the remainder of the current page. You mustspecify exactly one of the formBean, forward, and mapping attributesto select the configuration object to be exposed.

    If a problem occurs while retrieving the specified configurationobject, a request time exception will be thrown.

  • 8/2/2019 SigmaInfoSolution_Hussain Akhtar Wahid

    24/31

    Tag write

    Render the value of the specified bean property to the current JspWriter.

    Retrieve the value of the specified bean property, and render it to the current JspWriter as a String bythe ways:

    If format attribute exists then value will be formatted on base of format string from format attributeand default system locale.If in resources exists format string for value data type (view format attribute description) then value

    will be formatted on base of format string from resources. Resources bundle and target locale can bespecified with bundle and locale attributes. If nothing specified then default resource bundle andcurrent user locale will be used.

    If there is a PropertyEditor configured for the property value's class, the getAsText() method will becalled.Otherwise, the usual toString() conversions will be applied.

    When a format string is provided, numeric values are formatted using the java.text.DecimalFormatclass; if the format string came from a resource, the applyLocalisedPattern() method is used, andapplyPattern() is used otherwise. Dates are formatted using the SimpleDateFormat class. For detailsof the specific format patterns, please see the Javadocs for those classes.

    If a problem occurs while retrieving the specified bean property, a request time exception will be

  • 8/2/2019 SigmaInfoSolution_Hussain Akhtar Wahid

    25/31

    logic

    Forward control to the page specified by the specified ActionForwardentry.

    Performs a PageContext.forward() orHttpServletResponse.sendRedirect() call for the global

    ActionForward entry for the specified name. URL rewriting willoccur automatically if a redirect is performed.

    Tag forward

  • 8/2/2019 SigmaInfoSolution_Hussain Akhtar Wahid

    26/31

    Tag iterate

    Render an internationalized message string to the response.

    Retrieves an internationalized message for the specified locale, using

    the specified message key, and write it to the output stream. Up tofive parametric replacements (such as "{0}") may be specified.

    The message key may be specified directly, using the key attribute, orindirectly, using the name and property attributes to obtain it from a

    bean.

    JSTL: The equivalent JSTL tag is . For example,

  • 8/2/2019 SigmaInfoSolution_Hussain Akhtar Wahid

    27/31

    Tag match

    Evaluate the nested body content of this tag if the specified value isan appropriate substring of the requested variable.

    Matches the variable specified by one of the selector attributes (as aString) against the specified constant value. If the value is a substring(appropriately limited by the location attribute), the nested bodycontent of this tag is evaluated.

  • 8/2/2019 SigmaInfoSolution_Hussain Akhtar Wahid

    28/31

    Pitfalls Of JSP

    1 : Hard-Coded Strings in JSPs2 : Hard-Coded Keys in JSPs3 : Not Using Struts Tags for Error Messaging4 : Calculating Derived Values in JSPs5 : Performing Business Logic in JSPs6 : Hard-Coded Options in HTML Select Lists7 : Not Checking for Duplicate Form Submissions

  • 8/2/2019 SigmaInfoSolution_Hussain Akhtar Wahid

    29/31

    Step-by-Step1. Create a Constants class.a. Depending on which approach is taken to the replacement ofconstant keys in the JSP, you might also need to create accessors

    for each property constant.2. Begin with a single, simple JSP.a. Keep in mind that you will be repeating these steps, so it is bestto start simple and work your way up.b. Another equally valid approach is to go through your homepage, then each page that is accessible from there and so on until

    you have covered all the pages.

    3. Search for hard-coded keys.4. Create a new constant in the Java class for each unique key.a. Keep in mind that if there are a lot of constants, say more than 30or 40 as a rule of thumb, the constants should be grouped andsplit into separate classes.5. Replace each hard-coded key with a reference to the appropriateconstant.

    a. Or use an expression referring to the property.6. Test the changes.7. Continue with the next JSP, until all keys have been replaced withthe constant.

  • 8/2/2019 SigmaInfoSolution_Hussain Akhtar Wahid

    30/31

  • 8/2/2019 SigmaInfoSolution_Hussain Akhtar Wahid

    31/31

    Hussain Akhtar Wahid

    ASE(Sigma InfoSolutions)

    Emp Id : 335