3/14/2008

File download in Click Framework

Click Framework provides FileField to upload file, however Click does not provide any support for file downloading. I made AbstractDownloadPage to download file.

Usage:

 public class SampleDownloadPage extends AbstractDownloadPage {
  public SampleDownloadPage(){
    setFileName("sample.txt");
    setContents(SampleDownloadPage.class.getResourceAsStream("sample.txt"));
  }
} 

This page class does not have a template because response is written by this class. So auto-mapping does not work for file download pages. The extended page class have to be registered to click.xml.

3/10/2008

Click Framework + LiveValidation

Click controls provide JavaScript validation, but they are not easy to customize. Now I'm writing JavaScript validation framework for Click using LiveValidation. In the page class, ready the LivaValiator control like below:

Form form = new Form("form");
form.add(new TextField("name", true));
form.add(new PasswordField("password", true));
form.add(new Submit("login"));

addControl(new LivaValidator("validator", form));

In the page template, generates LiveValidation JavaScript code by the LiveValidator control:

<body>
  $form
  <script type="text/javascript">
    $validator
  </script>
</body>

We can also add customized validation rules by use of Validate.Custom.

3/09/2008

OVal: The simple validation framework for Java

OVal is the simple validation framework for Java. You can specify validation rules using annotations.

public class Person {
  @NotNull
  public String name;
}

Usage:

Validator v = new Validator();

Person p = new Person();
for(ConstraintViolation error: v.validate(p)){
  System.out.println(error.getMessage());
}
OVal can switch validation rules by profiles.
public class Person {
  @NotNull(profiles={"profile1"})
  public String name;
  
  @NotNull(profiles={"profile1", "profile2"})
  public String email;
}

Switch profiles like following:

// Enable all profiles
v.enableAllProfiles();
// Enable a specified profile
v.enableProfile("profile1");

// Disable all profiles
v.disableAllProfiles();
// Disable a specified profile
v.disableProfile("profile1");