| 
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectnet.sf.click.extras.control.LinkDecorator
Provides a table column AbstractLink and ActionButton Decorator.
  
  | 
 
public class EditTable extends BorderPage { public Table table = new Table(); public ActionLink editLink = new ActionLink("edit", "Edit", this, "onEditClick"); public ActionLink deleteLink = new ActionLink("delete", "Delete", this, "onDeleteClick"); public EditTable() { table.addColumn(new Column("name")); table.addColumn(new Column("email")); table.addColumn(new Column("holdings")); table.addColumn(new Column("dateJoined")); Column column = new Column("Action"); ActionLink[] links = new ActionLink[]{editLink, deleteLink}; column.setDecorator(new LinkDecorator(table, links, "id")); table.addColumn(column); deleteLink.setAttribute("onclick", "return window.confirm('Please confirm delete');"); } public boolean onEditClick() { Integer id = editLink.getValueInteger(); Customer customer = getCustomerService().getCustomer(id); .. } public boolean onDeleteClick() { Integer id = deleteLink.getValueInteger(); getCustomerService().deleteCustomer(id); return true; } public void onRender() { List customers = getCustomerService().getCustomersSortedByName(12); table.setRowList(customers); } }The LinkDecorator class automatically supports table paging.
renderActionLink
 or renderActionButton.
 
 In the example below we want to send both the state and postCode
 parameters to the AddressPage:
 
 public class SelectPostCode extends BorderPage {
     private Table table = new Table("table");
     public SelectPostCode() {
         ...
         PageLink selectPostCode = new PageLink("select", AddressPage.class);
         Column action = new Column("action");
         String idProperty = "postCode";
         LinkDecorator decorator = new LinkDecorator(table, selectPostCode, idProperty) {
             protected void renderActionLink(HtmlStringBuffer buffer, AbstractLink link, Context context, Object row, Object value) {
                 // We want to add the PostCode "state" as an extra parameter
                 // to the action link
                 link.setParameter("state", ((PostCode) row).getState());
                 // You can manipulate the link parameters as needed, and
                 // even remove the default idProperty parameter.
                 // Object currentValue = link.getParameters().remove(this.idProperty);
                 // NB we invoke the super implementation here for default rendering to continue
                 super.renderActionLink(buffer, link, context, row, value);
             }
         }
         action.setDecorator(decorator);
         table.addColumn(action);
     };
     public void onRender() {
         table.setRowList(getPostCodeService().getPostCodes());
     }
 } 
 In the above example the LinkDecorator will extract the idProperty value ("state")
 for each object in the table.
 The PageLinks will render as follows:
 <a href="/mycorp/address-page.htm?postCode=6089&state=NSW>Select</a>This class was inspired by Richardo Lecheta's ViewDecorator design pattern.
ActionLink, 
PageLink, 
Serialized Form| Field Summary | |
protected  ActionButton[] | 
buttonsArray
The array of ActionButtons to render.  | 
protected  String | 
idProperty
The row object identifier property.  | 
protected  AbstractLink[] | 
linksArray
The array of AbstractLinks to render.  | 
protected  String | 
linkSeparator
The link separator string, default value is " | ".  | 
protected  Map | 
methodCache
The method cached for rendering column values.  | 
protected  Table | 
table
The table to render the links for.  | 
| Constructor Summary | |
LinkDecorator(Table table,
              AbstractLink[] links,
              String idProperty)
Create a new AbstractLink table column Decorator with the given AbstractLinks array and row object identifier property name.  | 
|
LinkDecorator(Table table,
              AbstractLink link,
              String idProperty)
Create a new AbstractLink table column Decorator with the given actionLink and row object identifier property name.  | 
|
LinkDecorator(Table table,
              ActionButton[] buttons,
              String idProperty)
Create a new ActionButton table column Decorator with the given ActionButtons array and row object identifier property name.  | 
|
LinkDecorator(Table table,
              ActionButton button,
              String idProperty)
Create a new AbstractLink table column Decorator with the given ActionButton and row object identifier property name.  | 
|
LinkDecorator(Table table,
              List controls,
              String idProperty)
Create a new table column Decorator with the given list of AbstractLinks or ActionButtons and row object identifier property name.  | 
|
| Method Summary | |
 String | 
getLinkSeparator()
Return the link separator string.  | 
protected  void | 
initButton(ActionButton button,
           Context context,
           Object value)
Initialize the button value and parameters.  | 
protected  void | 
initLink(AbstractLink link,
         Context context,
         Object value)
Initialize the link value and parameters.  | 
 String | 
render(Object row,
       Context context)
Render the given row object using the links or buttons.  | 
protected  void | 
renderActionButton(HtmlStringBuffer buffer,
                   ActionButton button,
                   Context context,
                   Object row,
                   Object value)
Render the button to the specified buffer.  | 
 String | 
renderActionButtons(Object row,
                    Context context)
Render the given row object using the actionButtons array.  | 
protected  void | 
renderActionLink(HtmlStringBuffer buffer,
                 AbstractLink link,
                 Context context,
                 Object row,
                 Object value)
