WebWork UI Tags

Source: Internet
Author: User
Tags prepare
WebWork UI Tags I. Overview of UI tags 1. Composition of UI Components

WebWork is a framework for non-binding view technology that can be used to write user interfaces using JSP, Velocity, Freemarker, or other supported methods. By default, webwork only supports JSP tag methods to invoke UI tags.

WebWork UI tags can be written in any template language.

Template

A template is a file written using velocity, JSP, or Freemarker to generate HTML markup.

Theme

A theme is a set of templates together to form a common sense of perception.

Tag

A tag is a JSP tag that is used to read properties and to output templates using attributes. 2, Themes

Theme defines the layout and style. WebWork built-in theme:xhtml, simple, css_xhtml and so on. Any one can be extended or copied to make your personalized theme. Second, the UI tag common Properties 1. General Properties

Property

Theme

Data type

Describe

Name

Simple

String

Name of the form element map

Value

Simple

Object

The value of the form element

Label

Xhtml

String

The label,simple theme used in XHTML theme will be ignored

LabelPosition

Xhtml

String

The position of the label element, top at the top of the element, left in the element

Required

Xhtml

Boolean

If true, an asterisk is displayed to the right of the label, indicating that the field is required and, by default, the value is true if a field-level validator is mapped to the field name.

Id

Simple

String

HTML ID attribute that allows simple integration with JavaScript

CssClass

Simple

String

The class property of the form element

CSSStyle

Simple

String

Form element's Style property

Disabled

Simple

Boolean

Disabled properties for form elements

TabIndex

Simple

String

TabIndex Properties for form elements

Theme

N/A

String

In which theme the template is to be found, by default, if it is not the theme specified in Webwork.properties, it is XHTML

Template

N/A

String

The template used to output the UI label, all UI tags have a default template (except for the component tag), but the template can be reset

2. id attribute

In addition to the form label, all UI tags have a default value for the ID property. It is generally recommended to set this property for the following reasons:

1th: It makes the label of the form more tightly bound to your form because it specifies the for property.

2nd: It can be integrated with JavaScript.

If not specified, the default value is [Formname]_[elementname]. three, simple label 1. Form label

Function: Serves as the container's role.

Property:

Action: [String] The name to be submitted to action

namespace: [String]action namespace, the default namespace depends on the current request

Method: [String]post or get

Target: [String]form commits the destination window. Typically a frame name, _blank, _top, or any other specified target value

Enctype: Set to Multipart/form-data when uploading files

Opentemplate: Default mapping to FORM.VM

Validate: Used for client-side validation

Note: By default, the value of the Name property is the name of the action to be submitted. 2. TextField label

Function: Text input

Property:

MaxLength: [String] The maximum length that can be entered

ReadOnly: [Boolean] is set to True when the user cannot enter

Size: [String] Visual size 3, password label

Function: Similar to TextField, but the default value is not displayed

Property:

MaxLength: [String] The maximum length that can be entered

ReadOnly: [Boolean] is set to True when the user cannot enter

Size: [String] Visual size

Show: [Boolean] defaults to False, when set to True, the password field is preset 4, textarea label

Function: Used to enter a large amount of text.

Property:

COLS: [String] Number of columns in the text area

Rows: Number of rows in the [String] text area

ReadOnly: [Boolean] is set to True when the user cannot enter

Wrap: [String] Specifies whether the contents of the text area should be wrapped 5, checkbox label

Features: check box

Property:

Fieldvalue: [String] check box is selected when the value submitted to the action

Example:

<ww:checkbox label= "is flag" name= "flag" fieldvalue= "true" value= "true"/>

index.jsp

<%@ taglib prefix= "ww" uri= "webwork"%>


Checkboxaction.java package

com.example;

Import Com.opensymphony.xwork.ActionSupport;

Import com.opensymphony.xwork.Preparable;

public class Checkboxaction extends Actionsupport implements preparable{

       Private Boolean flag = false;

       private String message;

       

