div>
td> tr>
form>
TABLE>
body>
html>
Xwork.xml:
"http://www.opensymphony.com/xwork/xwork-1.0.dtd">
eX01-index.jsp result>
eX01-surcess.jsp result>
action>
package>
xwork>
FormProcessingAction.java:
Package lesson04_01_01;
Import com.opensymphony.xWork.Actionsupport; public class formProcessing Extends ActionSupport {
PRIVATE STRING CHECKBOX;
PRIVATE STRING FILE;
PRIVATE STRING HIDDEN
PRIVATE STRING Password;
PRIVATE STRING RADIO;
PRIVATE STRING SELECT;
PRIVATE STRING TEXTAREA;
PRIVATE STRING TEXTFIELD;
Public string getCheckbox () {return checkbox;}
PUBLIC STRING GETFILE () {Return File;
Public string gethidden () {return hidden;
Public string getpassword () {return password;}
Public string getradio () {return radio;}
Public string getselect () {return select;}
Public string gettextArea () {returnization textarea;}
Public string gettextfield () {returnization;
Public void setCheckbox (string checkbox) {this.checkbox = checkbox;}
Public void setfile (string file) {this.file = file;}
Public void sethidden (string hidden) {this.hidden = hidden;}
Public void setpassword (string password) {this.password = password;}
Public void setradio (string radio) {this.radio = radio;}
Public void setselect (string select) {this.select = select;}
Public void settextAREA (String textarea) {this.textarea = textarea;}
Public void settextfield (string textfield) {this.textfield = textfield;
Public String Execute () throws exception {
RETURN SUCCESS;
}
}
FormProcessingAction-Validation.xml:
"http://www.opensymphony.com/xwork/xwork-validator-1.0.dtd">
please, Check the checkbox. message>
Field-Validator>
field>
please select a file. message>
Field-Validator>
field>
please type something in the password field. message>
Field-Validator>
field>
please select a radio button. message>
Field-Validator>
field>
please select an option from the list. message>
Field-Validator>
field>
please type something in the text area. message>
Field-Validator>
field>
please type something in the text field. message>
Field-Validator>
field>
validators>
EX01-SUCCESS.JSP:
<% @ Taglib Uri = "Webwork" prefix = "ww"%>
Webwork Tutorial - Lesson 4.1.1 - Example 1 Title>
hEAD>
ui form tags example result: p>
Checkbox: li>
file: li>
hidden: li> password: li>
Radio: li>
select: li>
textarea: li>
textfield: li>
ul>
body>
html>
The default layout of form is a table, the left is a label, and the right is a single domain. You can create your own layout using the template system.
Note the reference to the ValidationWorkflowstack in the Action configuration. This allows WebWork to verify the parameters passed to the Action according to the verification profile (formProcessingAction-Validation.xml) on the same location as the Action class. If there is an illegal parameter, the webwork will block the execution of the Action, and the request assigned INPUT results page will display the error message to the corresponding form field.
(2) Template system
WebWork uses the Velocity template system to present the actual HTML output for all UI tags. The default implementation of all templates is included in the WebWork-2.1.jar / template / xhtml directory. These templates can be edited or replaced to customize HTML output results.
If you want to use a different layout to display UI components, you can:
l Edit or replace the file in / template / xhtml directory
l Editing the web.ui.Theme of the Webwork.properties file (to be placed in / web-inf / class directory), pointing to the template location.
l Use the tagged the or template property to specify a template location for a single tag.
Below is an example of using the third method:
EX02.JSP:
<% @ Taglib Uri = "Webwork" prefix = "ww"%>
Webwork Tutorial - Lesson 4.1.1 - Example 2 Title>
hEAD>
template change EXAMPLE: P>
FieldValue = "'CheckBox_Value'" "Theme =" / files / templates / components "/> p>
p>
body>
html>
/files/templates/components/checkbox.vm:
Name = "$! Webwork.htmlencode ($ Parameters.name)"
Value = "$! Webwork.htmlencode ($ Parameters.fieldValue"
#if ($ parameters.namevalue) checked = "checked" #end
#if ($ Parameters.Disabled == True) Disabled = "Disabled" #end
#if ($ parameters.tabindex) TabINDEX = "$! Webwork.htmlencode ($ Parameters.taBindex) #end
#if ($ Parameters.onChange) οnchange = "$! Webwork.htmlencode ($ Parameters.onChange)" #end
#if ($ Parameters.id) ID = "$! Webwork.htmlencode ($ Parameters.ID)" #end
/>
$! Webwork.htmlencode ($ Parameters.label)
div>
/files/templates/components/mytextfield.vm:
Name = "$! Webwork.htmlencode ($ Parameters.name)"
#if ($ parameters.size) size = "$! Webwork.htmlencode ($ Parameters.size) #end
#if ($ parameters.maxlength) maxlength = "$! Webwork.htmlencode ($ Parameters.maxlength)" #end
#if ($ parameters.namevalue) value = "$! Webwork.htmlencode ($ parameters.namevalue)" #end
#if ($ Parameters.Disabled == True) Disabled = "Disabled" #end
#if ($ Parameters.Readonly) Readonly = "Readonly" #end
#if ($ Parameters.onkeyup) οnkeyup = "$! Webwork.htmlencode ($ Parameters.onkeyup) #END
#if ($ Parameters.tabindex) TabINDEX = "$! Webwork.htmlencode ($ Parameters.Tabindex) # End # f ($ Parameters.onChange) οnchange =" $! Webwork.htmlencode "#end
#if ($ Parameters.id) ID = "$! Webwork.htmlencode ($ Parameters.ID)" #end
/>
$! Webwork.htmlencode ($ Parameters.label)
div>
EX02.JSP is processed HTML output results:
Webwork Tutorial - Lesson 4.1.1 - Example 2 Title>
hEAD>
template change EXAMPLE: P>
Name = "checkbox"
Value = "Checkbox_Value"
/>
A checkbox
div> p>
Name = "textfield"
/>
A Text Field
div> p>
body>
html>
(3) Creating a custom UI component
Sometimes the Webwork's UI component can't meet your needs, you can create custom components. You can create a layout clean, an error check, reusable custom component recommended using the webwork recommended method.
To create a custom component, just create a Velocity template for it, use the tag to place it in the web page, specify the template location using the template property. To pass parameters to the template, you can use the tag in the tag. The following example creates a custom Date domain:
EX03.JSP:
<% @ Taglib Uri = "Webwork" prefix = "ww"%>
Webwork Tutorial - Lesson 4.1.1 - Example 3 Title>
hEAD>
Custom Component Example: P>
ww: component>
p>
body>
html>
/files/templates/components/datefield.vm:
#set ($ name = $ tag.params.get ('name'))
#SET ($ size = $ tag.params.get ('size'))
#set ($ YEARSIZE = $ SIZE * 2)
$ tag.params.get ('label'):
/
/
(dd / mm / yyyy)
EX03.JSP is processed HTML output results:
Webwork Tutorial - Lesson 4.1.1 - Example 3 Title>
hEAD>
Custom Component Example: P>
Date:
/
/
(dd / mm / yyyy)
p>
body>
html>
转载请注明原文地址:https://www.9cbs.com/read-6429.html