InterviewSolution
This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
What is the purpose of TypeConversion Annotation annotation? |
|
Answer» This annotation annotation is used for class and application wide conversion rules. The TypeConversion annotation can be applied at property and method level. TypeConversion(rule = ConversionRule.COLLECTION, converter = "java.util.String")public void setUsers( List users ) { this.users = users;}
|
|
| 2. |
What is the purpose of KeyProperty Annotation annotation? |
|
Answer» This annotation sets the KeyProperty for type conversion. The KeyProperty annotation must be applied at field or method level. KeyProperty( value = "userName" )protected List<User> users = null; |
|
| 3. |
What is the purpose of Key Annotation annotation? |
|
Answer» This annotation sets the Key for type conversion. The Key annotation must be applied at field or method level. Key( value = java.lang.Long.class )private Map<Long, User> userMap; |
|
| 4. |
What is the purpose of Element Annotation annotation? |
|
Answer» This annotation sets the Element for type conversion. The Element annotation must be applied at field or method level. Element( value = com.acme.User )private List<User> userList; |
|
| 5. |
What is the purpose of CreateIfNull Annotation annotation? |
|
Answer» This annotation sets the CreateIfNull for type conversion. The CreateIfNull annotation must be applied at field or method level. CreateIfNull( value = true )private List<User> users; |
|
| 6. |
What is the purpose of Conversion Annotation annotation? |
|
Answer» This is a marker annotation for type conversions at Type level. The Conversion annotation must be applied at Type level. Conversion() public class ConversionAction implements Action {}
|
|
| 7. |
What is the purpose of CustomValidator annotation? |
|
Answer» This annotation can be used for custom validators. Use the ValidationParameter annotation to supply additional params. CustomValidator(type ="customValidatorName", fieldName = "myField") |
|
| 8. |
What is the purpose of Validations annotation? |
|
Answer» If you want to use several annotations of the same type, these annotation must be nested within the Validations() annotation. public class Employee extends ActionSupport{ Validations( requiredFields = {RequiredFieldValidator(type = ValidatorType.SIMPLE, fieldName = "customfield", message = "You must enter a value for field.")}, requiredStrings = {RequiredStringValidator(type = ValidatorType.SIMPLE, fieldName = "stringisrequired", message = "You must enter a value for string.")} ) public String getName() { return name; }}
|
|
| 9. |
What is the purpose of UrlValidator annotation? |
|
Answer» This validator checks that a field is a valid URL. public class Employee extends ActionSupport{ UrlValidator(message = "Default message", key = "i18n.key", shortCircuit = true) public String getURL() { return url; }}
|
|
| 10. |
What is the purpose of StringLengthFieldValidator annotation? |
|
Answer» This validator checks that a String field is of the right length. It assumes that the field is a String. If neither minLength nor maxLength is set, nothing will be done. public class Employee extends ActionSupport{ StringLengthFieldValidator(message = "Default message", key = "i18n.key", shortCircuit = true, trim = true, minLength = "5", maxLength = "12") public String getName() { return name; }}
|
|
| 11. |
What is the purpose of RequiredStringValidator annotation? |
|
Answer» This validation annotation checks that a String field is not empty (i.e. non-null with a length > 0). public class Employee extends ActionSupport{ RequiredStringValidator(message = "Default message", key = "i18n.key", shortCircuit = true, trim = true) public String getName() { return name; }}
|
|
| 12. |
What is the purpose of RequiredFieldValidator annotation? |
|
Answer» This validation annotation checks that a field is non-null. The annotation must be applied at method level. public class Employee extends ActionSupport{ RequiredFieldValidator(message = "Default message", key = "i18n.key", shortCircuit = true) public String getAge() { return age; }}
|
|
| 13. |
What is the purpose of RegexFieldValidator annotation? |
|
Answer» This annotation validates a string field using a regular expression. RegexFieldValidator( key = "regex.field", expression = "yourregexp") |
|
| 14. |
What is the purpose of IntRangeFieldValidator annotation? |
|
Answer» This validation annotation checks that a numeric field has a value within a specified range. If neither min nor max is set, nothing will be done. public class Employee extends ActionSupport{ IntRangeFieldValidator(message = "Default message", key = "i18n.key", shortCircuit = true, min = "0", max = "42") public String getAge() { return age; }}
|
|
| 15. |
What is the purpose of ExpressionValidator annotation? |
|
Answer» This non-field level validator validates a supplied regular expression. ExpressionValidator(message = "Default message", key = "i18n.key", shortCircuit = true, expression = "an OGNL expression" ) |
|
| 16. |
What is the purpose of EmailValidator annotation? |
|
Answer» This validation annotation checks that a field is a valid e-mail address if it contains a non-empty String. public class Employee extends ActionSupport{ EmailValidator(message = "Default message", key = "i18n.key", shortCircuit = true) public String getEmail() { return email; }}
|
|
| 17. |
What is the purpose of DoubleRangeFieldValidator annotation? |
|
Answer» This validation annotation checks that a double field has a value within a specified range. If neither min nor max is set, nothing will be done. public class Employee extends ActionSupport{ DoubleRangeFieldValidator(message = "Default message", key = "i18n.key", shortCircuit = true, minInclusive = "0.123", maxInclusive = "99.987") public String getIncome() { return income; }}
|
|
| 18. |
What is the purpose of DateRangeFieldValidator annotation? |
|
Answer» This validation annotation checks that a date field has a value within a specified range. public class Employee extends ActionSupport{ DateRangeFieldValidator(message = "Default message", key = "i18n.key", shortCircuit = true, min = "2005/01/01", max = "2005/12/31") public String getDOB() { return dob; }}
|
|
| 19. |
What is the purpose of ConversionErrorFieldValidator annotation? |
|
Answer» This validation annotation checks if there are any conversion errors for a field and applies them if they exist. public class Employee extends ActionSupport{ ConversionErrorFieldValidator(message = "Default message", key = "i18n.key", shortCircuit = true) public String getName() { return name; }}
|
|
| 20. |
What is the purpose of BeforeResult annotation? |
|
Answer» The BeforeResult annotation marks a action method that needs to be executed before the result. Return value is ignored. public class Employee extends ActionSupport{ BeforeResult public void isValid() throws ValidationException { // validate model object, throw exception if failed } public String execute() { // perform action return SUCCESS; }}
|
|
| 21. |
What is the purpose of Before annotation? |
|
Answer» The Before annotation marks a action method that needs to be called before the main action method and the result was executed. Return value is ignored. public class Employee extends ActionSupport{ Before public void isAuthorized() throws AuthenticationException { // authorize request, throw exception if failed } public String execute() { // perform secure action return SUCCESS; }}
|
|
| 22. |
What is the purpose of After annotation? |
|
Answer» The After annotation marks a action method that needs to be called after the main action method and the result was executed. Return value is ignored. public class Employee extends ActionSupport{ After public void isValid() throws ValidationException { // validate model object, throw exception if failed } public String execute() { // perform secure action return SUCCESS; }}
|
|
| 23. |
What is the purpose of Action annotation? |
|
Answer» This is used to decorate the execute() method. The Action method also takes in a value which is the URL on which the action is invoked. public class Employee extends ActionSupport{ private String name; private int age; Action(value = "/empinfo") public String execute() { return SUCCESS; }}
|
|
| 24. |
What is the purpose of Result annotation? |
|
Answer» The result annotations have the name that correspond to the outcome of the execute method. They also contain a location as to which view should be served corresponding to return value from execute(). Result(name = "success", value = "/success.jsp")public class Employee extends ActionSupport{ ...}
|
|
| 25. |
What is the purpose of Results annotation? |
|
Answer» A Results annotation is a collection of results. Under the Results annotation, we can have multiple Result annotations. Results({ Result(name = "success", value = "/success.jsp"), Result(name = "error", value = "/error.jsp")})public class Employee extends ActionSupport{ ...}
|
|