Monday, June 14, 2010

Annotations used in Stripes{Included widely used annotations}

Dispatch Annotations

@UrlBinding

This annotation can be applied to ActionBean classes to override the generated URL binding for the class with a specific URL. It binds the ActionBean to the specified path so that this bean is invoked in response to that path being requested.

Example:
@UrlBinding("/ValidateLogin.action")
public class ValidateLoginActionBean implements ActionBean {
.
.
}

@HandlesEvent

When applied to an ActionBean method, this annotion denotes that the method should be executed when there is no event name provided in the request. Note: when only one handler method exists, it is deemedto be the default without need for annotation.

@DefaultHandler

When applied to an ActionBean method, this annotion denotes that the method should be executed when there is no event name provided in the request. Note: when only one handler method exists, it is deemed to be the default without need for annotation.


@SessionScope

Causes the ActionBean, the first time it is used within a user's session, to be placed in the user's HttpSession. On subsequent requests the ActionBean will be retrieved from the HttpSession and re-used.


Validation Annotations

@DontValidate

When applied to an event method, this annotation overrides the stripes validation process, skipping the typical required field and field value checks. ActionBean properties are still converted and bound where possible with the use of this annotation.

@Validate

This annotation defines the rules of validation for a single field in an ActionBean.
Example:
@Validate(required = true)
private String username;


@ValidateNestedProperties

This annotation can be used for complex object validation. For example, if your ActionBean has a User member variable, with a username property and a password property, you can apply individual field validation to each of the sub fields of the object. This validation may only include @Validate definitions.
Example:
@ValidateNestedProperties(
Unknown macro: { @Validate(field="username",
required="true"), @Validate(field="password",
required="true")}
)

Data Binding

Stripes performs data binding directly from submitted form fields or query string parameters to the backing ActionBean as described in the overview above. In addition to binding simple types, Stripes also supports binding complex classes.

Example:
public class User {
private String firstname;
private String lastname;
private boolean admin=false;
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getLastname() {
return lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
public boolean isAdmin() {
return admin;
}
public void setAdmin(boolean admin) {
this.admin = admin;
}
}
//Action Bean class
public class MessageActionBean implements ActionBean {
private User user;
public void setUser(User user) {
this.user = user;
}
public User getUser() {
return user;
}
public Resolution saveUser() {
userManager.saveUser(getUser());
}
…etc…

No comments:

Post a Comment