Where Key Will Be Generated In Struts
- Details
- Written by Nam Ha Minh
- Last Updated on 01 August 2019 Print Email
- XML: using type=”required” attribute in <validator> or <field-validator> elements.
- Annotation: using @RequiredFieldValidator annotation type to annotate setter method of the field or action method (plain-validator).
ResetToken - reset the token key Example: Step 1. Action Class where saveToken before JSP Page. First saveToken then forward to your jsp. Upon loading the form, invokes saveToken on the action class to create and store the token key. Struts will store the generated key in request/session. Sets whether or not to generate the dynamic JavaScript. Void: setFormName(java.lang.String formName) Sets the key (form name) that will be used to retrieve a set of validation rules to be performed on the bean passed in for validation. Void: setHtmlComment(java.lang.String htmlComment) Sets whether or not to delimit the JavaScript with html comments. Possible duplicate of Struts 1.3 ActionErrors access – Dave Newton Jul 14 '14 at 14:25 thanks for comment, i am still newbie to this. Could you give me more detail the answer to my code above? (convert to array list) – smftr Jul 15 '14 at 1:09.
1. Struts Required Field Validator XML
Usage:- Field-validator syntax:
- Plain-validator syntax:
Parameters:
Parameter name | Description |
fieldName | Name of the field to validate. Required if using plain validator syntax. |
Struts Required Field Validator XML Examples:
- Field-validator example:
- Plain-validator example:
2. Struts @RequiredFieldValidator Annotation
Usage: Put the @RequiredFieldValidatorannotation before the setter method or action method (in case of using plain-validator) in the following form:@RequiredFieldValidator(param1 = 'param 1 value', param2 = 'param 2 value', ..)
Parameters:
Parameter name | Required | Default value | Description |
Yes | validation error message. | ||
key | No | i18n key for validation error message. | |
messageParams | No | Additional parameters to customize the message. | |
fieldName | No | Specifies field name in case this validator type is plain-validator. | |
shortCircuit | No | false | Whether this validator is short circuit. |
type | No | ValidatorType.FIELD | type of the validator: field-validator (FIELD) or plain-validator (SIMPLE). |
Struts @RequiredFieldValidator Examples:
- Basic field-validator:
- Specifying i18n key for the message:
- Plain-validator (annotating the action method):