       public Boolean Getflag () {

              return flag;

       }

       

       public void Setflag (Boolean flag) {

              This.flag = flag;

       }

       

       Public String GetMessage () {

              return message;

       }

       

       public void Prepare () {

              

       } public

       

       String execute () throws exception{

              if (flag)

                     message = ' You have Selected the checkbox! ";

              else

                     message = "You had not selected!";

              return SUCCESS;

       }

}


res.jsp

<%@ taglib prefix= "ww" uri= "webwork"%>


Iv. Collection-based tagging 1. Select Label

Features: Options Box

Property:

List: [Collection, Map, array, or iterator] expressions, which are used to evaluate the list of options the user wants to select.

ListKey: Expression of key of [String] list, default is key

ListValue: Expression of value of the [String] list, default is value

Headerkey: [String] If the user selects the header option, the value to commit

Headervalue: [String] The contents of the header option that the user sees

Emptyoption: When [Boolean] is set to true, an empty option is placed between the header option and the option to remove from the list

Multiple: When [Boolean] is set to True, allows the user to select multiple values

Size: [String] Specifies the size of the list box

Example 1:

<ww:select label= "City" Name= "City" list= "{' Huhehot ', ' Baotou ', ' Beijing ', ' Shanghai ', ' Tianjin '}"/>

<ww : select label= "Sex" name= "Sex" list= "#{1: ' Man ', 2: ' Woman '}"/>

<ww:select label= "book" Name= "book" list= "{' C ', ' C + + ', ' C # ', ' Java ', ' j2me ', ' ee ', ' Spring ', ' webwork ', ' DWR '} "headerkey=" 0 "headervalue=" Please select a book "/>

<ww:select label= "Books" name= "Books" list= "{' C ', ' C + + ', ' C # ', ' Java ', ' j2me ', ' ee ', ' Spring ', ' webwork ', ' DWR ' } "multiple=" true "size=" 5 "/>

<ww:select label=" Computer "name=" Computer "list=" {' HP ', ' IBM ', ' SAMSUNG ', ' LENOVO '} "emptyoption=" true "/>


Example 2:

index.jsp

<%@ taglib prefix= "ww" uri= "webwork"%>


Initselectaction.java

Package com.example;

Import Com.opensymphony.xwork.ActionSupport;

Import com.opensymphony.xwork.Preparable;

Import java.util.*;

public class Initselectaction extends Actionsupport implements preparable{

    private Directorydao Directorydao;

    Private List directorylist;

    Private Map Directorymap;

    

    public void Setdirectorydao (Directorydao directorydao) {

       This.directorydao = Directorydao;

    }

    

    Public List getdirectorylist () {

       return directorylist;

    }   

    Public Map Getdirectorymap () {

       return directorymap;

    }

    

    public void Prepare () {

       directorylist = Directorydao.getalldirectory ();

       Directorymap = Directorydao.getallmapdirectory ();

    }

    

    Public String Execute () throws exception{

       return SUCCESS;

    }

}


select.jsp
<%@ taglib prefix= "ww" uri= "webwork"%>


Example 3:

index.jsp

<%@ taglib prefix= "ww" uri= "webwork"%>

Package com.example;

Import Com.opensymphony.xwork.ActionSupport;

Import java.util.*;

public class Mulselectaction extends actionsupport{

      private List city = new ArrayList ();

      Private List book = new ArrayList ();

       

       public void Setcity (List city) {

              this.city = city;

       }

       public void Setbook (List book) {

              this.book = Book;

       }

       

       Public List getcity () {

              return city;

       }

       Public List GetBook () {

              return book;

       }

       

       Public String Execute () throws exception{         

              return SUCCESS;

       }

       

       public void Validate () {

              if (city.size () ==0)

                     addfielderror (' City ', "Please select citys!");

              if (Book.size () ==0)

                     addfielderror ("book", "Please select books!");

       }

}


res.jsp
<%@ taglib prefix= "ww" uri= "webwork"%>


2. Radio Label

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.