I also forgot where I found it as follows: Three files: ValidTextArea.java:
Java code:
Package COM.
Tomxp.
Web.
Components.
Valid;
Import org.
Apache.
Tapestry.
ApplicationRuntimeException;
Import org.
Apache.
Tapestry.
IFORM;
Import org.
Apache.
Tapestry.
IMarkupwriter;
Import org.
Apache.
Tapestry.
IREQuestCYCLE;
Import org.
Apache.
Tapestry.
Tapestry;
Import org.
Apache.
Tapestry.
Form.
TEXTAREA;
Import org.
Apache.
Tapestry.
Valid.
IvalidationDelegate;
Import org.
Apache.
Tapestry.
Valid.
Ivalidator;
Import org.
Apache.
Tapestry.
Valid.
ValidatorException;
/ ** * @Author peter butler * /
public
Abstract
Class ValidTextArea
Extends
Textarea
{
WritererRordecoator myWriter =
New WritererRordecorator
(this
);
Public ValidTextArea
(
)
{
Super
(
);
}
public
Abstract IvaliDator getValidator
(
);
public
Abstract
String getDisplayName
(
);
protected
Void rendercomponent
(ImarkupWriter Writer, Irequestcycle Cycle
)
{
IFORM FORM = Getform
(Cycle
);
IvalidationdeLegate delegate = form.
Getdelegate
(
);
IF
(Delegate ==
NULL
)
Throw
New ApplicationRuntimeException
Tapestry.
Format
"" ValidTextarea.
No-delegate, getExtendedidID
(
Getform
(
).
GetExtendedidID
(
)
), THIS,
NULL,
NULL
);
Ivalidator validator = getValidator
(
);
IF
(Validator ==
NULL
)
Throw TapeStry.
CreateRequidParameterException
(this, "validator"
);
Boolean rendering =! cycle.
Isrewinding
(
);
ImarkupWriter Superwriter;
IF
(Rendering)
)
{
Delegate.
Writeprefix
(Writer, Cycle, This, Validator
);
MYWRITER.
init
(Writer, Delegate, Validator, Cycle
);
Superwriter = mywriter;
}
Else
{
Superwriter = Writer;}
SUPER.
Rendercomponent
(SuperWriter, Cycle
);
String name = getName
(
);
IF
(! RENDERING &&! Isdisabled
(
)
)
{
String value = cycle.
GetRequestContext
(
).
GetParameter
(Name)
);
UpdateValue
(Value
);
}
IF
(Rendering)
)
{
Delegate.
Writesuffix
(Writer, Cycle, This, Validator
);
MYWRITER.
Clear
(
);
}
}
protected
Void UpdateValue
(
String Value
)
{
Object ObjectValue =
NULL;
IvalidationdeLegate delegate = getform
(
).
Getdelegate
(
);
Delegate.
RecordfieldInputValue
(Value
);
Try
{
ObjectValue = GetValidator
(
).
TOOBJECT
(this, Value
);
}
Catch
(ValidatorException EX
)
{
Delegate.
Record
(EX
);
Return;
}
SetValue
(
(
String
) ObjectValue
);
}
}
ValidTextArea.jwc
Java code:
XML Version = "
1.
0 "encoding =" UTF-
8 "?>
DOCTYPE Component-Specification
PUBLIC "-
// Apache Software Foundation // TapeStry Specification 3.0 // en "
"http:
//jakarta.apache.org/tapestry/dtd/tapestry_3_0.dtd ">
//spindle.sourceforge.net ->
Class = "COM. Tomxp. Web. Components. Valid. ValidTextArea "allow-body =" no "> A Multi-Line Valid Text Area. description> Converts Value to A String and Parses Strings Back Into Object Values. description> parameter> Name Used by FieldLabel and when Generating Validation Error Messages. description> parameter> component-specification> Java code: Package COM. Tomxp. Web. Components. Valid; Import org. Apache. Tapestry. IMarkupwriter; Import org. Apache. Tapestry. IREQuestCYCLE; Import org. Apache. Tapestry. Form. IFORMComponent; Import org. Apache. Tapestry. Valid. IvalidationDelegate; Import org. Apache. Tapestry. Valid. Ivalidator; / ** * @Author peter butler * / public Class WritererRordecorator Implements IMARKUPWRITER { PRIVATE IMARKUPWRITER ACTUAL; Private ivalidationdelegate delegate; Private ivalidator validator; Private IREQUESTCYCLE CYCLE; Private iFormComponent Field; Public WritererRordecorator (IFormComponent Field ) { THIS. Field = field; } public Voidin (ImarkupWriter Actual, IvalidationDelegate Delegate, Ivalidator Validator, IREQuestCYCLE CYCLE ) { THIS. Actual = actual; THIS. Delegate = delegate; THIS. Validator = validator; THIS. CYCLE = cycle; } public Void Clear ( ) { THIS. Actual = NULL; THIS. Delegate = NULL; THIS. Validator = NULL; THIS. CYCLE = NULL; } public Void Attribute ( String Name, Int Value ) { Actual. Attribute (Name, Value ); } public Void Attribute ( String Name, Boolean Value ) { Actual. Attribute (Name, Value ); } public Void Attribute ( String Name, String Value ) { Actual. Attribute (Name, Value ); } public Void AttributeRaw ( String Name, String Value ) { Actual. AttributeRaw (Name, Value ); } public Void Begin ( String name ) { Actual. Begin (Name) ); Validator. RenderValidatorControl (Field, this, cycle ); Delegate. WriteaTributes (this, Cycle, Field, Validator ); } public Void Beginempty ( String name ) { Actual. Beginempty (Name) ); Validator. RenderValidatorControl (Field, this, cycle ); Delegate. WriteaTributes (this, Cycle, Field, Validator ); } public Boolean Checkerror ( ) { Return Actual. Checkerror ( ); } public Void Close ( ) { Actual. Close ( ); } public Void ClosetAg ( ) { Actual. Closetag ( ); } public Void Comment ( String Value ) { Actual. Comment (Value ); } public Void end ( ) { Actual. end ( ); } public Void end ( String name ) { Actual. end (Name) ); } public Void Flush ( ) { Actual. Flush ( ); } Public IMARKUPWRITER GETNESTEDWRITER ( ) { Return Actual. GetnestedWriter ( ); } public Void Print (char) [ ] DATA, Int offset, INT Length ) { Actual. Print (Data, Offset, Length ); } public Void Print (Char Value) ) { Actual. Print (Value ); } public Void Print ( Int Value ) { Actual. Print (Value ); } public Void Print ( String value) { Actual. Print (Value ); } public Void Println ( ) { Actual. PRINTLN ( ); } public Void Printraw (char) [ ] buffer, Int offset, INT Length ) { Actual. PRINTRAW (Buffer, Offset, Length ); } public Void Printraw ( String Value ) { Actual. PRINTRAW (Value ); } public String getContentType ( ) { Return Actual. GetContentType ( ); } } For TextArea's length verification, only write components yourself. Especially when the Tapestry's FieldLabel Validator is already using Tapestry, if only simply written JS is written in HTML, there will be a JavaScript integration that cannot be dynamically generated by Tapestry. . . I saw the code of Ewaves stickers, and I didn't seem to posted. Script files. I have written my own components, although it is totally different from the code, but .script file can be universal, it can automatically generate dynamic JavaScript. Java code: XML Version = " 1. 0 "Encoding =" GBK "?>
Script, V 1. 5 2004 / 03 / 09 18: twenty three: 50 HLSHIP EXP $ -> DOCTYPE SCRIPT Public " // Apache Software Foundation // TapeStry Script Specification 3.0 // en " "http: //jakarta.apache.org/tapestry/dtd/script_3_0.dtd ">
Input Symbols: TEXTAREAScript: The TextareAscript Component. Output Symbols: FormValidateFunction The name of a form validator function That Validates the fields. -> Class = "COM. CDMCS. Tapestry. JWC. TEXTAREAScript "/> RequiredMessage "/> NumberLengthmessage "/> Document. $ {TextareAscript. Form. Name }. $ {Name } let> Validate_ $ {Name } let>
[Cdata [ Function $ {FormValidateFunction } ( ) { Var Field = $ {Basename } Var keycode = window. Event. Keycode; IF ($ {NumberFormatenable } &&! Field. Value. Match (/ ^ / d { 11 } $ / ) ) { IF Field. Value. Length == 0 ) Return True; Return Validator_INVALID_FIELD (Field, "$ {NumberLengthMessage " ); } IF ($ {Required } && field. Value. Length == 0 ) { Return Validator_INVALID_FIELD (Field, "$ {RequiredMessage " ); } IF ($ {Required } && field. Value. Length <$ {minimumlength } ) { Return Validator_INVALID_FIELD (Field, "$ {MINIMUMLENGTHMESSAGE " ); } IF ($ {Required } &&field.value. Length> $ {MaxImumlength } ) { Return Validator_INVALID_FIELD (Field, "$ {MaximumLengthMessage " ); } Return True; } ] ]> body> script> I have a function of this code. It is the 15-bit mobile phone number, because 11 is much longer than Tapestry's NumberValidator range, there is no way, I have to write it, I don't want to be lazy.