The largest Interview Solution Library on the web


Interview Questions
« Previous | 0 | 1 | 2 | 3 | 4 | Next »

41.What is the purpose of @Action annotation?

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 Em ployee extends ActionSupport{
private String nam e;
private int age;
@ Action(value="/em pinfo")
public String execute()
{
return SUCCESS;
}
}

42.What is the purpose of @After annotation?

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 Em ployee extends ActionSupport{
@ After
public void isValid() throws ValidationException {
// validate m odel object, throw exception if failed
}
public String execute() {
// perform secure action
return SUCCESS;
}
}

43.What is the purpose of @Before annotation?

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 Em ployee extends ActionSupport{
@ Before
public void isAuthorized() throws AuthenticationException {
// authorize request, throw exception if failed
}
public String execute() {
// perform secure action
return SUCCESS;
}
}

44.What is the purpose of @BeforeResult annotation?

The @BeforeResult annotation marks a action method that needs to be executed before the result. Return value is ignored.
public class Em ployee extends ActionSupport{
@ BeforeResult
public void isValid() throws ValidationException {
// validate m odel object, throw exception if failed
}
public String execute() {
// perform action
return SUCCESS;
}
}

45.What is the purpose of @ConversionErrorFieldValidator annotation?

This validation annotation checks if there are any conversion errors for a field and applies them if they exist.
public class Em ployee extends ActionSupport{
@ ConversionErrorFieldValidator(m essage = "Default m essage",
key = "i18n.key", shortCircuit = true)
public String getNam e() {
return nam e;
}
}

46.What is the purpose of @DateRangeFieldValidator annotation?

This validation annotation checks that a date field has a value within a specified range.
public class Em ployee extends ActionSupport{
@ DateRangeFieldValidator(m essage = "Default m essage",
key = "i18n.key", shortCircuit = true,
m in = "2005/01/01", m ax = "2005/12/31")
public String getDOB() {
return dob;
}
}

47.What is the purpose of @DoubleRangeFieldValidator annotation?

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 Em ployee extends ActionSupport{
@ DoubleRangeFieldValidator(m essage = "Default m essage",
key = "i18n.key", shortCircuit = true,
m inInclusive = "0.123", m axInclusive = "99.987")
public String getIncom e() {
return incom e;
}
}

48.What is the purpose of @EmailValidator annotation?

This validation annotation checks that a field is a valid e-mail address if it contains a non-empty String.
public class Em ployee extends ActionSupport{
@ Em ailValidator(m essage = "Default m essage",
key = "i18n.key", shortCircuit = true)
public String getEm ail() {
return em ail;
}
}

49.What is the purpose of @ExpressionValidator annotation?

This non-field level validator validates a supplied regular expression.
@ ExpressionValidator(m essage = "Default m essage", key = "i18n.key",
shortCircuit = true, expression = "an OGNL expression" )

50.What is the purpose of @IntRangeFieldValidator annotation?

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 Em ployee extends ActionSupport{
@ IntRangeFieldValidator(m essage = "Default m essage",
key = "i18n.key", shortCircuit = true,
m in = "0", m ax = "42")
public String getAge() {
return age;
}
}

51.What is the purpose of @RegexFieldValidator annotation?

This annotation validates a string field using a regular expression.
@ RegexFieldValidator( key = "regex.field", expression = "yourregexp")

52.What is the purpose of @RequiredFieldValidator annotation?

This validation annotation checks that a field is non-null. The annotation must be applied at method level.
public class Em ployee extends ActionSupport{
@ RequiredFieldValidator(m essage = "Default m essage",
key = "i18n.key", shortCircuit = true)
public String getAge() {
return age;
}
}

53.What is the purpose of @RequiredStringValidator annotation?

This validation annotation checks that a String field is not empty i. e. non − nullwithalength > 0.
public class Em ployee extends ActionSupport{
@ RequiredStringValidator(m essage = "Default m essage",
key = "i18n.key", shortCircuit = true, trim = true)
public String getNam e() {
return nam e;
}
}

54.What is the purpose of @StringLengthFieldValidator annotation?

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 Em ployee extends ActionSupport{
@ StringLengthFieldValidator(m essage = "Default m essage",
key = "i18n.key", shortCircuit = true,
trim = true, m inLength = "5", m axLength = "12")
public String getNam e() {
return nam e;
}
}

55.What is the purpose of @UrlValidator annotation?

This validator checks that a field is a valid URL.
public class Em ployee extends ActionSupport{
@ UrlValidator(m essage = "Default m essage",
key = "i18n.key", shortCircuit = true)
public String getURL() {
return url;
}
}

56.What is the purpose of @Validations annotation?

If you want to use several annotations of the same type, these annotation must be nested within the @Validations annotation.
public class Em ployee extends ActionSupport{
@ Validations(
requiredFields =
{@ RequiredFieldValidator(type = ValidatorType.SIMPLE,
fieldNam e = "custom field",
m essage = "You m ust enter a value for field.")},
requiredStrings =
{@ RequiredStringValidator(type = ValidatorType.SIMPLE,
fieldNam e = "stringisrequired",
m essage = "You m ust enter a value for string.")}
)
public String getNam e() {
return nam e;
}
}

57.What is the purpose of @CustomValidator annotation?

This annotation can be used for custom validators. Use the ValidationParameter annotation to supply additional params.
@ Custom Validator(type ="custom ValidatorNam e", fieldNam e = "m yField")

58.What is the purpose of @Conversion Annotation annotation?

This is a marker annotation for type conversions at Type level. The Conversion annotation must be applied at Type level.
@ Conversion()
public class ConversionAction im plem ents Action {
}

59.What is the purpose of @CreateIfNull Annotation annotation?

This annotation sets the CreateIfNull for type conversion. The CreateIfNull annotation must be applied at field or method level.
@ CreateIfNull( value = true )
private List users;

60.What is the purpose of @Element Annotation annotation?

This annotation sets the Element for type conversion. The Element annotation must be applied at field or method level.
@ Elem ent( value = com .acm e.User )
private List userList;

« Previous | 0 | 1 | 2 | 3 | 4 | Next »


copyright © 2014 - all rights riserved by javatechnologycenter.com