Thanks Allan! I'm forwarding this to the user list so others can benefit.
Matt
---------- Forwarded message ----------
From: Allan Ang <[EMAIL PROTECTED]>
Date: Mar 15, 2007 11:17 PM
Subject: [appfuse-dev] Checkbox to delete records in default generated tables
To: [EMAIL PROTECTED]
Hi all,
Here's some code that allows users to select records in the default table
view using checkboxes and delete them. (I use the struts, spring, hibernate
combo). Hope someone can find this useful (if it hasn't been posted already)
Checkbox decorator class
========================
public class CheckboxIDDecorator extends TableDecorator{
public CheckboxIDDecorator(){
super(); //bootstrapping
}
public String getIdArray(){
String id="";
Object obj = this.getCurrentRowObject();
Class theClass = obj.getClass();
try {
Method theMethod =
theClass.getMethod("getId"); //all model classes must
use getId for this
to work
id=String.valueOf((Long)theMethod.invoke(obj,null));
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NoSuchMethodException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String value = "<INPUT TYPE=\"CHECKBOX\" NAME=\"idArray\"
VALUE=\""+ id
+"\">";
return value;
}
}
===================
added this in metadata/templates/struts_form.xdt
====================
protected String[] idArray;
public String[] getIdArray(){
return this.idArray;
}
public void setIdArray(String[] idArray){
this.idArray = idArray;
}
====================
added in the appgen templates
List_jsp.xdt
============
<html:submit styleClass="button" property="method.delete"
onclick="bCancel=true; return confirmDelete
('<XDtForm:className/>')">
<fmt:message key="button.delete"/>
</html:submit>
in the c:set buttons tag and
<html:form action="<XDtForm:classNameLower/>s" method="post"
styleId="<XDtForm:classNameLower/>Form"
onsubmit="return validate<XDtForm:className/>Form(this)">
Action.xdt
==========
added this in the delete method
if(<XDtForm:className/>Form.getIdArray()!=null){
for(int i=0;i<<XDtForm:className/>Form.getIdArray().length;i++){
mgr.remove<XDtForm:className/>(<XDtForm:classNameLower/>Form.getIdArray()[i]);
}
}else{
mgr.remove<XDtForm:className/>(<XDtForm:classNameLower/>Form.<XDtMethodEx:idField
getType="getterName"/>());
}
--
View this message in context:
http://www.nabble.com/Checkbox-to-delete-records-in-default-generated-tables-tf3412683s2369.html#a9508932
Sent from the AppFuse - Dev mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--
http://raibledesigns.com
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]