Sunday, January 31, 2010

Working with GWT, beginning with the Getting Started tutorial, trying to deploy Bookstore to GAE in one weeked! Almost got stumped adding ClickHander to a Grid, thankfully someone posted this solution,

// listen for mouse events on the results grid
resultsGrid.addClickHandler(new ClickHandler() {
   public void onClick(ClickEvent event) {
      final HTMLTable table = (HTMLTable) event.getSource();
      final HTMLTable.Cell cell = table.getCellForEvent(event);
      // cell.getCellIndex() COL
      // cell.getRowIndex() ROW
   });

Very cool!

Sunday, April 19, 2009

Alternating row colors using Struts2
<s:iterator value="results" status="status">
<s:if test="#status.odd">
<tr bgcolor="#F8ECE0">
</s:if>
<s:else>
<tr>
</s:else>

Saturday, February 21, 2009

Struts2 nested checkbox tag inside iterator

Using the s:iterator tag and status attribute it's possible to display and update values of complex types within a collection.

For example, using an iterator tag,

<s:iterator value="results" status="status">

<s:hidden value="%{product.sku}" name="results[%{#status.index}].product.sku" />

<input type="checkbox" name="results[<s:property value="%{#status.index}" />].selected" <s:property value="%{selected}" />>

</s:iterator>

within a form tag, the submit action will update the list of results in the Action class, where my action class has

protected List<ProductBean> results;

with getters and setters, and my ProductBean has,

private Product product;

with getters and setters, and

private boolean selected;

/**
* @return the selected
*/
public String isSelected() {
    return selected ? "checked" : "";
}

/**
* @param selected the selected to set
*/
public void setSelected(String selected) {
    this.selected = selected == null || selected.equals("") ? false : true;
}

Note: If you find something useful, please leave a comment, thanks!