You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by Apache Wiki <wi...@apache.org> on 2006/03/19 04:12:42 UTC
[Jakarta-tapestry Wiki] Update of "PropertySelectionForAll" by diogenes
Dear Wiki user,
You have subscribed to a wiki page or wiki category on "Jakarta-tapestry Wiki" for change notification.
The following page has been changed by diogenes:
http://wiki.apache.org/jakarta-tapestry/PropertySelectionForAll
The comment on the change is:
sorry for my english, I´m Argentinian.Please if any one may be fix this notes
New page:
following we will be include a simple sample for use a property selection
The first step is desig a html template. In this template you must include a tapestry tag like this.
{{{
....
<span jwcid="@PropertySelection" value="ognl:propertyName" model="ognl:collectionName"></span>
....
}}}
then you must define a class, this class must implement the IPropertySelectionModel Interface.
{{{
import java.io.Serializable;
import org.apache.tapestry.form.IPropertySelectionModel;
public class SelectionObject implements IPropertySelectionModel, Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private Object[] core;
private String methodName;
private String getMethodName() {
return methodName;
}
private void setMethodName(String methodName) {
this.methodName = methodName;
}
private Object[] getCore() {
return core;
}
private void setCore(Object[] core) {
this.core = core;
}
public SelectionObject(Object[] data,String method) {
this.setCore(data);
this.setMethodName(method);
}
public SelectionObject(Object[] data) {
this.setCore(data);
this.setMethodName("toString");
}
public int getOptionCount() {
return this.getCore().length;
}
public Object getOption(int arg0) {
return this.getCore()[arg0];
}
public String getLabel(int arg0) {
try {
return this.getCore()[arg0].getClass().getMethod(this.getMethodName(),new Class[]{}).invoke(this.getCore()[arg0],new Object[]{}).toString();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public String getValue(int arg0) {
return Integer.toString(arg0);
}
public Object translateValue(String arg0) {
int index;
index = Integer.parseInt(arg0);
return this.getCore()[index];
}
}
}}}
this class can contein any object's cain. Please see the constructor with 2 parameters. the first parameter is an array the objects. this objects will be assign to the property and the second parameter, is a String with the method name for invoke and obteing the representation for the user in the combo box.
And then in you Page Implementation you must include a code like this.
{{{
public abstract class YourPage implements PageBeginRenderListener{
...
private IPropertySelectionModel collectionName;
public void pageBeginRender(PageEvent event){
.....
this.setCollectionName(new SelectionObject(youObjectArray[],"youMethod"));
....
}
.....
public IPropertySelectionModel getCollectionName() {
return collectionName;
}
public void setCollectionName(IPropertySelectionModel collection) {
this.collectionName = collection;
}
@Perstist
public abstract youObject getPropertyName();
public abstract void setPropertyName(youObject);
......
}
}}}
when the use make submit the property ''PropertyName'' will be set with de object selected in the combo box for the user.
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-dev-help@jakarta.apache.org