You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by phillip rhodes <rh...@yahoo.com> on 2006/01/13 20:45:30 UTC
need "order the list" component
I need to provide a means to specify the order of items in a list. The palate component provides this, but all I need are the up/down buttons.
Let me know if you have seen a component around town that provides this functionality.
Thanks.
Phillip Rhodeshttp://www.jsso.org Open source Java Identity and Authorization Serviceshttp://www.rhoderunner.com Open Source Java Ecommerce Suite
Re: need "order the list" component
Posted by Paul Ferraro <pm...@columbia.edu>.
Here's one I wrote using Tapestry 3.0:
OrderField.jwc:
<?xml version="1.0"?>
<!DOCTYPE component-specification PUBLIC "-//Apache Software
Foundation//Tapestry Specification 3.0//EN"
"http://jakarta.apache.org/tapestry/dtd/Tapestry_3_0.dtd">
<component-specification class="OrderField" allow-body="no"
allow-informal-parameters="no">
<parameter name="model"
type="org.apache.tapestry.form.IPropertySelectionModel" required="yes"
direction="in"></parameter>
<parameter name="list" type="java.util.List" required="yes"
direction="form"></parameter>
<parameter name="tableClass" type="java.lang.String" required="no"
direction="in"></parameter>
<parameter name="buttonClass" type="java.lang.String" required="no"
direction="in"></parameter>
<parameter name="upLabel" type="java.lang.String" required="no"
direction="in" default-value="getMessage('label.up')"></parameter>
<parameter name="downLabel" type="java.lang.String" required="no"
direction="in" default-value="getMessage('label.down')"></parameter>
<property-specification name="name"
type="java.lang.String"></property-specification>
<property-specification name="form"
type="org.apache.tapestry.IForm"></property-specification>
<property-specification name="indexList"
type="java.util.List"></property-specification>
<property-specification name="index"
type="java.lang.Integer"></property-specification>
<private-asset name="script"
resource-path="OrderField.js"></private-asset>
</component-specification>
OrderField.js:
function selectAll(element, selected) {
for (var i = 0; i < element.length; ++i) {
element.options[i].selected = selected
}
}
function shift(element, i) {
var oldIndex = element.selectedIndex
var newIndex = oldIndex + i
if ((newIndex >= 0) && (newIndex < element.length)) {
var oldOption = element.options[oldIndex]
var newOption = element.options[newIndex]
var text = oldOption.text
var value = oldOption.value
oldOption.text = newOption.text
oldOption.value = newOption.value
newOption.text = text
newOption.value = value
newOption.selected = true
oldOption.selected = false
}
}
OrderField.html:
<span jwcid="$content$">
<table jwcid="@Any" element="table" class="ognl:tableClass">
<tr valign="top">
<td>
<select jwcid="@Any" name="ognl:name" element="select"
size="ognl:model.optionCount" multiple="multiple">
<span jwcid="@Foreach" source="ognl:indexList"
value="ognl:index">
<option jwcid="@Any" element="option"
value="ognl:model.value[index]"><span jwcid="@Insert"
value="ognl:model.label[index]"></span></option>
</span>
</select>
</td>
<td valign="middle">
<button jwcid="@Any" name="ognl:'up'+name"
value="ognl:upLabel"
onclick="ognl:'shift(this.form.'+name+',-1);this.disabled=(this.form.'+name+'.selectedIndex
== 0);this.form.down'+name+'.disabled=false'" class="ognl:buttonClass"
type="button"><span jwcid="@Insert"
value="ognl:upLabel">Up</span></button><br/>
<br/>
<button jwcid="@Any" name="ognl:'down'+name"
value="ognl:downLabel"
onclick="ognl:'shift(this.form.'+name+',+1);this.disabled=(this.form.'+name+'.selectedIndex
== (this.form.'+name+'.length -
1));this.form.up'+name+'.disabled=false'" class="ognl:buttonClass"
type="button"><span jwcid="@Insert"
value="ognl:downLabel">Down</span></button><br/>
</td>
</tr>
</table>
</span>
OrderField.properties:
label.down = \u2193
label.up = \u2191
OrderField.java:
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.apache.tapestry.ApplicationRuntimeException;
import org.apache.tapestry.BaseComponent;
import org.apache.tapestry.IForm;
import org.apache.tapestry.IMarkupWriter;
import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.form.Form;
import org.apache.tapestry.form.FormEventType;
import org.apache.tapestry.form.IFormComponent;
import org.apache.tapestry.form.IPropertySelectionModel;
import org.apache.tapestry.html.Body;
import org.apache.tapestry.valid.IValidationDelegate;
public abstract class OrderField extends BaseComponent implements
IFormComponent
{
public abstract void setForm(IForm form);
public abstract List<Object> getIndexList();
public abstract void setIndexList(List list);
public abstract IPropertySelectionModel getModel();
public abstract List<Object> getList();
public abstract void setList(List list);
/**
* @see
org.apache.tapestry.AbstractComponent#renderComponent(org.apache.tapestry.IMarkupWriter,
org.apache.tapestry.IRequestCycle)
*/
protected void renderComponent(IMarkupWriter writer, IRequestCycle
requestCycle)
{
IForm form = Form.get(getPage().getRequestCycle());
if (form == null)
{
throw new ApplicationRuntimeException("Palette component
must be wrapped by a Form.", this, null, null);
}
setForm(form);
IValidationDelegate delegate = form.getDelegate();
if (delegate != null)
{
delegate.setFormComponent(this);
}
setName(form.getElementId(this));
IPropertySelectionModel model = this.getModel();
if (form.isRewinding())
{
String[] parameters =
requestCycle.getRequestContext().getParameters(this.getName());
if (parameters != null)
{
this.setList(new ArrayList(parameters.length));
for (int i = 0; i < parameters.length; ++i)
{
this.getList().add(model.translateValue(parameters[i]));
}
}
else
{
this.setList(Collections.EMPTY_LIST);
}
}
else if (!requestCycle.isRewinding())
{
this.setIndexList(new
ArrayList(this.getModel().getOptionCount()));
for (int i = 0; i < model.getOptionCount(); ++i)
{
this.getIndexList().add(i);
}
form.addEventHandler(FormEventType.SUBMIT, "function () {
selectAll(document." + form.getName() + "." + this.getName() + ",true);
return true }");
Body.get(requestCycle).addExternalScript(this.getAsset("script").getResourceLocation());
}
super.renderComponent(writer, requestCycle);
}
/**
* @see org.apache.tapestry.form.IFormComponent#getDisplayName()
*/
public String getDisplayName()
{
return null;
}
/**
* @see org.apache.tapestry.form.IFormComponent#isDisabled()
*/
public boolean isDisabled()
{
return false;
}
}
Paul
phillip rhodes wrote:
> I need to provide a means to specify the order of items in a list. The palate component provides this, but all I need are the up/down buttons.
>
> Let me know if you have seen a component around town that provides this functionality.
>
> Thanks.
>
>
>
>
> Phillip Rhodeshttp://www.jsso.org Open source Java Identity and Authorization Serviceshttp://www.rhoderunner.com Open Source Java Ecommerce Suite
>
Re: need "order the list" component
Posted by phillip rhodes <rh...@yahoo.com>.
Yes, a single multi-item select box (like from palette) with up/down image keys that perform sorting on the client side would work great for me.
Jesse Kuhnert <jk...@gmail.com> wrote: Can you be more specific about what you are looking for?
Is it a single multi item select box (like one from pallette) with up/down
image keys that perform sorting on the client side? What is the use case for
this list?
On 1/13/06, phillip rhodes wrote:
>
> I need to provide a means to specify the order of items in a list. The
> palate component provides this, but all I need are the up/down buttons.
>
> Let me know if you have seen a component around town that provides this
> functionality.
>
> Thanks.
>
>
>
>
> Phillip Rhodeshttp://www.jsso.org Open source Java Identity and
> Authorization Serviceshttp://www.rhoderunner.com Open Source Java
> Ecommerce Suite
>
Phillip Rhodeshttp://www.jsso.org Open source Java Identity and Authorization Serviceshttp://www.rhoderunner.com Open Source Java Ecommerce Suite
Re: need "order the list" component
Posted by Jesse Kuhnert <jk...@gmail.com>.
Can you be more specific about what you are looking for?
Is it a single multi item select box (like one from pallette) with up/down
image keys that perform sorting on the client side? What is the use case for
this list?
On 1/13/06, phillip rhodes <rh...@yahoo.com> wrote:
>
> I need to provide a means to specify the order of items in a list. The
> palate component provides this, but all I need are the up/down buttons.
>
> Let me know if you have seen a component around town that provides this
> functionality.
>
> Thanks.
>
>
>
>
> Phillip Rhodeshttp://www.jsso.org Open source Java Identity and
> Authorization Serviceshttp://www.rhoderunner.com Open Source Java
> Ecommerce Suite
>