Render the link to the specified buffer.  | 
 String | 
renderActionLinks(Object row,
                  Context context)
Render the given row object using the actionLinks array.  | 
 void | 
setLinkSeparator(String value)
Set the link separator string with the given value.  | 
| Methods inherited from class java.lang.Object | 
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait | 
| Field Detail | 
protected String idProperty
protected AbstractLink[] linksArray
protected ActionButton[] buttonsArray
protected String linkSeparator
protected Table table
protected transient Map methodCache
| Constructor Detail | 
public LinkDecorator(Table table,
                     AbstractLink link,
                     String idProperty)
 Table table = new Table("table");
 public void onInit() {
     ... // setup other columns
     ActionLink selectState = new ActionLink("select");
     Column action = new Column("action");
     String idProperty = "state";
     LinkDecorator decorator = new LinkDecorator(table, selectState, idProperty);
     action.setDecorator(decorator);
     table.addColumn(action);
     ...
 }
 public void onRender() {
     // Populate the table rows with post code instances
     table.setRowList(getPostCodeService().getPostCodes());
 } 
 In the above example the LinkDecorator will extract the idProperty value
 ("state") from each PostCode instance in the table.
 
 The idProperty value will also be used as the name of the
 request parameter. In this example the idProperty value is "state" thus
 the request parameter name will also be "state".
 
 For the PostCode "NSW" the PageLink will render as follows:
 <a href="/mycorp/postcodes.htm?state=NSW>Select</a>
table - the table to render the links forlink - the AbstractLink to renderidProperty - the row object identifier property name
public LinkDecorator(Table table,
                     AbstractLink[] links,
                     String idProperty)
table - the table to render the links forlinks - the array of AbstractLinks to renderidProperty - the row object identifier property nameLinkDecorator(net.sf.click.control.Table, net.sf.click.control.AbstractLink, java.lang.String)
public LinkDecorator(Table table,
                     ActionButton button,
                     String idProperty)
table - the table to render the links forbutton - the ActionButton to renderidProperty - the row object identifier property nameLinkDecorator(net.sf.click.control.Table, net.sf.click.control.AbstractLink, java.lang.String)
public LinkDecorator(Table table,
                     ActionButton[] buttons,
                     String idProperty)
table - the table to render the links forbuttons - the array of ActionButtons to renderidProperty - the row object identifier property nameLinkDecorator(net.sf.click.control.Table, net.sf.click.control.AbstractLink, java.lang.String)
public LinkDecorator(Table table,
                     List controls,
                     String idProperty)
table - the table to render the links forcontrols - the list of AbstractLink or ActionButtons to renderidProperty - the row object identifier property nameLinkDecorator(net.sf.click.control.Table, net.sf.click.control.AbstractLink, java.lang.String)| Method Detail | 
public String getLinkSeparator()
public void setLinkSeparator(String value)
value - the link separator string value
public String render(Object row,
                     Context context)
render in interface Decoratorrow - the row object to rendercontext - the request context
Decorator.render(java.lang.Object, net.sf.click.Context)
public String renderActionLinks(Object row,
                                Context context)
initLink(net.sf.click.control.AbstractLink, net.sf.click.Context, java.lang.Object).
 
 This method also renders each link in the array by
 invoking renderActionLink(net.sf.click.util.HtmlStringBuffer, net.sf.click.control.AbstractLink, net.sf.click.Context, java.lang.Object, java.lang.Object).
row - the row object to rendercontext - the request context
public String renderActionButtons(Object row,
                                  Context context)
initButton(net.sf.click.control.ActionButton, net.sf.click.Context, java.lang.Object).
 
 This method also renders each button in the array by
 invoking renderActionButton(net.sf.click.util.HtmlStringBuffer, net.sf.click.control.ActionButton, net.sf.click.Context, java.lang.Object, java.lang.Object).
row - the row object to rendercontext - the request context
protected void renderActionLink(HtmlStringBuffer buffer,
                                AbstractLink link,
                                Context context,
                                Object row,
                                Object value)
buffer - the specified buffer to render the link output tolink - the link to rendercontext - the request contextrow - the table row being renderedvalue - the value of the link
protected void renderActionButton(HtmlStringBuffer buffer,
                                  ActionButton button,
                                  Context context,
                                  Object row,
                                  Object value)
buffer - the specified buffer to render the button output tobutton - the button to rendercontext - the request contextrow - the table row being renderedvalue - the value of the buttonrenderActionLink(net.sf.click.util.HtmlStringBuffer, net.sf.click.control.AbstractLink, net.sf.click.Context, java.lang.Object, java.lang.Object)
protected void initLink(AbstractLink link,
                        Context context,
                        Object value)
link - the link to initializecontext - the request contextvalue - the value of the link
protected void initButton(ActionButton button,
                          Context context,
                          Object value)
button - the button to initializecontext - the request contextvalue - the value of the button
  | 
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||