The TreeControl automatically generates an onDrilldown-Event on clicking on a label, to which the programmer can react within the action class.
To react to this event in our example, we include a corresponding Callback method in the ProductTreeBrowseAction. Since we do not wish to implement the business logic here, we forward the event to another action - ProductDisplayAction.
import java.io.IOException;
import javax.servlet.ServletException;
import com.cc.framework.adapter.struts.ActionContext;
import com.cc.framework.adapter.struts.FWAction;
import com.cc.framework.ui.control.ControlActionContext;
import com.cc.framework.ui.control.TreeControl;
import com.cc.sampleapp.common.Forwards;
public class ProductTreeBrowseAction extends FWAction {
/**
* @see com.cc.framework.adapter.struts.FWAction#doExecute(ActionContext)
*/
public void doExecute(ActionContext ctx)
throws IOException, ServletException {
try {
ProductGroupDsp data = DBProduct.fetch();
TreeControl products = new TreeControl();
products.setDataModel(data);
ctx.session().setAttribute("products", products);
}
catch (Throwable t) {
ctx.addGlobalError("Error: ", t);
}
// Display the Page with the Tree
ctx.forwardToInput();
}
// ------------------------------------------------
// Tree-Control Event Handler
// ------------------------------------------------
/**
* This Method is called when the TreeLabel is clicked
* In our Example we switch to the DetailView, which shows
* more Information about the node.
* @param ctx ControlActionContext
* @param key UniqueKey, as created in the Datamodel
*/
public void products_onDrilldown(ControlActionContext ctx, String key) {
ctx.forwardByName(Forwards.DRILLDOWN, key);
}
}
The name of the CallBack is composed of the Property name of the TreeControl - the name of the Bean - and the event that has occurred. Since the TreeControl was saved in the Session under the name "products", the name of the CallBack method is products_onDrilldown.
back |
continue
|