How to Make Mailbox Style Multiple Checkboxes and Pre-select

Form bean:

public class MyForm {
  private String[] selectedIds;

  public String[] getSelectedIds() {
    return this.selectedIds;
  }
  public void setSelectedIds(String[] ids) {
    this.selectedIds = ids;
  }
}

Action:

public class MyAction extends ActionSupport {
  MyForm form;
  List<String> completeList;

  public String getForm() {
    return this.form;
  }

  public List<String> getCompleteList() {
    return this.completeList;
  }
}

JSP:

<s:iterator value="completeList" var="id">
<tr>
  <td><s:checkbox name="form.selectedIds" fieldValue="%{id}" id="id-%{id}" value="%{id in form.selectedIds}" /></td>
</tr>
</s:iterator>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s