You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@myfaces.apache.org by Bernd Bohmann <be...@atanion.com> on 2006/02/25 10:10:19 UTC
Re: svn commit: r380866 - in /incubator/tobago/trunk: tobago-core/src/main/java/org/apache/myfaces/tobago/component/
tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/component/ tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/t...
Hi Volker,
I would prefer an actionListener and a SortActionEvent instead of a
sortActionListener.
I don't like the x XYZActionListener.
Can you change it?
Regards
Bernd
weber@apache.org schrieb:
> Author: weber
> Date: Fri Feb 24 15:37:31 2006
> New Revision: 380866
>
> URL: http://svn.apache.org/viewcvs?rev=380866&view=rev
> Log:
> add sortActionListener attribute to sheet
>
> Modified:
> incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/ComponentUtil.java
> incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/Sorter.java
> incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/UIData.java
> incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/component/SheetTag.java
> incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/TobagoDemoController.java
> incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/model/solar/SolarObject.java
> incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/OverviewController.java
> incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/SheetConfig.java
> incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/overview/sheetControl.jsp
> incubator/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SheetRenderer.java
> incubator/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-sheet.js
>
> Modified: incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/ComponentUtil.java
> URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/ComponentUtil.java?rev=380866&r1=380865&r2=380866&view=diff
> ==============================================================================
> --- incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/ComponentUtil.java (original)
> +++ incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/ComponentUtil.java Fri Feb 24 15:37:31 2006
> @@ -23,30 +23,7 @@
>
> import org.apache.commons.logging.Log;
> import org.apache.commons.logging.LogFactory;
> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_ACCESS_KEY;
> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_ACTION_STRING;
> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_ALIGN;
> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_DISABLED;
> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_FOR;
> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_HOVER;
> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_LABEL;
> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_LABEL_WITH_ACCESS_KEY;
> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_READONLY;
> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_RENDER_RANGE;
> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_RENDER_RANGE_EXTERN;
> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_SORTABLE;
> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_VALUE;
> -import static org.apache.myfaces.tobago.TobagoConstants.COMMAND_TYPE_NAVIGATE;
> -import static org.apache.myfaces.tobago.TobagoConstants.COMMAND_TYPE_RESET;
> -import static org.apache.myfaces.tobago.TobagoConstants.COMMAND_TYPE_SCRIPT;
> -import static org.apache.myfaces.tobago.TobagoConstants.FACET_CHECKBOX;
> -import static org.apache.myfaces.tobago.TobagoConstants.FACET_LABEL;
> -import static org.apache.myfaces.tobago.TobagoConstants.FACET_RADIO;
> -import static org.apache.myfaces.tobago.TobagoConstants.RENDERER_TYPE_OUT;
> -import static org.apache.myfaces.tobago.TobagoConstants.RENDERER_TYPE_SELECT_BOOLEAN_CHECKBOX;
> -import static org.apache.myfaces.tobago.TobagoConstants.RENDERER_TYPE_SELECT_ONE_RADIO;
> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_CREATE_SPAN;
> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_ESCAPE;
> +import static org.apache.myfaces.tobago.TobagoConstants.*;
> import org.apache.myfaces.tobago.el.ConstantMethodBinding;
> import org.apache.myfaces.tobago.event.SheetStateChangeEvent;
> import org.apache.myfaces.tobago.renderkit.RendererBase;
> @@ -55,33 +32,22 @@
>
> import javax.faces.FactoryFinder;
> import javax.faces.application.Application;
> -import javax.faces.component.ActionSource;
> -import javax.faces.component.EditableValueHolder;
> -import javax.faces.component.UIColumn;
> +import javax.faces.component.*;
> import javax.faces.component.UICommand;
> -import javax.faces.component.UIComponent;
> -import javax.faces.component.UIGraphic;
> import javax.faces.component.UIOutput;
> -import javax.faces.component.UIParameter;
> -import javax.faces.component.UISelectBoolean;
> import javax.faces.component.UISelectItem;
> -import javax.faces.component.UISelectItems;
> -import javax.faces.component.ValueHolder;
> import javax.faces.context.FacesContext;
> import javax.faces.convert.Converter;
> import javax.faces.el.MethodBinding;
> import javax.faces.el.ValueBinding;
> +import javax.faces.event.ActionEvent;
> import javax.faces.event.ActionListener;
> import javax.faces.model.SelectItem;
> import javax.faces.render.RenderKit;
> import javax.faces.render.RenderKitFactory;
> import javax.faces.webapp.UIComponentTag;
> import javax.servlet.jsp.JspException;
> -import java.util.ArrayList;
> -import java.util.Collection;
> -import java.util.Iterator;
> -import java.util.List;
> -import java.util.Map;
> +import java.util.*;
>
> public class ComponentUtil {
>
> @@ -90,6 +56,9 @@
> private static final String RENDER_KEY_PREFIX
> = "org.apache.myfaces.tobago.component.ComponentUtil.RendererKeyPrefix_";
>
> + private static final Class[] ACTION_LISTENER_ARGS = {ActionEvent.class};
> +
> +
> private ComponentUtil() {
> }
>
> @@ -917,13 +886,27 @@
> final Application application = facesContext.getApplication();
> if (actionListener != null) {
> if (UIComponentTag.isValueReference(actionListener)) {
> - Class[] arguments = {javax.faces.event.ActionEvent.class};
> MethodBinding binding
> - = application.createMethodBinding(actionListener, arguments);
> + = application.createMethodBinding(actionListener, ACTION_LISTENER_ARGS);
> command.setActionListener(binding);
> } else {
> throw new IllegalArgumentException(
> "Must be a valueReference (actionListener): " + actionListener);
> + }
> + }
> + }
> +
> + public static void setSortActionListener(UIData data, String actionListener) {
> + final FacesContext facesContext = FacesContext.getCurrentInstance();
> + final Application application = facesContext.getApplication();
> + if (actionListener != null) {
> + if (UIComponentTag.isValueReference(actionListener)) {
> + MethodBinding binding
> + = application.createMethodBinding(actionListener, ACTION_LISTENER_ARGS);
> + data.setSortActionListener(binding);
> + } else {
> + throw new IllegalArgumentException(
> + "Must be a valueReference (sortActionListener): " + actionListener);
> }
> }
> }
>
> Modified: incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/Sorter.java
> URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/Sorter.java?rev=380866&r1=380865&r2=380866&view=diff
> ==============================================================================
> --- incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/Sorter.java (original)
> +++ incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/Sorter.java Fri Feb 24 15:37:31 2006
> @@ -21,15 +21,12 @@
> import org.apache.myfaces.tobago.TobagoConstants;
> import static org.apache.myfaces.tobago.TobagoConstants.ATTR_SORTABLE;
> import org.apache.myfaces.tobago.model.SheetState;
> -import org.apache.myfaces.tobago.model.SortableByApplication;
> import org.apache.myfaces.tobago.util.BeanComparator;
> import org.apache.myfaces.tobago.util.ValueBindingComparator;
>
> -import javax.faces.component.UIColumn;
> -import javax.faces.component.UIComponent;
> +import javax.faces.component.*;
> import javax.faces.component.UIInput;
> import javax.faces.component.UIOutput;
> -import javax.faces.component.UISelectBoolean;
> import javax.faces.context.FacesContext;
> import javax.faces.el.EvaluationException;
> import javax.faces.el.MethodBinding;
> @@ -37,11 +34,7 @@
> import javax.faces.el.ValueBinding;
> import javax.faces.event.ActionEvent;
> import javax.faces.model.DataModel;
> -import java.util.Arrays;
> -import java.util.Collections;
> -import java.util.Comparator;
> -import java.util.Iterator;
> -import java.util.List;
> +import java.util.*;
>
> /**
> * User: weber
> @@ -52,8 +45,6 @@
>
> private static final Log LOG = LogFactory.getLog(Sorter.class);
>
> - public static final String ID_PREFIX = "sorter_";
> -
>
> public Object invoke(FacesContext facesContext, Object[] aobj)
> throws EvaluationException {
> @@ -63,87 +54,66 @@
> if (LOG.isDebugEnabled()) {
> LOG.debug("sorterId = " + command.getId());
> }
> - UIData data = (UIData) command.getParent();
> + UIColumn column = (UIColumn) command.getParent();
> + UIData data = (UIData) column.getParent();
> +
> Object value = data.getValue();
> if (value instanceof DataModel) {
> value = ((DataModel) value).getWrappedData();
> }
> SheetState sheetState = data.getSheetState(facesContext);
> - int column = sheetState.getSortedColumn();
> - boolean ascending = sheetState.isAscending();
>
> Comparator comparator = null;
>
> - if (value instanceof SortableByApplication
> - || value instanceof List
> - || value instanceof Object[]) {
> + if (value instanceof List || value instanceof Object[]) {
> String sortProperty;
>
> - if (command.getId() != null && command.getId().startsWith(ID_PREFIX)) {
> - UIColumn uiColumn = null;
> - try {
> - int actualColumn =
> - Integer.parseInt(
> - command.getId().substring(ID_PREFIX.length()));
> - if (actualColumn == column) {
> - ascending = !ascending;
> - } else {
> - ascending = true;
> - column = actualColumn;
> - }
> - sheetState.setAscending(ascending);
> - sheetState.setSortedColumn(column);
> + try {
> + if (!updateSheetState(data, column, sheetState)) {
> + return null;
> + }
>
> - uiColumn = data.getRendererdColumns().get(column);
> - UIComponent child = getFirstSortableChild(uiColumn.getChildren());
> - if (child != null) {
> - ValueBinding valueBinding = child.getValueBinding("value");
> - String var = data.getVar();
> -
> - if (valueBinding != null) {
> - if (isSimpleProperty(valueBinding.getExpressionString())) {
> - String expressionString = valueBinding.getExpressionString();
> - if (expressionString.startsWith("#{")
> - && expressionString.endsWith("}")) {
> - expressionString =
> - expressionString.substring(2,
> - expressionString.length() - 1);
> - }
> - sortProperty = expressionString.substring(var.length() + 1);
> -
> - comparator = new BeanComparator(sortProperty, null, !ascending);
> -
> - if (LOG.isDebugEnabled()) {
> - LOG.debug("Sort property is " + sortProperty);
> - }
> - } else {
> - comparator = new ValueBindingComparator(facesContext, var, valueBinding, !ascending);
> + UIComponent child = getFirstSortableChild(column.getChildren());
> + if (child != null) {
> + ValueBinding valueBinding = child.getValueBinding("value");
> + String var = data.getVar();
> +
> + if (valueBinding != null) {
> + if (isSimpleProperty(valueBinding.getExpressionString())) {
> + String expressionString = valueBinding.getExpressionString();
> + if (expressionString.startsWith("#{")
> + && expressionString.endsWith("}")) {
> + expressionString =
> + expressionString.substring(2,
> + expressionString.length() - 1);
> }
> - }
> + sortProperty = expressionString.substring(var.length() + 1);
>
> - } else {
> - LOG.error("No sortable component found!");
> - removeSortableAttribute(uiColumn);
> - return null;
> - }
> - } catch (Exception e) {
> - LOG.error("Error while extracting sortMethod :" + e.getMessage(), e);
> - if (uiColumn != null) {
> - removeSortableAttribute(uiColumn);
> + comparator = new BeanComparator(
> + sortProperty, null, !sheetState.isAscending());
> +
> + if (LOG.isDebugEnabled()) {
> + LOG.debug("Sort property is " + sortProperty);
> + }
> + } else {
> + comparator = new ValueBindingComparator(
> + facesContext, var, valueBinding, !sheetState.isAscending());
> + }
> }
> +
> + } else {
> + LOG.error("No sortable component found!");
> + removeSortableAttribute(column);
> return null;
> }
> - } else {
> - LOG.error(
> - "Sorter.invoke() with illegal id in ActionEvent's source");
> + } catch (Exception e) {
> + LOG.error("Error while extracting sortMethod :" + e.getMessage(), e);
> + if (column != null) {
> + removeSortableAttribute(column);
> + }
> return null;
> }
>
> - //if (value instanceof SortableByApplication) {
> - //((SortableByApplication) value).sortBy(sortProperty);
> -
> - // TODO ???? sortable by application
> - if (!(value instanceof SortableByApplication)) {
> // TODO: locale / comparator parameter?
> // don't compare numbers with Collator.getInstance() comparator
> // Comparator comparator = Collator.getInstance();
> @@ -151,16 +121,43 @@
>
> if (value instanceof List) {
> Collections.sort((List) value, comparator);
> - } else { // if (value instanceof Object[]) {
> + } else { // value is instanceof Object[]
> Arrays.sort((Object[]) value, comparator);
> }
> - }
> +
> } else { // DataModel?, ResultSet, Result or Object
> LOG.warn("Sorting not supported for type "
> + (value != null ? value.getClass().toString() : "null"));
> }
> }
> return null;
> + }
> +
> + private boolean updateSheetState(UIData data, UIColumn uiColumn, SheetState sheetState) {
> + int actualColumn = -1;
> + List<UIColumn> rendererdColumns = data.getRendererdColumns();
> + for (int i = 0; i < rendererdColumns.size(); i++) {
> + if (uiColumn == rendererdColumns.get(i)) {
> + actualColumn = i;
> + break;
> + }
> + }
> + if (actualColumn == -1) {
> + LOG.warn("Can't find column to sort in rendered columns of sheet!");
> + return false;
> + }
> +
> + int column = sheetState.getSortedColumn();
> + boolean ascending = sheetState.isAscending();
> + if (actualColumn == column) {
> + ascending = !ascending;
> + } else {
> + ascending = true;
> + column = actualColumn;
> + }
> + sheetState.setAscending(ascending);
> + sheetState.setSortedColumn(column);
> + return true;
> }
>
> private boolean isSimpleProperty(String expressionString) {
>
> Modified: incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/UIData.java
> URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/UIData.java?rev=380866&r1=380865&r2=380866&view=diff
> ==============================================================================
> --- incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/UIData.java (original)
> +++ incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/UIData.java Fri Feb 24 15:37:31 2006
> @@ -53,12 +53,14 @@
>
> public static final String COMPONENT_TYPE = "org.apache.myfaces.tobago.Data";
>
> + public static final String FACET_SORTER = "sorter";
> + public static final String SORTER_ID = "sorter";
> +
> private MethodBinding stateChangeListener;
>
> private List<Integer> widthList;
>
> - // TODO: should be removed?
> - private Sorter sorter;
> + private MethodBinding sortActionListener;
>
> private SheetState sheetState;
>
> @@ -320,10 +322,10 @@
> private void updateSheetState(FacesContext facesContext) {
> SheetState state = getSheetState(facesContext);
> if (state != null) {
> - // ensure sorter
> -// getSorter();
> -// state.setSortedColumn(sorter != null ? sorter.getColumn() : -1);
> -// state.setAscending(sorter != null && sorter.isAscending());
> + // ensure sortActionListener
> +// getSortActionListener();
> +// state.setSortedColumn(sortActionListener != null ? sortActionListener.getColumn() : -1);
> +// state.setAscending(sortActionListener != null && sortActionListener.isAscending());
> state.setSelectedRows((List<Integer>)
> getAttributes().get(ATTR_SELECTED_LIST_STRING));
> state.setColumnWidths((String)
> @@ -335,7 +337,7 @@
> Object[] saveState = new Object[5];
> saveState[0] = super.saveState(context);
> saveState[1] = sheetState;
> - saveState[2] = sorter;
> + saveState[2] = saveAttachedState(context, sortActionListener);
> saveState[3] = saveAttachedState(context, stateChangeListener);
> if (showHeaderSet) {
> saveState[4] = showHeader;
> @@ -347,7 +349,7 @@
> Object[] values = (Object[]) savedState;
> super.restoreState(context, values[0]);
> sheetState = (SheetState) values[1];
> - sorter = (Sorter) values[2];
> + sortActionListener = (MethodBinding) restoreAttachedState(context, values[2]);
> stateChangeListener = (MethodBinding) restoreAttachedState(context, values[3]);
> if (values[4] != null) {
> showHeaderSet = true;
> @@ -376,17 +378,16 @@
> return columns;
> }
>
> - // TODO: should be removed?
> - public Sorter getSorter() {
> - if (sorter != null) {
> - return sorter;
> + public MethodBinding getSortActionListener() {
> + if (sortActionListener != null) {
> + return sortActionListener;
> } else {
> return new Sorter();
> }
> }
>
> - public void setSorter(Sorter sorter) {
> - this.sorter = sorter;
> + public void setSortActionListener(MethodBinding sortActionListener) {
> + this.sortActionListener = sortActionListener;
> }
>
> public void queueEvent(FacesEvent facesEvent) {
>
> Modified: incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/component/SheetTag.java
> URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/component/SheetTag.java?rev=380866&r1=380865&r2=380866&view=diff
> ==============================================================================
> --- incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/component/SheetTag.java (original)
> +++ incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/component/SheetTag.java Fri Feb 24 15:37:31 2006
> @@ -16,19 +16,7 @@
> * limitations under the License.
> */
>
> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_COLUMNS;
> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_DIRECT_LINK_COUNT;
> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_FIRST;
> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_FORCE_VERTICAL_SCROLLBAR;
> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_INNER_WIDTH;
> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_ROWS;
> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_SHOW_DIRECT_LINKS;
> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_SHOW_HEADER;
> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_SHOW_PAGE_RANGE;
> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_SHOW_ROW_RANGE;
> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_STATE;
> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_VALUE;
> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_VAR;
> +import static org.apache.myfaces.tobago.TobagoConstants.*;
> import org.apache.myfaces.tobago.apt.annotation.BodyContentDescription;
> import org.apache.myfaces.tobago.apt.annotation.Tag;
> import org.apache.myfaces.tobago.apt.annotation.TagAttribute;
> @@ -59,6 +47,7 @@
> private String forceVerticalScrollbar;
> private String state;
> private String stateChangeListener;
> + private String sortActionListener;
>
> public String getComponentType() {
> // TODO: implement uidata with overridden processUpdates to store state
> @@ -80,6 +69,7 @@
> forceVerticalScrollbar = null;
> state = null;
> stateChangeListener = null;
> + sortActionListener = null;
> }
>
> protected void setProperties(UIComponent component) {
> @@ -101,6 +91,7 @@
> data.getAttributes().put(ATTR_INNER_WIDTH, new Integer(-1));
> ComponentUtil.setValueBinding(component, ATTR_STATE, state);
> ComponentUtil.setStateChangeListener(data, stateChangeListener);
> + ComponentUtil.setSortActionListener(data, sortActionListener);
>
> }
>
> @@ -280,5 +271,24 @@
> public void setStateChangeListener(String stateChangeListener) {
> this.stateChangeListener = stateChangeListener;
> }
> +
> + /**
> + * MethodBinding representing an actionListener method that will be
> + * invoked when sorting was requested by the user.
> + * Use this if your application needs special handling for sorting columns.
> + * If this is not set and the sortable attribute column is not false the sheet
> + * implementation will use a default sort method.
> + * The expression must evaluate to a public method that takes an
> + * ActionEvent parameter, with a return type of void.
> + * The parent of the actionEvents source will be the UIColumn object for that
> + * the sorting is requested,
> + * <code>UIColumn column = (UIColumn)actionEvent.getSource().getParent()</code>.
> + */
> + @TagAttribute
> + @UIComponentTagAttribute()
> + public void setSortActionListener(String sortActionListener) {
> + this.sortActionListener = sortActionListener;
> + }
> +
> }
>
>
> Modified: incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/TobagoDemoController.java
> URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/TobagoDemoController.java?rev=380866&r1=380865&r2=380866&view=diff
> ==============================================================================
> --- incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/TobagoDemoController.java (original)
> +++ incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/TobagoDemoController.java Fri Feb 24 15:37:31 2006
> @@ -61,6 +61,8 @@
>
> private SolarObject[] solarArray;
>
> + private List<SolarObject> solarList;
> +
> private List<UIColumn> solarArrayColumns;
>
> private String solarArrayColumnLayout;
> @@ -148,6 +150,7 @@
> = "**strong text**\n\n__emphasis__\n\nnormaler text\n\n__dieses "
> + "ist emphasis__\n\n**und nochmal strong**\n\n**__ strong und emphasis__**";
> solarArray = SolarObject.getArray();
> + solarList = SolarObject.getList();
> solarArrayColumns = createSolarArrayColumns();
> solarArrayColumnLayout = "3*; 3*; 3*";
>
> @@ -292,6 +295,14 @@
>
> public void setSolarArray(SolarObject[] solarArray) {
> this.solarArray = solarArray;
> + }
> +
> + public List<SolarObject> getSolarList() {
> + return solarList;
> + }
> +
> + public void setSolarList(List<SolarObject> solarList) {
> + this.solarList = solarList;
> }
>
> public List<UIColumn> getSolarArrayColumns() {
>
> Modified: incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/model/solar/SolarObject.java
> URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/model/solar/SolarObject.java?rev=380866&r1=380865&r2=380866&view=diff
> ==============================================================================
> --- incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/model/solar/SolarObject.java (original)
> +++ incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/model/solar/SolarObject.java Fri Feb 24 15:37:31 2006
> @@ -176,7 +176,17 @@
> return array;
> }
>
> - public static List<SolarObject> getSatellites(String center) {
> +
> + public static List<SolarObject> getList() {
> + SolarObject[] array = getArray();
> + List<SolarObject> list = new ArrayList<SolarObject>(array.length);
> + for (SolarObject object : array) {
> + list.add(object);
> + }
> + return list;
> + }
> +
> + public static List<SolarObject> getSatellites(String center) {
> List<SolarObject> collect = new ArrayList<SolarObject>();
> SolarObject[] all = getArray();
> for (int i = 0; i < all.length; i++) {
>
> Modified: incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/OverviewController.java
> URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/OverviewController.java?rev=380866&r1=380865&r2=380866&view=diff
> ==============================================================================
> --- incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/OverviewController.java (original)
> +++ incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/OverviewController.java Fri Feb 24 15:37:31 2006
> @@ -23,9 +23,12 @@
>
> import org.apache.commons.logging.Log;
> import org.apache.commons.logging.LogFactory;
> +import org.apache.myfaces.tobago.component.Sorter;
> +import org.apache.myfaces.tobago.component.UIData;
> import org.apache.myfaces.tobago.context.ResourceManager;
> import org.apache.myfaces.tobago.context.ResourceManagerFactory;
>
> +import javax.faces.component.UICommand;
> import javax.faces.context.FacesContext;
> import javax.faces.event.ActionEvent;
> import javax.faces.model.SelectItem;
> @@ -109,6 +112,19 @@
>
> public void click(ActionEvent actionEvent) {
> lastAction = actionEvent.getComponent().getId();
> + }
> +
> +
> + public void sheetSorter(ActionEvent event) {
> + Object eventSource = event.getSource();
> + UIData data = (UIData) ((UICommand) eventSource).getParent().getParent();
> + List list = (List) data.getValue();
> + Object sun = list.remove(0);
> + Object[] objects = new Object[1];
> + objects[0] = event;
> + Sorter sorter = new Sorter();
> + sorter.invoke(FacesContext.getCurrentInstance(), objects);
> + list.add(0, sun);
> }
>
> public boolean getShowPopup() {
>
> Modified: incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/SheetConfig.java
> URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/SheetConfig.java?rev=380866&r1=380865&r2=380866&view=diff
> ==============================================================================
> --- incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/SheetConfig.java (original)
> +++ incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/SheetConfig.java Fri Feb 24 15:37:31 2006
> @@ -47,7 +47,7 @@
> private boolean sheetConfigPopup;
>
> public SheetConfig() {
> - sheetPagingStart = 1;
> + sheetPagingStart = 0;
> sheetPagingLength = 7;
> sheetDirectLinkCount = 5;
> sheetDirectLinkCountItems = createSheetDirectLinkCountItems();
>
> Modified: incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/overview/sheetControl.jsp
> URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/overview/sheetControl.jsp?rev=380866&r1=380865&r2=380866&view=diff
> ==============================================================================
> --- incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/overview/sheetControl.jsp (original)
> +++ incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/overview/sheetControl.jsp Fri Feb 24 15:37:31 2006
> @@ -106,7 +106,7 @@
> </tc:toolBar>
> </f:facet>
>
> - <tc:sheet value="#{demo.solarArray}" id="sheet"
> + <tc:sheet value="#{demo.solarList}" id="sheet"
> columns="3*;1*;3*;3*;3*;3*" var="luminary"
> state="#{demo.sheetState}"
> showHeader="#{overviewController.sheetConfig.sheetShowHeader}"
> @@ -116,7 +116,8 @@
> pagingStart="#{overviewController.sheetConfig.sheetPagingStart}"
> pagingLength="#{overviewController.sheetConfig.sheetPagingLength}"
> directLinkCount="#{overviewController.sheetConfig.sheetDirectLinkCount}"
> - stateChangeListener="#{demo.stateChangeListener}">
> + stateChangeListener="#{demo.stateChangeListener}"
> + sortActionListener="#{overviewController.sheetSorter}">
> <tc:column label="#{overviewBundle.solarArrayName}" id="name" sortable="true">
> <tc:out value="#{luminary.name}" id="t_name" />
> </tc:column>
>
> Modified: incubator/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SheetRenderer.java
> URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SheetRenderer.java?rev=380866&r1=380865&r2=380866&view=diff
> ==============================================================================
> --- incubator/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SheetRenderer.java (original)
> +++ incubator/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SheetRenderer.java Fri Feb 24 15:37:31 2006
> @@ -23,44 +23,11 @@
>
> import org.apache.commons.logging.Log;
> import org.apache.commons.logging.LogFactory;
> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_ACTION_STRING;
> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_ALIGN;
> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_COMMAND_TYPE;
> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_DIRECT_LINK_COUNT;
> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_DISABLED;
> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_FOOTER_HEIGHT;
> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_FORCE_VERTICAL_SCROLLBAR;
> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_IMAGE;
> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_INLINE;
> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_LABEL;
> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_LAYOUT_HEIGHT;
> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_MENU_POPUP;
> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_MENU_POPUP_TYPE;
> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_SELECTED_LIST_STRING;
> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_SHOW_DIRECT_LINKS;
> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_SHOW_PAGE_RANGE;
> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_SHOW_ROW_RANGE;
> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_SORTABLE;
> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_STYLE;
> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_STYLE_BODY;
> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_STYLE_CLASS;
> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_STYLE_HEADER;
> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_TYPE;
> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_WIDTH_LIST;
> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_WIDTH_LIST_STRING;
> -import static org.apache.myfaces.tobago.TobagoConstants.COMMAND_TYPE_SCRIPT;
> -import static org.apache.myfaces.tobago.TobagoConstants.FACET_MENUPOPUP;
> -import static org.apache.myfaces.tobago.TobagoConstants.FACET_PAGER_PAGE;
> -import static org.apache.myfaces.tobago.TobagoConstants.FACET_PAGER_ROW;
> -import static org.apache.myfaces.tobago.TobagoConstants.RENDERER_TYPE_LINK;
> -import static org.apache.myfaces.tobago.TobagoConstants.RENDERER_TYPE_MENUBAR;
> -import static org.apache.myfaces.tobago.TobagoConstants.RENDERER_TYPE_MENUCOMMAND;
> -import static org.apache.myfaces.tobago.TobagoConstants.SUBCOMPONENT_SEP;
> +import static org.apache.myfaces.tobago.TobagoConstants.*;
> import org.apache.myfaces.tobago.ajax.api.AjaxRenderer;
> import org.apache.myfaces.tobago.ajax.api.AjaxUtils;
> import org.apache.myfaces.tobago.component.ComponentUtil;
> import org.apache.myfaces.tobago.component.Pager;
> -import org.apache.myfaces.tobago.component.Sorter;
> import org.apache.myfaces.tobago.component.UIColumnSelector;
> import org.apache.myfaces.tobago.component.UIData;
> import org.apache.myfaces.tobago.config.TobagoConfig;
> @@ -77,22 +44,13 @@
> import org.apache.myfaces.tobago.webapp.TobagoResponseWriter;
>
> import javax.faces.application.Application;
> -import javax.faces.component.UIColumn;
> -import javax.faces.component.UICommand;
> -import javax.faces.component.UIComponent;
> -import javax.faces.component.UIPanel;
> -import javax.faces.component.UIViewRoot;
> +import javax.faces.component.*;
> import javax.faces.context.FacesContext;
> import javax.faces.context.ResponseWriter;
> import javax.faces.el.MethodBinding;
> import java.io.IOException;
> import java.text.MessageFormat;
> -import java.util.ArrayList;
> -import java.util.Collections;
> -import java.util.Iterator;
> -import java.util.List;
> -import java.util.Locale;
> -import java.util.Map;
> +import java.util.*;
>
> public class SheetRenderer extends RendererBase
> implements SheetRendererWorkaround, AjaxRenderer {
> @@ -774,7 +732,7 @@
> String image1x1, int sortMarkerWidth) throws IOException {
> String sheetId = component.getClientId(facesContext);
> Application application = facesContext.getApplication();
> - Sorter sorter = component.getSorter();
> + MethodBinding sorter = component.getSortActionListener();
>
> List columnWidths
> = (List) component.getAttributes().get(ATTR_WIDTH_LIST);
> @@ -797,18 +755,23 @@
> ComponentUtil.getBooleanAttribute(column,
> ATTR_SORTABLE);
> if (sortable && !(column instanceof UIColumnSelector)) {
> - String sorterId = Sorter.ID_PREFIX + columnCount;
> + UICommand sortCommand = (UICommand) column.getFacet(UIData.FACET_SORTER);
> + if (sortCommand == null) {
> + String columnId = column.getClientId(facesContext);
> + String sorterId = columnId.substring(columnId.lastIndexOf(":") + 1 )
> + + "_" + UIData.SORTER_ID;
> + sortCommand
> + = (UICommand) application.createComponent(UICommand.COMPONENT_TYPE);
> + sortCommand.setRendererType(RENDERER_TYPE_LINK);
> + sortCommand.setActionListener(sorter);
> + sortCommand.setId(sorterId);
> + column.getFacets().put(UIData.FACET_SORTER, sortCommand);
> + }
> +
> String onclick = "submitAction('"
> + ComponentUtil.findPage(component).getFormId(facesContext)
> - + "','" + component.getClientId(facesContext) + ":" + sorterId + "')";
> + + "','" + sortCommand.getClientId(facesContext) + "')";
> writer.writeAttribute("onclick", onclick, null);
> - UICommand sortCommand = (UICommand)
> - application.createComponent(UICommand.COMPONENT_TYPE);
> - sortCommand.setRendererType(RENDERER_TYPE_LINK);
> - sortCommand.setActionListener(sorter);
> - sortCommand.setId(sorterId);
> - component.getFacets().put(sorterId, sortCommand);
> - sortCommand.getClientId(facesContext); // this must called here to fix the ClientId
>
> writer.writeAttribute("title",
> ResourceManagerUtil.getPropertyNotNull(facesContext, "tobago",
>
> Modified: incubator/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-sheet.js
> URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-sheet.js?rev=380866&r1=380865&r2=380866&view=diff
> ==============================================================================
> --- incubator/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-sheet.js (original)
> +++ incubator/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-sheet.js Fri Feb 24 15:37:31 2006
> @@ -34,6 +34,9 @@
> LOG.debug("New Sheet with id " + this.sheetId);
> },
>
> + sortOnclickRegExp :
> + new RegExp("submitAction\\(('|\")(.*?)('|\") *, *('|\")(.*?)('|\")\\)"),
> +
> setup: function() {
>
> // setup sorting headers
> @@ -42,7 +45,18 @@
> var headerBox = $(idPrefix + i++);
> while (headerBox) {
> if (headerBox.onclick) {
> + var match = this.sortOnclickRegExp.exec(headerBox.onclick.valueOf());
> +// LOG.debug("match[0] = " + match[0]);
> +// LOG.debug("match[1] = " + match[1]);
> +// LOG.debug("*match[2] = " + match[2]);
> +// LOG.debug("match[3] = " + match[3]);
> +// LOG.debug("match[4] = " + match[4]);
> +// LOG.debug("*match[5] = " + match[5]);
> +// LOG.debug("match[6] = " + match[6]);
> +// headerBox.formId = match[2];
> + headerBox.sorterId = match[5];
> headerBox.onclick = null;
> +// LOG.debug("headerBox.id = " + headerBox.id);
> Event.observe(headerBox, "click", this.doSort.bindAsEventListener(this));
> }
> headerBox = $(idPrefix + i++);
> @@ -97,10 +111,12 @@
>
> doSort: function(event) {
> var element = Event.element(event);
> - var idx = element.id.lastIndexOf('_');
> - idx = element.id.substring(idx + 1);
> - var action = this.sheetId + Tobago.componentSeparator + "sorter_" + idx;
> - this.reloadWithAction(action);
> + if (!element.sorterId) {
> + element = element.parentNode;
> + }
> +// LOG.debug("element.id = " + element.id);
> +// LOG.debug("sorterId = " + element.sorterId);
> + this.reloadWithAction(element.sorterId);
> },
>
> doPagingDirect: function(event) {
>
>
>
--
Dipl.-Ing. Bernd Bohmann - Atanion GmbH - Software Development
Bismarckstr. 13, 26122 Oldenburg, http://www.atanion.com
phone: +49 441 4082312, mobile: +49 173 8839471, fax: +49 441 4082333
Re: svn commit: r380866 - in /incubator/tobago/trunk: tobago-core/src/main/java/org/apache/myfaces/tobago/component/
tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/component/ tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/t...
Posted by Volker Weber <us...@weber-oldenburg.de>.
Hi Bernd,
sould any other events than SortActionEvent delivered to this
actionListener? If so, i think we can't use your approach, if not, why
don't call it sortActionListener?
Tobagos sheet has a internal default sorting mechanism, which is
implemented as methodBinding and set into the sort UICommand as
actionListener. If a application provides external sorting this must
known when creating the sort command. We can't know this if the
specified action listener is a 'univeral' one.
I don't like to disable internal sorting, just because the application
is interested in recieving any other events from this sheet.
Regards,
Volker
Bernd Bohmann wrote:
> I think so, but now I go to a Kohlfahrt.
> We can discuss this tommorrow :-)
>
> Volker Weber schrieb:
>
>> Hi Bernd,
>>
>> the sheet was already using a actionListener methodBinding to do the
>> sort. The (mainly) only thing i did was to enable defining the
>> methodBinding to use in the sheetTag.
>>
>> Hmmm, when i started to write this mail, i thought it where mutch more
>> complicated to change this to queue a SortActionEvent instead of an
>> standard ActionEvent, because the event is generated in the
>> CommandRendererBase, but i just got an idea how to catch and replace
>> this ActionEvent with a SortActionEvent.
>>
>> This could be done in the queueEvent() method of UIData.
>> Thoughts?
>>
>> Regards,
>> Volker
>>
>> Bernd Bohmann wrote:
>>
>>> Hi Volker,
>>>
>>> I would prefer an actionListener and a SortActionEvent instead of a
>>> sortActionListener.
>>>
>>> I don't like the x XYZActionListener.
>>>
>>> Can you change it?
>>>
>>> Regards
>>>
>>> Bernd
>>>
>>> weber@apache.org schrieb:
>>>
>>>
>>>> Author: weber
>>>> Date: Fri Feb 24 15:37:31 2006
>>>> New Revision: 380866
>>>>
>>>> URL: http://svn.apache.org/viewcvs?rev=380866&view=rev
>>>> Log:
>>>> add sortActionListener attribute to sheet
>>>>
>>>> Modified:
>>>>
>>>> incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/ComponentUtil.java
>>>>
>>>>
>>>>
>>>> incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/Sorter.java
>>>>
>>>>
>>>>
>>>> incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/UIData.java
>>>>
>>>>
>>>>
>>>> incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/component/SheetTag.java
>>>>
>>>>
>>>>
>>>> incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/TobagoDemoController.java
>>>>
>>>>
>>>>
>>>> incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/model/solar/SolarObject.java
>>>>
>>>>
>>>>
>>>> incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/OverviewController.java
>>>>
>>>>
>>>>
>>>> incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/SheetConfig.java
>>>>
>>>>
>>>>
>>>> incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/overview/sheetControl.jsp
>>>>
>>>>
>>>>
>>>> incubator/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SheetRenderer.java
>>>>
>>>>
>>>>
>>>> incubator/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-sheet.js
>>>>
>>>>
>>>>
>>>> Modified:
>>>> incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/ComponentUtil.java
>>>>
>>>>
>>>> URL:
>>>> http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/ComponentUtil.java?rev=380866&r1=380865&r2=380866&view=diff
>>>>
>>>>
>>>> ==============================================================================
>>>>
>>>>
>>>> ---
>>>> incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/ComponentUtil.java
>>>>
>>>> (original)
>>>> +++
>>>> incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/ComponentUtil.java
>>>>
>>>> Fri Feb 24 15:37:31 2006
>>>> @@ -23,30 +23,7 @@
>>>>
>>>> import org.apache.commons.logging.Log;
>>>> import org.apache.commons.logging.LogFactory;
>>>> -import static
>>>> org.apache.myfaces.tobago.TobagoConstants.ATTR_ACCESS_KEY;
>>>> -import static
>>>> org.apache.myfaces.tobago.TobagoConstants.ATTR_ACTION_STRING;
>>>> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_ALIGN;
>>>> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_DISABLED;
>>>> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_FOR;
>>>> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_HOVER;
>>>> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_LABEL;
>>>> -import static
>>>> org.apache.myfaces.tobago.TobagoConstants.ATTR_LABEL_WITH_ACCESS_KEY;
>>>> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_READONLY;
>>>> -import static
>>>> org.apache.myfaces.tobago.TobagoConstants.ATTR_RENDER_RANGE;
>>>> -import static
>>>> org.apache.myfaces.tobago.TobagoConstants.ATTR_RENDER_RANGE_EXTERN;
>>>> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_SORTABLE;
>>>> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_VALUE;
>>>> -import static
>>>> org.apache.myfaces.tobago.TobagoConstants.COMMAND_TYPE_NAVIGATE;
>>>> -import static
>>>> org.apache.myfaces.tobago.TobagoConstants.COMMAND_TYPE_RESET;
>>>> -import static
>>>> org.apache.myfaces.tobago.TobagoConstants.COMMAND_TYPE_SCRIPT;
>>>> -import static
>>>> org.apache.myfaces.tobago.TobagoConstants.FACET_CHECKBOX;
>>>> -import static org.apache.myfaces.tobago.TobagoConstants.FACET_LABEL;
>>>> -import static org.apache.myfaces.tobago.TobagoConstants.FACET_RADIO;
>>>> -import static
>>>> org.apache.myfaces.tobago.TobagoConstants.RENDERER_TYPE_OUT;
>>>> -import static
>>>> org.apache.myfaces.tobago.TobagoConstants.RENDERER_TYPE_SELECT_BOOLEAN_CHECKBOX;
>>>>
>>>>
>>>> -import static
>>>> org.apache.myfaces.tobago.TobagoConstants.RENDERER_TYPE_SELECT_ONE_RADIO;
>>>>
>>>> -import static
>>>> org.apache.myfaces.tobago.TobagoConstants.ATTR_CREATE_SPAN;
>>>> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_ESCAPE;
>>>> +import static org.apache.myfaces.tobago.TobagoConstants.*;
>>>> import org.apache.myfaces.tobago.el.ConstantMethodBinding;
>>>> import org.apache.myfaces.tobago.event.SheetStateChangeEvent;
>>>> import org.apache.myfaces.tobago.renderkit.RendererBase;
>>>> @@ -55,33 +32,22 @@
>>>>
>>>> import javax.faces.FactoryFinder;
>>>> import javax.faces.application.Application;
>>>> -import javax.faces.component.ActionSource;
>>>> -import javax.faces.component.EditableValueHolder;
>>>> -import javax.faces.component.UIColumn;
>>>> +import javax.faces.component.*;
>>>> import javax.faces.component.UICommand;
>>>> -import javax.faces.component.UIComponent;
>>>> -import javax.faces.component.UIGraphic;
>>>> import javax.faces.component.UIOutput;
>>>> -import javax.faces.component.UIParameter;
>>>> -import javax.faces.component.UISelectBoolean;
>>>> import javax.faces.component.UISelectItem;
>>>> -import javax.faces.component.UISelectItems;
>>>> -import javax.faces.component.ValueHolder;
>>>> import javax.faces.context.FacesContext;
>>>> import javax.faces.convert.Converter;
>>>> import javax.faces.el.MethodBinding;
>>>> import javax.faces.el.ValueBinding;
>>>> +import javax.faces.event.ActionEvent;
>>>> import javax.faces.event.ActionListener;
>>>> import javax.faces.model.SelectItem;
>>>> import javax.faces.render.RenderKit;
>>>> import javax.faces.render.RenderKitFactory;
>>>> import javax.faces.webapp.UIComponentTag;
>>>> import javax.servlet.jsp.JspException;
>>>> -import java.util.ArrayList;
>>>> -import java.util.Collection;
>>>> -import java.util.Iterator;
>>>> -import java.util.List;
>>>> -import java.util.Map;
>>>> +import java.util.*;
>>>>
>>>> public class ComponentUtil {
>>>>
>>>> @@ -90,6 +56,9 @@
>>>> private static final String RENDER_KEY_PREFIX
>>>> =
>>>> "org.apache.myfaces.tobago.component.ComponentUtil.RendererKeyPrefix_";
>>>>
>>>> + private static final Class[] ACTION_LISTENER_ARGS =
>>>> {ActionEvent.class};
>>>> +
>>>> +
>>>> private ComponentUtil() {
>>>> }
>>>>
>>>> @@ -917,13 +886,27 @@
>>>> final Application application = facesContext.getApplication();
>>>> if (actionListener != null) {
>>>> if (UIComponentTag.isValueReference(actionListener)) {
>>>> - Class[] arguments = {javax.faces.event.ActionEvent.class};
>>>> MethodBinding binding
>>>> - = application.createMethodBinding(actionListener,
>>>> arguments);
>>>> + = application.createMethodBinding(actionListener,
>>>> ACTION_LISTENER_ARGS);
>>>> command.setActionListener(binding);
>>>> } else {
>>>> throw new IllegalArgumentException(
>>>> "Must be a valueReference (actionListener): " +
>>>> actionListener);
>>>> + }
>>>> + }
>>>> + }
>>>> +
>>>> + public static void setSortActionListener(UIData data, String
>>>> actionListener) {
>>>> + final FacesContext facesContext =
>>>> FacesContext.getCurrentInstance();
>>>> + final Application application = facesContext.getApplication();
>>>> + if (actionListener != null) {
>>>> + if (UIComponentTag.isValueReference(actionListener)) {
>>>> + MethodBinding binding
>>>> + = application.createMethodBinding(actionListener,
>>>> ACTION_LISTENER_ARGS);
>>>> + data.setSortActionListener(binding);
>>>> + } else {
>>>> + throw new IllegalArgumentException(
>>>> + "Must be a valueReference (sortActionListener): " +
>>>> actionListener);
>>>> }
>>>> }
>>>> }
>>>>
>>>> Modified:
>>>> incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/Sorter.java
>>>>
>>>>
>>>> URL:
>>>> http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/Sorter.java?rev=380866&r1=380865&r2=380866&view=diff
>>>>
>>>>
>>>> ==============================================================================
>>>>
>>>>
>>>> ---
>>>> incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/Sorter.java
>>>>
>>>> (original)
>>>> +++
>>>> incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/Sorter.java
>>>>
>>>> Fri Feb 24 15:37:31 2006
>>>> @@ -21,15 +21,12 @@
>>>> import org.apache.myfaces.tobago.TobagoConstants;
>>>> import static org.apache.myfaces.tobago.TobagoConstants.ATTR_SORTABLE;
>>>> import org.apache.myfaces.tobago.model.SheetState;
>>>> -import org.apache.myfaces.tobago.model.SortableByApplication;
>>>> import org.apache.myfaces.tobago.util.BeanComparator;
>>>> import org.apache.myfaces.tobago.util.ValueBindingComparator;
>>>>
>>>> -import javax.faces.component.UIColumn;
>>>> -import javax.faces.component.UIComponent;
>>>> +import javax.faces.component.*;
>>>> import javax.faces.component.UIInput;
>>>> import javax.faces.component.UIOutput;
>>>> -import javax.faces.component.UISelectBoolean;
>>>> import javax.faces.context.FacesContext;
>>>> import javax.faces.el.EvaluationException;
>>>> import javax.faces.el.MethodBinding;
>>>> @@ -37,11 +34,7 @@
>>>> import javax.faces.el.ValueBinding;
>>>> import javax.faces.event.ActionEvent;
>>>> import javax.faces.model.DataModel;
>>>> -import java.util.Arrays;
>>>> -import java.util.Collections;
>>>> -import java.util.Comparator;
>>>> -import java.util.Iterator;
>>>> -import java.util.List;
>>>> +import java.util.*;
>>>>
>>>> /**
>>>> * User: weber
>>>> @@ -52,8 +45,6 @@
>>>>
>>>> private static final Log LOG = LogFactory.getLog(Sorter.class);
>>>>
>>>> - public static final String ID_PREFIX = "sorter_";
>>>> -
>>>>
>>>> public Object invoke(FacesContext facesContext, Object[] aobj)
>>>> throws EvaluationException {
>>>> @@ -63,87 +54,66 @@
>>>> if (LOG.isDebugEnabled()) {
>>>> LOG.debug("sorterId = " + command.getId());
>>>> }
>>>> - UIData data = (UIData) command.getParent();
>>>> + UIColumn column = (UIColumn) command.getParent();
>>>> + UIData data = (UIData) column.getParent();
>>>> +
>>>> Object value = data.getValue();
>>>> if (value instanceof DataModel) {
>>>> value = ((DataModel) value).getWrappedData();
>>>> }
>>>> SheetState sheetState = data.getSheetState(facesContext);
>>>> - int column = sheetState.getSortedColumn();
>>>> - boolean ascending = sheetState.isAscending();
>>>>
>>>> Comparator comparator = null;
>>>>
>>>> - if (value instanceof SortableByApplication
>>>> - || value instanceof List
>>>> - || value instanceof Object[]) {
>>>> + if (value instanceof List || value instanceof Object[]) {
>>>> String sortProperty;
>>>>
>>>> - if (command.getId() != null &&
>>>> command.getId().startsWith(ID_PREFIX)) {
>>>> - UIColumn uiColumn = null;
>>>> - try {
>>>> - int actualColumn =
>>>> - Integer.parseInt(
>>>> - command.getId().substring(ID_PREFIX.length()));
>>>> - if (actualColumn == column) {
>>>> - ascending = !ascending;
>>>> - } else {
>>>> - ascending = true;
>>>> - column = actualColumn;
>>>> - }
>>>> - sheetState.setAscending(ascending);
>>>> - sheetState.setSortedColumn(column);
>>>> + try {
>>>> + if (!updateSheetState(data, column, sheetState)) {
>>>> + return null;
>>>> + }
>>>>
>>>> - uiColumn = data.getRendererdColumns().get(column);
>>>> - UIComponent child =
>>>> getFirstSortableChild(uiColumn.getChildren());
>>>> - if (child != null) {
>>>> - ValueBinding valueBinding =
>>>> child.getValueBinding("value");
>>>> - String var = data.getVar();
>>>> -
>>>> - if (valueBinding != null) {
>>>> - if
>>>> (isSimpleProperty(valueBinding.getExpressionString())) {
>>>> - String expressionString =
>>>> valueBinding.getExpressionString();
>>>> - if (expressionString.startsWith("#{")
>>>> - && expressionString.endsWith("}")) {
>>>> - expressionString =
>>>> - expressionString.substring(2,
>>>> - expressionString.length() - 1);
>>>> - }
>>>> - sortProperty =
>>>> expressionString.substring(var.length() + 1);
>>>> -
>>>> - comparator = new BeanComparator(sortProperty, null,
>>>> !ascending);
>>>> -
>>>> - if (LOG.isDebugEnabled()) {
>>>> - LOG.debug("Sort property is " + sortProperty);
>>>> - }
>>>> - } else {
>>>> - comparator = new
>>>> ValueBindingComparator(facesContext, var, valueBinding, !ascending);
>>>> + UIComponent child =
>>>> getFirstSortableChild(column.getChildren());
>>>> + if (child != null) {
>>>> + ValueBinding valueBinding =
>>>> child.getValueBinding("value");
>>>> + String var = data.getVar();
>>>> +
>>>> + if (valueBinding != null) {
>>>> + if
>>>> (isSimpleProperty(valueBinding.getExpressionString())) {
>>>> + String expressionString =
>>>> valueBinding.getExpressionString();
>>>> + if (expressionString.startsWith("#{")
>>>> + && expressionString.endsWith("}")) {
>>>> + expressionString =
>>>> + expressionString.substring(2,
>>>> + expressionString.length() - 1);
>>>> }
>>>> - }
>>>> + sortProperty =
>>>> expressionString.substring(var.length() + 1);
>>>>
>>>> - } else {
>>>> - LOG.error("No sortable component found!");
>>>> - removeSortableAttribute(uiColumn);
>>>> - return null;
>>>> - }
>>>> - } catch (Exception e) {
>>>> - LOG.error("Error while extracting sortMethod :" +
>>>> e.getMessage(), e);
>>>> - if (uiColumn != null) {
>>>> - removeSortableAttribute(uiColumn);
>>>> + comparator = new BeanComparator(
>>>> + sortProperty, null, !sheetState.isAscending());
>>>> +
>>>> + if (LOG.isDebugEnabled()) {
>>>> + LOG.debug("Sort property is " + sortProperty);
>>>> + }
>>>> + } else {
>>>> + comparator = new ValueBindingComparator(
>>>> + facesContext, var, valueBinding,
>>>> !sheetState.isAscending());
>>>> + }
>>>> }
>>>> +
>>>> + } else {
>>>> + LOG.error("No sortable component found!");
>>>> + removeSortableAttribute(column);
>>>> return null;
>>>> }
>>>> - } else {
>>>> - LOG.error(
>>>> - "Sorter.invoke() with illegal id in ActionEvent's
>>>> source");
>>>> + } catch (Exception e) {
>>>> + LOG.error("Error while extracting sortMethod :" +
>>>> e.getMessage(), e);
>>>> + if (column != null) {
>>>> + removeSortableAttribute(column);
>>>> + }
>>>> return null;
>>>> }
>>>>
>>>> - //if (value instanceof SortableByApplication) {
>>>> - //((SortableByApplication) value).sortBy(sortProperty);
>>>> -
>>>> - // TODO ???? sortable by application
>>>> - if (!(value instanceof SortableByApplication)) {
>>>> // TODO: locale / comparator parameter?
>>>> // don't compare numbers with Collator.getInstance()
>>>> comparator
>>>> // Comparator comparator = Collator.getInstance();
>>>> @@ -151,16 +121,43 @@
>>>>
>>>> if (value instanceof List) {
>>>> Collections.sort((List) value, comparator);
>>>> - } else { // if (value instanceof Object[]) {
>>>> + } else { // value is instanceof Object[]
>>>> Arrays.sort((Object[]) value, comparator);
>>>> }
>>>> - }
>>>> +
>>>> } else { // DataModel?, ResultSet, Result or Object
>>>> LOG.warn("Sorting not supported for type "
>>>> + (value != null ? value.getClass().toString() :
>>>> "null"));
>>>> }
>>>> }
>>>> return null;
>>>> + }
>>>> +
>>>> + private boolean updateSheetState(UIData data, UIColumn uiColumn,
>>>> SheetState sheetState) {
>>>> + int actualColumn = -1;
>>>> + List<UIColumn> rendererdColumns = data.getRendererdColumns();
>>>> + for (int i = 0; i < rendererdColumns.size(); i++) {
>>>> + if (uiColumn == rendererdColumns.get(i)) {
>>>> + actualColumn = i;
>>>> + break;
>>>> + }
>>>> + }
>>>> + if (actualColumn == -1) {
>>>> + LOG.warn("Can't find column to sort in rendered columns of
>>>> sheet!");
>>>> + return false;
>>>> + }
>>>> +
>>>> + int column = sheetState.getSortedColumn();
>>>> + boolean ascending = sheetState.isAscending();
>>>> + if (actualColumn == column) {
>>>> + ascending = !ascending;
>>>> + } else {
>>>> + ascending = true;
>>>> + column = actualColumn;
>>>> + }
>>>> + sheetState.setAscending(ascending);
>>>> + sheetState.setSortedColumn(column);
>>>> + return true;
>>>> }
>>>>
>>>> private boolean isSimpleProperty(String expressionString) {
>>>>
>>>> Modified:
>>>> incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/UIData.java
>>>>
>>>>
>>>> URL:
>>>> http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/UIData.java?rev=380866&r1=380865&r2=380866&view=diff
>>>>
>>>>
>>>> ==============================================================================
>>>>
>>>>
>>>> ---
>>>> incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/UIData.java
>>>>
>>>> (original)
>>>> +++
>>>> incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/UIData.java
>>>>
>>>> Fri Feb 24 15:37:31 2006
>>>> @@ -53,12 +53,14 @@
>>>>
>>>> public static final String COMPONENT_TYPE =
>>>> "org.apache.myfaces.tobago.Data";
>>>>
>>>> + public static final String FACET_SORTER = "sorter";
>>>> + public static final String SORTER_ID = "sorter";
>>>> +
>>>> private MethodBinding stateChangeListener;
>>>>
>>>> private List<Integer> widthList;
>>>>
>>>> - // TODO: should be removed?
>>>> - private Sorter sorter;
>>>> + private MethodBinding sortActionListener;
>>>>
>>>> private SheetState sheetState;
>>>>
>>>> @@ -320,10 +322,10 @@
>>>> private void updateSheetState(FacesContext facesContext) {
>>>> SheetState state = getSheetState(facesContext);
>>>> if (state != null) {
>>>> - // ensure sorter
>>>> -// getSorter();
>>>> -// state.setSortedColumn(sorter != null ? sorter.getColumn() :
>>>> -1);
>>>> -// state.setAscending(sorter != null && sorter.isAscending());
>>>> + // ensure sortActionListener
>>>> +// getSortActionListener();
>>>> +// state.setSortedColumn(sortActionListener != null ?
>>>> sortActionListener.getColumn() : -1);
>>>> +// state.setAscending(sortActionListener != null &&
>>>> sortActionListener.isAscending());
>>>> state.setSelectedRows((List<Integer>)
>>>> getAttributes().get(ATTR_SELECTED_LIST_STRING));
>>>> state.setColumnWidths((String)
>>>> @@ -335,7 +337,7 @@
>>>> Object[] saveState = new Object[5];
>>>> saveState[0] = super.saveState(context);
>>>> saveState[1] = sheetState;
>>>> - saveState[2] = sorter;
>>>> + saveState[2] = saveAttachedState(context, sortActionListener);
>>>> saveState[3] = saveAttachedState(context, stateChangeListener);
>>>> if (showHeaderSet) {
>>>> saveState[4] = showHeader;
>>>> @@ -347,7 +349,7 @@
>>>> Object[] values = (Object[]) savedState;
>>>> super.restoreState(context, values[0]);
>>>> sheetState = (SheetState) values[1];
>>>> - sorter = (Sorter) values[2];
>>>> + sortActionListener = (MethodBinding)
>>>> restoreAttachedState(context, values[2]);
>>>> stateChangeListener = (MethodBinding)
>>>> restoreAttachedState(context, values[3]);
>>>> if (values[4] != null) {
>>>> showHeaderSet = true;
>>>> @@ -376,17 +378,16 @@
>>>> return columns;
>>>> }
>>>>
>>>> - // TODO: should be removed?
>>>> - public Sorter getSorter() {
>>>> - if (sorter != null) {
>>>> - return sorter;
>>>> + public MethodBinding getSortActionListener() {
>>>> + if (sortActionListener != null) {
>>>> + return sortActionListener;
>>>> } else {
>>>> return new Sorter();
>>>> }
>>>> }
>>>>
>>>> - public void setSorter(Sorter sorter) {
>>>> - this.sorter = sorter;
>>>> + public void setSortActionListener(MethodBinding
>>>> sortActionListener) {
>>>> + this.sortActionListener = sortActionListener;
>>>> }
>>>>
>>>> public void queueEvent(FacesEvent facesEvent) {
>>>>
>>>> Modified:
>>>> incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/component/SheetTag.java
>>>>
>>>>
>>>> URL:
>>>> http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/component/SheetTag.java?rev=380866&r1=380865&r2=380866&view=diff
>>>>
>>>>
>>>> ==============================================================================
>>>>
>>>>
>>>> ---
>>>> incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/component/SheetTag.java
>>>>
>>>> (original)
>>>> +++
>>>> incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/component/SheetTag.java
>>>>
>>>> Fri Feb 24 15:37:31 2006
>>>> @@ -16,19 +16,7 @@
>>>> * limitations under the License.
>>>> */
>>>>
>>>> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_COLUMNS;
>>>> -import static
>>>> org.apache.myfaces.tobago.TobagoConstants.ATTR_DIRECT_LINK_COUNT;
>>>> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_FIRST;
>>>> -import static
>>>> org.apache.myfaces.tobago.TobagoConstants.ATTR_FORCE_VERTICAL_SCROLLBAR;
>>>>
>>>> -import static
>>>> org.apache.myfaces.tobago.TobagoConstants.ATTR_INNER_WIDTH;
>>>> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_ROWS;
>>>> -import static
>>>> org.apache.myfaces.tobago.TobagoConstants.ATTR_SHOW_DIRECT_LINKS;
>>>> -import static
>>>> org.apache.myfaces.tobago.TobagoConstants.ATTR_SHOW_HEADER;
>>>> -import static
>>>> org.apache.myfaces.tobago.TobagoConstants.ATTR_SHOW_PAGE_RANGE;
>>>> -import static
>>>> org.apache.myfaces.tobago.TobagoConstants.ATTR_SHOW_ROW_RANGE;
>>>> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_STATE;
>>>> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_VALUE;
>>>> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_VAR;
>>>> +import static org.apache.myfaces.tobago.TobagoConstants.*;
>>>> import org.apache.myfaces.tobago.apt.annotation.BodyContentDescription;
>>>> import org.apache.myfaces.tobago.apt.annotation.Tag;
>>>> import org.apache.myfaces.tobago.apt.annotation.TagAttribute;
>>>> @@ -59,6 +47,7 @@
>>>> private String forceVerticalScrollbar;
>>>> private String state;
>>>> private String stateChangeListener;
>>>> + private String sortActionListener;
>>>>
>>>> public String getComponentType() {
>>>> // TODO: implement uidata with overridden processUpdates to store
>>>> state
>>>> @@ -80,6 +69,7 @@
>>>> forceVerticalScrollbar = null;
>>>> state = null;
>>>> stateChangeListener = null;
>>>> + sortActionListener = null;
>>>> }
>>>>
>>>> protected void setProperties(UIComponent component) {
>>>> @@ -101,6 +91,7 @@
>>>> data.getAttributes().put(ATTR_INNER_WIDTH, new Integer(-1));
>>>> ComponentUtil.setValueBinding(component, ATTR_STATE, state);
>>>> ComponentUtil.setStateChangeListener(data, stateChangeListener);
>>>> + ComponentUtil.setSortActionListener(data, sortActionListener);
>>>>
>>>> }
>>>>
>>>> @@ -280,5 +271,24 @@
>>>> public void setStateChangeListener(String stateChangeListener) {
>>>> this.stateChangeListener = stateChangeListener;
>>>> }
>>>> +
>>>> + /**
>>>> + * MethodBinding representing an actionListener method that will be
>>>> + * invoked when sorting was requested by the user.
>>>> + * Use this if your application needs special handling for sorting
>>>> columns.
>>>> + * If this is not set and the sortable attribute column is not
>>>> false the sheet
>>>> + * implementation will use a default sort method.
>>>> + * The expression must evaluate to a public method that takes an
>>>> + * ActionEvent parameter, with a return type of void.
>>>> + * The parent of the actionEvents source will be the UIColumn
>>>> object for that
>>>> + * the sorting is requested,
>>>> + * <code>UIColumn column =
>>>> (UIColumn)actionEvent.getSource().getParent()</code>.
>>>> + */
>>>> + @TagAttribute
>>>> + @UIComponentTagAttribute()
>>>> + public void setSortActionListener(String sortActionListener) {
>>>> + this.sortActionListener = sortActionListener;
>>>> + }
>>>> +
>>>> }
>>>>
>>>>
>>>> Modified:
>>>> incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/TobagoDemoController.java
>>>>
>>>>
>>>> URL:
>>>> http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/TobagoDemoController.java?rev=380866&r1=380865&r2=380866&view=diff
>>>>
>>>>
>>>> ==============================================================================
>>>>
>>>>
>>>> ---
>>>> incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/TobagoDemoController.java
>>>>
>>>> (original)
>>>> +++
>>>> incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/TobagoDemoController.java
>>>>
>>>> Fri Feb 24 15:37:31 2006
>>>> @@ -61,6 +61,8 @@
>>>>
>>>> private SolarObject[] solarArray;
>>>>
>>>> + private List<SolarObject> solarList;
>>>> +
>>>> private List<UIColumn> solarArrayColumns;
>>>>
>>>> private String solarArrayColumnLayout;
>>>> @@ -148,6 +150,7 @@
>>>> = "**strong text**\n\n__emphasis__\n\nnormaler
>>>> text\n\n__dieses "
>>>> + "ist emphasis__\n\n**und nochmal strong**\n\n**__ strong
>>>> und emphasis__**";
>>>> solarArray = SolarObject.getArray();
>>>> + solarList = SolarObject.getList();
>>>> solarArrayColumns = createSolarArrayColumns();
>>>> solarArrayColumnLayout = "3*; 3*; 3*";
>>>>
>>>> @@ -292,6 +295,14 @@
>>>>
>>>> public void setSolarArray(SolarObject[] solarArray) {
>>>> this.solarArray = solarArray;
>>>> + }
>>>> +
>>>> + public List<SolarObject> getSolarList() {
>>>> + return solarList;
>>>> + }
>>>> +
>>>> + public void setSolarList(List<SolarObject> solarList) {
>>>> + this.solarList = solarList;
>>>> }
>>>>
>>>> public List<UIColumn> getSolarArrayColumns() {
>>>>
>>>> Modified:
>>>> incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/model/solar/SolarObject.java
>>>>
>>>>
>>>> URL:
>>>> http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/model/solar/SolarObject.java?rev=380866&r1=380865&r2=380866&view=diff
>>>>
>>>>
>>>> ==============================================================================
>>>>
>>>>
>>>> ---
>>>> incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/model/solar/SolarObject.java
>>>>
>>>> (original)
>>>> +++
>>>> incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/model/solar/SolarObject.java
>>>>
>>>> Fri Feb 24 15:37:31 2006
>>>> @@ -176,7 +176,17 @@
>>>> return array;
>>>> }
>>>>
>>>> - public static List<SolarObject> getSatellites(String center) {
>>>> +
>>>> + public static List<SolarObject> getList() {
>>>> + SolarObject[] array = getArray();
>>>> + List<SolarObject> list = new ArrayList<SolarObject>(array.length);
>>>> + for (SolarObject object : array) {
>>>> + list.add(object);
>>>> + }
>>>> + return list;
>>>> + }
>>>> +
>>>> + public static List<SolarObject> getSatellites(String center) {
>>>> List<SolarObject> collect = new ArrayList<SolarObject>();
>>>> SolarObject[] all = getArray();
>>>> for (int i = 0; i < all.length; i++) {
>>>>
>>>> Modified:
>>>> incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/OverviewController.java
>>>>
>>>>
>>>> URL:
>>>> http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/OverviewController.java?rev=380866&r1=380865&r2=380866&view=diff
>>>>
>>>>
>>>> ==============================================================================
>>>>
>>>>
>>>> ---
>>>> incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/OverviewController.java
>>>>
>>>> (original)
>>>> +++
>>>> incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/OverviewController.java
>>>>
>>>> Fri Feb 24 15:37:31 2006
>>>> @@ -23,9 +23,12 @@
>>>>
>>>> import org.apache.commons.logging.Log;
>>>> import org.apache.commons.logging.LogFactory;
>>>> +import org.apache.myfaces.tobago.component.Sorter;
>>>> +import org.apache.myfaces.tobago.component.UIData;
>>>> import org.apache.myfaces.tobago.context.ResourceManager;
>>>> import org.apache.myfaces.tobago.context.ResourceManagerFactory;
>>>>
>>>> +import javax.faces.component.UICommand;
>>>> import javax.faces.context.FacesContext;
>>>> import javax.faces.event.ActionEvent;
>>>> import javax.faces.model.SelectItem;
>>>> @@ -109,6 +112,19 @@
>>>>
>>>> public void click(ActionEvent actionEvent) {
>>>> lastAction = actionEvent.getComponent().getId();
>>>> + }
>>>> +
>>>> + + public void sheetSorter(ActionEvent event) {
>>>> + Object eventSource = event.getSource();
>>>> + UIData data = (UIData) ((UICommand)
>>>> eventSource).getParent().getParent();
>>>> + List list = (List) data.getValue();
>>>> + Object sun = list.remove(0);
>>>> + Object[] objects = new Object[1];
>>>> + objects[0] = event;
>>>> + Sorter sorter = new Sorter();
>>>> + sorter.invoke(FacesContext.getCurrentInstance(), objects);
>>>> + list.add(0, sun);
>>>> }
>>>>
>>>> public boolean getShowPopup() {
>>>>
>>>> Modified:
>>>> incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/SheetConfig.java
>>>>
>>>>
>>>> URL:
>>>> http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/SheetConfig.java?rev=380866&r1=380865&r2=380866&view=diff
>>>>
>>>>
>>>> ==============================================================================
>>>>
>>>>
>>>> ---
>>>> incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/SheetConfig.java
>>>>
>>>> (original)
>>>> +++
>>>> incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/SheetConfig.java
>>>>
>>>> Fri Feb 24 15:37:31 2006
>>>> @@ -47,7 +47,7 @@
>>>> private boolean sheetConfigPopup;
>>>>
>>>> public SheetConfig() {
>>>> - sheetPagingStart = 1;
>>>> + sheetPagingStart = 0;
>>>> sheetPagingLength = 7;
>>>> sheetDirectLinkCount = 5;
>>>> sheetDirectLinkCountItems = createSheetDirectLinkCountItems();
>>>>
>>>> Modified:
>>>> incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/overview/sheetControl.jsp
>>>>
>>>>
>>>> URL:
>>>> http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/overview/sheetControl.jsp?rev=380866&r1=380865&r2=380866&view=diff
>>>>
>>>>
>>>> ==============================================================================
>>>>
>>>>
>>>> ---
>>>> incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/overview/sheetControl.jsp
>>>>
>>>> (original)
>>>> +++
>>>> incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/overview/sheetControl.jsp
>>>>
>>>> Fri Feb 24 15:37:31 2006
>>>> @@ -106,7 +106,7 @@
>>>> </tc:toolBar>
>>>> </f:facet>
>>>>
>>>> - <tc:sheet value="#{demo.solarArray}" id="sheet"
>>>> + <tc:sheet value="#{demo.solarList}" id="sheet"
>>>> columns="3*;1*;3*;3*;3*;3*" var="luminary"
>>>> state="#{demo.sheetState}"
>>>>
>>>> showHeader="#{overviewController.sheetConfig.sheetShowHeader}"
>>>> @@ -116,7 +116,8 @@
>>>>
>>>> pagingStart="#{overviewController.sheetConfig.sheetPagingStart}"
>>>>
>>>> pagingLength="#{overviewController.sheetConfig.sheetPagingLength}"
>>>>
>>>> directLinkCount="#{overviewController.sheetConfig.sheetDirectLinkCount}"
>>>>
>>>> - stateChangeListener="#{demo.stateChangeListener}">
>>>> + stateChangeListener="#{demo.stateChangeListener}"
>>>> + sortActionListener="#{overviewController.sheetSorter}">
>>>> <tc:column label="#{overviewBundle.solarArrayName}"
>>>> id="name" sortable="true">
>>>> <tc:out value="#{luminary.name}" id="t_name" />
>>>> </tc:column>
>>>>
>>>> Modified:
>>>> incubator/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SheetRenderer.java
>>>>
>>>>
>>>> URL:
>>>> http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SheetRenderer.java?rev=380866&r1=380865&r2=380866&view=diff
>>>>
>>>>
>>>> ==============================================================================
>>>>
>>>>
>>>> ---
>>>> incubator/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SheetRenderer.java
>>>>
>>>> (original)
>>>> +++
>>>> incubator/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SheetRenderer.java
>>>>
>>>> Fri Feb 24 15:37:31 2006
>>>> @@ -23,44 +23,11 @@
>>>>
>>>> import org.apache.commons.logging.Log;
>>>> import org.apache.commons.logging.LogFactory;
>>>> -import static
>>>> org.apache.myfaces.tobago.TobagoConstants.ATTR_ACTION_STRING;
>>>> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_ALIGN;
>>>> -import static
>>>> org.apache.myfaces.tobago.TobagoConstants.ATTR_COMMAND_TYPE;
>>>> -import static
>>>> org.apache.myfaces.tobago.TobagoConstants.ATTR_DIRECT_LINK_COUNT;
>>>> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_DISABLED;
>>>> -import static
>>>> org.apache.myfaces.tobago.TobagoConstants.ATTR_FOOTER_HEIGHT;
>>>> -import static
>>>> org.apache.myfaces.tobago.TobagoConstants.ATTR_FORCE_VERTICAL_SCROLLBAR;
>>>>
>>>> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_IMAGE;
>>>> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_INLINE;
>>>> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_LABEL;
>>>> -import static
>>>> org.apache.myfaces.tobago.TobagoConstants.ATTR_LAYOUT_HEIGHT;
>>>> -import static
>>>> org.apache.myfaces.tobago.TobagoConstants.ATTR_MENU_POPUP;
>>>> -import static
>>>> org.apache.myfaces.tobago.TobagoConstants.ATTR_MENU_POPUP_TYPE;
>>>> -import static
>>>> org.apache.myfaces.tobago.TobagoConstants.ATTR_SELECTED_LIST_STRING;
>>>> -import static
>>>> org.apache.myfaces.tobago.TobagoConstants.ATTR_SHOW_DIRECT_LINKS;
>>>> -import static
>>>> org.apache.myfaces.tobago.TobagoConstants.ATTR_SHOW_PAGE_RANGE;
>>>> -import static
>>>> org.apache.myfaces.tobago.TobagoConstants.ATTR_SHOW_ROW_RANGE;
>>>> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_SORTABLE;
>>>> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_STYLE;
>>>> -import static
>>>> org.apache.myfaces.tobago.TobagoConstants.ATTR_STYLE_BODY;
>>>> -import static
>>>> org.apache.myfaces.tobago.TobagoConstants.ATTR_STYLE_CLASS;
>>>> -import static
>>>> org.apache.myfaces.tobago.TobagoConstants.ATTR_STYLE_HEADER;
>>>> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_TYPE;
>>>> -import static
>>>> org.apache.myfaces.tobago.TobagoConstants.ATTR_WIDTH_LIST;
>>>> -import static
>>>> org.apache.myfaces.tobago.TobagoConstants.ATTR_WIDTH_LIST_STRING;
>>>> -import static
>>>> org.apache.myfaces.tobago.TobagoConstants.COMMAND_TYPE_SCRIPT;
>>>> -import static
>>>> org.apache.myfaces.tobago.TobagoConstants.FACET_MENUPOPUP;
>>>> -import static
>>>> org.apache.myfaces.tobago.TobagoConstants.FACET_PAGER_PAGE;
>>>> -import static
>>>> org.apache.myfaces.tobago.TobagoConstants.FACET_PAGER_ROW;
>>>> -import static
>>>> org.apache.myfaces.tobago.TobagoConstants.RENDERER_TYPE_LINK;
>>>> -import static
>>>> org.apache.myfaces.tobago.TobagoConstants.RENDERER_TYPE_MENUBAR;
>>>> -import static
>>>> org.apache.myfaces.tobago.TobagoConstants.RENDERER_TYPE_MENUCOMMAND;
>>>> -import static
>>>> org.apache.myfaces.tobago.TobagoConstants.SUBCOMPONENT_SEP;
>>>> +import static org.apache.myfaces.tobago.TobagoConstants.*;
>>>> import org.apache.myfaces.tobago.ajax.api.AjaxRenderer;
>>>> import org.apache.myfaces.tobago.ajax.api.AjaxUtils;
>>>> import org.apache.myfaces.tobago.component.ComponentUtil;
>>>> import org.apache.myfaces.tobago.component.Pager;
>>>> -import org.apache.myfaces.tobago.component.Sorter;
>>>> import org.apache.myfaces.tobago.component.UIColumnSelector;
>>>> import org.apache.myfaces.tobago.component.UIData;
>>>> import org.apache.myfaces.tobago.config.TobagoConfig;
>>>> @@ -77,22 +44,13 @@
>>>> import org.apache.myfaces.tobago.webapp.TobagoResponseWriter;
>>>>
>>>> import javax.faces.application.Application;
>>>> -import javax.faces.component.UIColumn;
>>>> -import javax.faces.component.UICommand;
>>>> -import javax.faces.component.UIComponent;
>>>> -import javax.faces.component.UIPanel;
>>>> -import javax.faces.component.UIViewRoot;
>>>> +import javax.faces.component.*;
>>>> import javax.faces.context.FacesContext;
>>>> import javax.faces.context.ResponseWriter;
>>>> import javax.faces.el.MethodBinding;
>>>> import java.io.IOException;
>>>> import java.text.MessageFormat;
>>>> -import java.util.ArrayList;
>>>> -import java.util.Collections;
>>>> -import java.util.Iterator;
>>>> -import java.util.List;
>>>> -import java.util.Locale;
>>>> -import java.util.Map;
>>>> +import java.util.*;
>>>>
>>>> public class SheetRenderer extends RendererBase
>>>> implements SheetRendererWorkaround, AjaxRenderer {
>>>> @@ -774,7 +732,7 @@
>>>> String image1x1, int sortMarkerWidth) throws IOException {
>>>> String sheetId = component.getClientId(facesContext);
>>>> Application application = facesContext.getApplication();
>>>> - Sorter sorter = component.getSorter();
>>>> + MethodBinding sorter = component.getSortActionListener();
>>>>
>>>> List columnWidths
>>>> = (List) component.getAttributes().get(ATTR_WIDTH_LIST);
>>>> @@ -797,18 +755,23 @@
>>>> ComponentUtil.getBooleanAttribute(column,
>>>> ATTR_SORTABLE);
>>>> if (sortable && !(column instanceof UIColumnSelector)) {
>>>> - String sorterId = Sorter.ID_PREFIX + columnCount;
>>>> + UICommand sortCommand = (UICommand)
>>>> column.getFacet(UIData.FACET_SORTER);
>>>> + if (sortCommand == null) {
>>>> + String columnId = column.getClientId(facesContext);
>>>> + String sorterId =
>>>> columnId.substring(columnId.lastIndexOf(":") + 1 )
>>>> + + "_" + UIData.SORTER_ID;
>>>> + sortCommand
>>>> + = (UICommand)
>>>> application.createComponent(UICommand.COMPONENT_TYPE);
>>>> + sortCommand.setRendererType(RENDERER_TYPE_LINK);
>>>> + sortCommand.setActionListener(sorter);
>>>> + sortCommand.setId(sorterId);
>>>> + column.getFacets().put(UIData.FACET_SORTER,
>>>> sortCommand); + }
>>>> +
>>>> String onclick = "submitAction('"
>>>> + ComponentUtil.findPage(component).getFormId(facesContext)
>>>> - + "','" + component.getClientId(facesContext) + ":" +
>>>> sorterId + "')";
>>>> + + "','" + sortCommand.getClientId(facesContext) + "')";
>>>> writer.writeAttribute("onclick", onclick, null);
>>>> - UICommand sortCommand = (UICommand)
>>>> - application.createComponent(UICommand.COMPONENT_TYPE);
>>>> - sortCommand.setRendererType(RENDERER_TYPE_LINK);
>>>> - sortCommand.setActionListener(sorter);
>>>> - sortCommand.setId(sorterId);
>>>> - component.getFacets().put(sorterId, sortCommand);
>>>> - sortCommand.getClientId(facesContext); // this must called here
>>>> to fix the ClientId
>>>>
>>>> writer.writeAttribute("title",
>>>> ResourceManagerUtil.getPropertyNotNull(facesContext,
>>>> "tobago",
>>>>
>>>> Modified:
>>>> incubator/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-sheet.js
>>>>
>>>>
>>>> URL:
>>>> http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-sheet.js?rev=380866&r1=380865&r2=380866&view=diff
>>>>
>>>>
>>>> ==============================================================================
>>>>
>>>>
>>>> ---
>>>> incubator/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-sheet.js
>>>>
>>>> (original)
>>>> +++
>>>> incubator/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-sheet.js
>>>>
>>>> Fri Feb 24 15:37:31 2006
>>>> @@ -34,6 +34,9 @@
>>>> LOG.debug("New Sheet with id " + this.sheetId);
>>>> },
>>>>
>>>> + sortOnclickRegExp :
>>>> + new RegExp("submitAction\\(('|\")(.*?)('|\") *,
>>>> *('|\")(.*?)('|\")\\)"),
>>>> +
>>>> setup: function() {
>>>>
>>>> // setup sorting headers
>>>> @@ -42,7 +45,18 @@
>>>> var headerBox = $(idPrefix + i++);
>>>> while (headerBox) {
>>>> if (headerBox.onclick) {
>>>> + var match =
>>>> this.sortOnclickRegExp.exec(headerBox.onclick.valueOf());
>>>> +// LOG.debug("match[0] = " + match[0]);
>>>> +// LOG.debug("match[1] = " + match[1]);
>>>> +// LOG.debug("*match[2] = " + match[2]);
>>>> +// LOG.debug("match[3] = " + match[3]);
>>>> +// LOG.debug("match[4] = " + match[4]);
>>>> +// LOG.debug("*match[5] = " + match[5]);
>>>> +// LOG.debug("match[6] = " + match[6]);
>>>> +// headerBox.formId = match[2];
>>>> + headerBox.sorterId = match[5];
>>>> headerBox.onclick = null;
>>>> +// LOG.debug("headerBox.id = " + headerBox.id);
>>>> Event.observe(headerBox, "click",
>>>> this.doSort.bindAsEventListener(this));
>>>> }
>>>> headerBox = $(idPrefix + i++);
>>>> @@ -97,10 +111,12 @@
>>>>
>>>> doSort: function(event) {
>>>> var element = Event.element(event);
>>>> - var idx = element.id.lastIndexOf('_');
>>>> - idx = element.id.substring(idx + 1);
>>>> - var action = this.sheetId + Tobago.componentSeparator + "sorter_"
>>>> + idx;
>>>> - this.reloadWithAction(action);
>>>> + if (!element.sorterId) {
>>>> + element = element.parentNode;
>>>> + }
>>>> +// LOG.debug("element.id = " + element.id);
>>>> +// LOG.debug("sorterId = " + element.sorterId);
>>>> + this.reloadWithAction(element.sorterId);
>>>> },
>>>>
>>>> doPagingDirect: function(event) {
>>>>
>>>>
>>>>
>>>
>>
>
--
Don't answer to From: address!
Mail to this account are droped if not recieved via mailinglist.
To contact me direct create the mail address by
concatenating my forename to my senders domain.
Re: svn commit: r380866 - in /incubator/tobago/trunk: tobago-core/src/main/java/org/apache/myfaces/tobago/component/
tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/component/ tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/t...
Posted by Bernd Bohmann <be...@atanion.com>.
I think so, but now I go to a Kohlfahrt.
We can discuss this tommorrow :-)
Volker Weber schrieb:
> Hi Bernd,
>
> the sheet was already using a actionListener methodBinding to do the
> sort. The (mainly) only thing i did was to enable defining the
> methodBinding to use in the sheetTag.
>
> Hmmm, when i started to write this mail, i thought it where mutch more
> complicated to change this to queue a SortActionEvent instead of an
> standard ActionEvent, because the event is generated in the
> CommandRendererBase, but i just got an idea how to catch and replace
> this ActionEvent with a SortActionEvent.
>
> This could be done in the queueEvent() method of UIData.
> Thoughts?
>
> Regards,
> Volker
>
> Bernd Bohmann wrote:
>
>>Hi Volker,
>>
>>I would prefer an actionListener and a SortActionEvent instead of a
>>sortActionListener.
>>
>>I don't like the x XYZActionListener.
>>
>>Can you change it?
>>
>>Regards
>>
>>Bernd
>>
>>weber@apache.org schrieb:
>>
>>
>>>Author: weber
>>>Date: Fri Feb 24 15:37:31 2006
>>>New Revision: 380866
>>>
>>>URL: http://svn.apache.org/viewcvs?rev=380866&view=rev
>>>Log:
>>>add sortActionListener attribute to sheet
>>>
>>>Modified:
>>>
>>>incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/ComponentUtil.java
>>>
>>>
>>>incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/Sorter.java
>>>
>>>
>>>incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/UIData.java
>>>
>>>
>>>incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/component/SheetTag.java
>>>
>>>
>>>incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/TobagoDemoController.java
>>>
>>>
>>>incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/model/solar/SolarObject.java
>>>
>>>
>>>incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/OverviewController.java
>>>
>>>
>>>incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/SheetConfig.java
>>>
>>>
>>>incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/overview/sheetControl.jsp
>>>
>>>
>>>incubator/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SheetRenderer.java
>>>
>>>
>>>incubator/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-sheet.js
>>>
>>>
>>>Modified:
>>>incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/ComponentUtil.java
>>>
>>>URL:
>>>http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/ComponentUtil.java?rev=380866&r1=380865&r2=380866&view=diff
>>>
>>>==============================================================================
>>>
>>>---
>>>incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/ComponentUtil.java
>>>(original)
>>>+++
>>>incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/ComponentUtil.java
>>>Fri Feb 24 15:37:31 2006
>>>@@ -23,30 +23,7 @@
>>>
>>> import org.apache.commons.logging.Log;
>>> import org.apache.commons.logging.LogFactory;
>>>-import static org.apache.myfaces.tobago.TobagoConstants.ATTR_ACCESS_KEY;
>>>-import static
>>>org.apache.myfaces.tobago.TobagoConstants.ATTR_ACTION_STRING;
>>>-import static org.apache.myfaces.tobago.TobagoConstants.ATTR_ALIGN;
>>>-import static org.apache.myfaces.tobago.TobagoConstants.ATTR_DISABLED;
>>>-import static org.apache.myfaces.tobago.TobagoConstants.ATTR_FOR;
>>>-import static org.apache.myfaces.tobago.TobagoConstants.ATTR_HOVER;
>>>-import static org.apache.myfaces.tobago.TobagoConstants.ATTR_LABEL;
>>>-import static
>>>org.apache.myfaces.tobago.TobagoConstants.ATTR_LABEL_WITH_ACCESS_KEY;
>>>-import static org.apache.myfaces.tobago.TobagoConstants.ATTR_READONLY;
>>>-import static
>>>org.apache.myfaces.tobago.TobagoConstants.ATTR_RENDER_RANGE;
>>>-import static
>>>org.apache.myfaces.tobago.TobagoConstants.ATTR_RENDER_RANGE_EXTERN;
>>>-import static org.apache.myfaces.tobago.TobagoConstants.ATTR_SORTABLE;
>>>-import static org.apache.myfaces.tobago.TobagoConstants.ATTR_VALUE;
>>>-import static
>>>org.apache.myfaces.tobago.TobagoConstants.COMMAND_TYPE_NAVIGATE;
>>>-import static
>>>org.apache.myfaces.tobago.TobagoConstants.COMMAND_TYPE_RESET;
>>>-import static
>>>org.apache.myfaces.tobago.TobagoConstants.COMMAND_TYPE_SCRIPT;
>>>-import static org.apache.myfaces.tobago.TobagoConstants.FACET_CHECKBOX;
>>>-import static org.apache.myfaces.tobago.TobagoConstants.FACET_LABEL;
>>>-import static org.apache.myfaces.tobago.TobagoConstants.FACET_RADIO;
>>>-import static
>>>org.apache.myfaces.tobago.TobagoConstants.RENDERER_TYPE_OUT;
>>>-import static
>>>org.apache.myfaces.tobago.TobagoConstants.RENDERER_TYPE_SELECT_BOOLEAN_CHECKBOX;
>>>
>>>-import static
>>>org.apache.myfaces.tobago.TobagoConstants.RENDERER_TYPE_SELECT_ONE_RADIO;
>>>-import static
>>>org.apache.myfaces.tobago.TobagoConstants.ATTR_CREATE_SPAN;
>>>-import static org.apache.myfaces.tobago.TobagoConstants.ATTR_ESCAPE;
>>>+import static org.apache.myfaces.tobago.TobagoConstants.*;
>>> import org.apache.myfaces.tobago.el.ConstantMethodBinding;
>>> import org.apache.myfaces.tobago.event.SheetStateChangeEvent;
>>> import org.apache.myfaces.tobago.renderkit.RendererBase;
>>>@@ -55,33 +32,22 @@
>>>
>>> import javax.faces.FactoryFinder;
>>> import javax.faces.application.Application;
>>>-import javax.faces.component.ActionSource;
>>>-import javax.faces.component.EditableValueHolder;
>>>-import javax.faces.component.UIColumn;
>>>+import javax.faces.component.*;
>>> import javax.faces.component.UICommand;
>>>-import javax.faces.component.UIComponent;
>>>-import javax.faces.component.UIGraphic;
>>> import javax.faces.component.UIOutput;
>>>-import javax.faces.component.UIParameter;
>>>-import javax.faces.component.UISelectBoolean;
>>> import javax.faces.component.UISelectItem;
>>>-import javax.faces.component.UISelectItems;
>>>-import javax.faces.component.ValueHolder;
>>> import javax.faces.context.FacesContext;
>>> import javax.faces.convert.Converter;
>>> import javax.faces.el.MethodBinding;
>>> import javax.faces.el.ValueBinding;
>>>+import javax.faces.event.ActionEvent;
>>> import javax.faces.event.ActionListener;
>>> import javax.faces.model.SelectItem;
>>> import javax.faces.render.RenderKit;
>>> import javax.faces.render.RenderKitFactory;
>>> import javax.faces.webapp.UIComponentTag;
>>> import javax.servlet.jsp.JspException;
>>>-import java.util.ArrayList;
>>>-import java.util.Collection;
>>>-import java.util.Iterator;
>>>-import java.util.List;
>>>-import java.util.Map;
>>>+import java.util.*;
>>>
>>> public class ComponentUtil {
>>>
>>>@@ -90,6 +56,9 @@
>>> private static final String RENDER_KEY_PREFIX
>>> =
>>>"org.apache.myfaces.tobago.component.ComponentUtil.RendererKeyPrefix_";
>>>
>>>+ private static final Class[] ACTION_LISTENER_ARGS =
>>>{ActionEvent.class};
>>>+
>>>+
>>> private ComponentUtil() {
>>> }
>>>
>>>@@ -917,13 +886,27 @@
>>> final Application application = facesContext.getApplication();
>>> if (actionListener != null) {
>>> if (UIComponentTag.isValueReference(actionListener)) {
>>>- Class[] arguments = {javax.faces.event.ActionEvent.class};
>>> MethodBinding binding
>>>- = application.createMethodBinding(actionListener,
>>>arguments);
>>>+ = application.createMethodBinding(actionListener,
>>>ACTION_LISTENER_ARGS);
>>> command.setActionListener(binding);
>>> } else {
>>> throw new IllegalArgumentException(
>>> "Must be a valueReference (actionListener): " +
>>>actionListener);
>>>+ }
>>>+ }
>>>+ }
>>>+
>>>+ public static void setSortActionListener(UIData data, String
>>>actionListener) {
>>>+ final FacesContext facesContext = FacesContext.getCurrentInstance();
>>>+ final Application application = facesContext.getApplication();
>>>+ if (actionListener != null) {
>>>+ if (UIComponentTag.isValueReference(actionListener)) {
>>>+ MethodBinding binding
>>>+ = application.createMethodBinding(actionListener,
>>>ACTION_LISTENER_ARGS);
>>>+ data.setSortActionListener(binding);
>>>+ } else {
>>>+ throw new IllegalArgumentException(
>>>+ "Must be a valueReference (sortActionListener): " +
>>>actionListener);
>>> }
>>> }
>>> }
>>>
>>>Modified:
>>>incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/Sorter.java
>>>
>>>URL:
>>>http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/Sorter.java?rev=380866&r1=380865&r2=380866&view=diff
>>>
>>>==============================================================================
>>>
>>>---
>>>incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/Sorter.java
>>>(original)
>>>+++
>>>incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/Sorter.java
>>>Fri Feb 24 15:37:31 2006
>>>@@ -21,15 +21,12 @@
>>> import org.apache.myfaces.tobago.TobagoConstants;
>>> import static org.apache.myfaces.tobago.TobagoConstants.ATTR_SORTABLE;
>>> import org.apache.myfaces.tobago.model.SheetState;
>>>-import org.apache.myfaces.tobago.model.SortableByApplication;
>>> import org.apache.myfaces.tobago.util.BeanComparator;
>>> import org.apache.myfaces.tobago.util.ValueBindingComparator;
>>>
>>>-import javax.faces.component.UIColumn;
>>>-import javax.faces.component.UIComponent;
>>>+import javax.faces.component.*;
>>> import javax.faces.component.UIInput;
>>> import javax.faces.component.UIOutput;
>>>-import javax.faces.component.UISelectBoolean;
>>> import javax.faces.context.FacesContext;
>>> import javax.faces.el.EvaluationException;
>>> import javax.faces.el.MethodBinding;
>>>@@ -37,11 +34,7 @@
>>> import javax.faces.el.ValueBinding;
>>> import javax.faces.event.ActionEvent;
>>> import javax.faces.model.DataModel;
>>>-import java.util.Arrays;
>>>-import java.util.Collections;
>>>-import java.util.Comparator;
>>>-import java.util.Iterator;
>>>-import java.util.List;
>>>+import java.util.*;
>>>
>>> /**
>>> * User: weber
>>>@@ -52,8 +45,6 @@
>>>
>>> private static final Log LOG = LogFactory.getLog(Sorter.class);
>>>
>>>- public static final String ID_PREFIX = "sorter_";
>>>-
>>>
>>> public Object invoke(FacesContext facesContext, Object[] aobj)
>>> throws EvaluationException {
>>>@@ -63,87 +54,66 @@
>>> if (LOG.isDebugEnabled()) {
>>> LOG.debug("sorterId = " + command.getId());
>>> }
>>>- UIData data = (UIData) command.getParent();
>>>+ UIColumn column = (UIColumn) command.getParent();
>>>+ UIData data = (UIData) column.getParent();
>>>+
>>> Object value = data.getValue();
>>> if (value instanceof DataModel) {
>>> value = ((DataModel) value).getWrappedData();
>>> }
>>> SheetState sheetState = data.getSheetState(facesContext);
>>>- int column = sheetState.getSortedColumn();
>>>- boolean ascending = sheetState.isAscending();
>>>
>>> Comparator comparator = null;
>>>
>>>- if (value instanceof SortableByApplication
>>>- || value instanceof List
>>>- || value instanceof Object[]) {
>>>+ if (value instanceof List || value instanceof Object[]) {
>>> String sortProperty;
>>>
>>>- if (command.getId() != null &&
>>>command.getId().startsWith(ID_PREFIX)) {
>>>- UIColumn uiColumn = null;
>>>- try {
>>>- int actualColumn =
>>>- Integer.parseInt(
>>>- command.getId().substring(ID_PREFIX.length()));
>>>- if (actualColumn == column) {
>>>- ascending = !ascending;
>>>- } else {
>>>- ascending = true;
>>>- column = actualColumn;
>>>- }
>>>- sheetState.setAscending(ascending);
>>>- sheetState.setSortedColumn(column);
>>>+ try {
>>>+ if (!updateSheetState(data, column, sheetState)) {
>>>+ return null;
>>>+ }
>>>
>>>- uiColumn = data.getRendererdColumns().get(column);
>>>- UIComponent child =
>>>getFirstSortableChild(uiColumn.getChildren());
>>>- if (child != null) {
>>>- ValueBinding valueBinding =
>>>child.getValueBinding("value");
>>>- String var = data.getVar();
>>>-
>>>- if (valueBinding != null) {
>>>- if
>>>(isSimpleProperty(valueBinding.getExpressionString())) {
>>>- String expressionString =
>>>valueBinding.getExpressionString();
>>>- if (expressionString.startsWith("#{")
>>>- && expressionString.endsWith("}")) {
>>>- expressionString =
>>>- expressionString.substring(2,
>>>- expressionString.length() - 1);
>>>- }
>>>- sortProperty =
>>>expressionString.substring(var.length() + 1);
>>>-
>>>- comparator = new BeanComparator(sortProperty, null,
>>>!ascending);
>>>-
>>>- if (LOG.isDebugEnabled()) {
>>>- LOG.debug("Sort property is " + sortProperty);
>>>- }
>>>- } else {
>>>- comparator = new
>>>ValueBindingComparator(facesContext, var, valueBinding, !ascending);
>>>+ UIComponent child =
>>>getFirstSortableChild(column.getChildren());
>>>+ if (child != null) {
>>>+ ValueBinding valueBinding = child.getValueBinding("value");
>>>+ String var = data.getVar();
>>>+
>>>+ if (valueBinding != null) {
>>>+ if
>>>(isSimpleProperty(valueBinding.getExpressionString())) {
>>>+ String expressionString =
>>>valueBinding.getExpressionString();
>>>+ if (expressionString.startsWith("#{")
>>>+ && expressionString.endsWith("}")) {
>>>+ expressionString =
>>>+ expressionString.substring(2,
>>>+ expressionString.length() - 1);
>>> }
>>>- }
>>>+ sortProperty =
>>>expressionString.substring(var.length() + 1);
>>>
>>>- } else {
>>>- LOG.error("No sortable component found!");
>>>- removeSortableAttribute(uiColumn);
>>>- return null;
>>>- }
>>>- } catch (Exception e) {
>>>- LOG.error("Error while extracting sortMethod :" +
>>>e.getMessage(), e);
>>>- if (uiColumn != null) {
>>>- removeSortableAttribute(uiColumn);
>>>+ comparator = new BeanComparator(
>>>+ sortProperty, null, !sheetState.isAscending());
>>>+
>>>+ if (LOG.isDebugEnabled()) {
>>>+ LOG.debug("Sort property is " + sortProperty);
>>>+ }
>>>+ } else {
>>>+ comparator = new ValueBindingComparator(
>>>+ facesContext, var, valueBinding,
>>>!sheetState.isAscending());
>>>+ }
>>> }
>>>+
>>>+ } else {
>>>+ LOG.error("No sortable component found!");
>>>+ removeSortableAttribute(column);
>>> return null;
>>> }
>>>- } else {
>>>- LOG.error(
>>>- "Sorter.invoke() with illegal id in ActionEvent's
>>>source");
>>>+ } catch (Exception e) {
>>>+ LOG.error("Error while extracting sortMethod :" +
>>>e.getMessage(), e);
>>>+ if (column != null) {
>>>+ removeSortableAttribute(column);
>>>+ }
>>> return null;
>>> }
>>>
>>>- //if (value instanceof SortableByApplication) {
>>>- //((SortableByApplication) value).sortBy(sortProperty);
>>>-
>>>- // TODO ???? sortable by application
>>>- if (!(value instanceof SortableByApplication)) {
>>> // TODO: locale / comparator parameter?
>>> // don't compare numbers with Collator.getInstance()
>>>comparator
>>> // Comparator comparator = Collator.getInstance();
>>>@@ -151,16 +121,43 @@
>>>
>>> if (value instanceof List) {
>>> Collections.sort((List) value, comparator);
>>>- } else { // if (value instanceof Object[]) {
>>>+ } else { // value is instanceof Object[]
>>> Arrays.sort((Object[]) value, comparator);
>>> }
>>>- }
>>>+
>>> } else { // DataModel?, ResultSet, Result or Object
>>> LOG.warn("Sorting not supported for type "
>>> + (value != null ? value.getClass().toString() :
>>>"null"));
>>> }
>>> }
>>> return null;
>>>+ }
>>>+
>>>+ private boolean updateSheetState(UIData data, UIColumn uiColumn,
>>>SheetState sheetState) {
>>>+ int actualColumn = -1;
>>>+ List<UIColumn> rendererdColumns = data.getRendererdColumns();
>>>+ for (int i = 0; i < rendererdColumns.size(); i++) {
>>>+ if (uiColumn == rendererdColumns.get(i)) {
>>>+ actualColumn = i;
>>>+ break;
>>>+ }
>>>+ }
>>>+ if (actualColumn == -1) {
>>>+ LOG.warn("Can't find column to sort in rendered columns of
>>>sheet!");
>>>+ return false;
>>>+ }
>>>+
>>>+ int column = sheetState.getSortedColumn();
>>>+ boolean ascending = sheetState.isAscending();
>>>+ if (actualColumn == column) {
>>>+ ascending = !ascending;
>>>+ } else {
>>>+ ascending = true;
>>>+ column = actualColumn;
>>>+ }
>>>+ sheetState.setAscending(ascending);
>>>+ sheetState.setSortedColumn(column);
>>>+ return true;
>>> }
>>>
>>> private boolean isSimpleProperty(String expressionString) {
>>>
>>>Modified:
>>>incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/UIData.java
>>>
>>>URL:
>>>http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/UIData.java?rev=380866&r1=380865&r2=380866&view=diff
>>>
>>>==============================================================================
>>>
>>>---
>>>incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/UIData.java
>>>(original)
>>>+++
>>>incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/UIData.java
>>>Fri Feb 24 15:37:31 2006
>>>@@ -53,12 +53,14 @@
>>>
>>> public static final String COMPONENT_TYPE =
>>>"org.apache.myfaces.tobago.Data";
>>>
>>>+ public static final String FACET_SORTER = "sorter";
>>>+ public static final String SORTER_ID = "sorter";
>>>+
>>> private MethodBinding stateChangeListener;
>>>
>>> private List<Integer> widthList;
>>>
>>>- // TODO: should be removed?
>>>- private Sorter sorter;
>>>+ private MethodBinding sortActionListener;
>>>
>>> private SheetState sheetState;
>>>
>>>@@ -320,10 +322,10 @@
>>> private void updateSheetState(FacesContext facesContext) {
>>> SheetState state = getSheetState(facesContext);
>>> if (state != null) {
>>>- // ensure sorter
>>>-// getSorter();
>>>-// state.setSortedColumn(sorter != null ? sorter.getColumn() : -1);
>>>-// state.setAscending(sorter != null && sorter.isAscending());
>>>+ // ensure sortActionListener
>>>+// getSortActionListener();
>>>+// state.setSortedColumn(sortActionListener != null ?
>>>sortActionListener.getColumn() : -1);
>>>+// state.setAscending(sortActionListener != null &&
>>>sortActionListener.isAscending());
>>> state.setSelectedRows((List<Integer>)
>>> getAttributes().get(ATTR_SELECTED_LIST_STRING));
>>> state.setColumnWidths((String)
>>>@@ -335,7 +337,7 @@
>>> Object[] saveState = new Object[5];
>>> saveState[0] = super.saveState(context);
>>> saveState[1] = sheetState;
>>>- saveState[2] = sorter;
>>>+ saveState[2] = saveAttachedState(context, sortActionListener);
>>> saveState[3] = saveAttachedState(context, stateChangeListener);
>>> if (showHeaderSet) {
>>> saveState[4] = showHeader;
>>>@@ -347,7 +349,7 @@
>>> Object[] values = (Object[]) savedState;
>>> super.restoreState(context, values[0]);
>>> sheetState = (SheetState) values[1];
>>>- sorter = (Sorter) values[2];
>>>+ sortActionListener = (MethodBinding)
>>>restoreAttachedState(context, values[2]);
>>> stateChangeListener = (MethodBinding)
>>>restoreAttachedState(context, values[3]);
>>> if (values[4] != null) {
>>> showHeaderSet = true;
>>>@@ -376,17 +378,16 @@
>>> return columns;
>>> }
>>>
>>>- // TODO: should be removed?
>>>- public Sorter getSorter() {
>>>- if (sorter != null) {
>>>- return sorter;
>>>+ public MethodBinding getSortActionListener() {
>>>+ if (sortActionListener != null) {
>>>+ return sortActionListener;
>>> } else {
>>> return new Sorter();
>>> }
>>> }
>>>
>>>- public void setSorter(Sorter sorter) {
>>>- this.sorter = sorter;
>>>+ public void setSortActionListener(MethodBinding sortActionListener) {
>>>+ this.sortActionListener = sortActionListener;
>>> }
>>>
>>> public void queueEvent(FacesEvent facesEvent) {
>>>
>>>Modified:
>>>incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/component/SheetTag.java
>>>
>>>URL:
>>>http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/component/SheetTag.java?rev=380866&r1=380865&r2=380866&view=diff
>>>
>>>==============================================================================
>>>
>>>---
>>>incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/component/SheetTag.java
>>>(original)
>>>+++
>>>incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/component/SheetTag.java
>>>Fri Feb 24 15:37:31 2006
>>>@@ -16,19 +16,7 @@
>>> * limitations under the License.
>>> */
>>>
>>>-import static org.apache.myfaces.tobago.TobagoConstants.ATTR_COLUMNS;
>>>-import static
>>>org.apache.myfaces.tobago.TobagoConstants.ATTR_DIRECT_LINK_COUNT;
>>>-import static org.apache.myfaces.tobago.TobagoConstants.ATTR_FIRST;
>>>-import static
>>>org.apache.myfaces.tobago.TobagoConstants.ATTR_FORCE_VERTICAL_SCROLLBAR;
>>>-import static
>>>org.apache.myfaces.tobago.TobagoConstants.ATTR_INNER_WIDTH;
>>>-import static org.apache.myfaces.tobago.TobagoConstants.ATTR_ROWS;
>>>-import static
>>>org.apache.myfaces.tobago.TobagoConstants.ATTR_SHOW_DIRECT_LINKS;
>>>-import static
>>>org.apache.myfaces.tobago.TobagoConstants.ATTR_SHOW_HEADER;
>>>-import static
>>>org.apache.myfaces.tobago.TobagoConstants.ATTR_SHOW_PAGE_RANGE;
>>>-import static
>>>org.apache.myfaces.tobago.TobagoConstants.ATTR_SHOW_ROW_RANGE;
>>>-import static org.apache.myfaces.tobago.TobagoConstants.ATTR_STATE;
>>>-import static org.apache.myfaces.tobago.TobagoConstants.ATTR_VALUE;
>>>-import static org.apache.myfaces.tobago.TobagoConstants.ATTR_VAR;
>>>+import static org.apache.myfaces.tobago.TobagoConstants.*;
>>> import org.apache.myfaces.tobago.apt.annotation.BodyContentDescription;
>>> import org.apache.myfaces.tobago.apt.annotation.Tag;
>>> import org.apache.myfaces.tobago.apt.annotation.TagAttribute;
>>>@@ -59,6 +47,7 @@
>>> private String forceVerticalScrollbar;
>>> private String state;
>>> private String stateChangeListener;
>>>+ private String sortActionListener;
>>>
>>> public String getComponentType() {
>>> // TODO: implement uidata with overridden processUpdates to store
>>>state
>>>@@ -80,6 +69,7 @@
>>> forceVerticalScrollbar = null;
>>> state = null;
>>> stateChangeListener = null;
>>>+ sortActionListener = null;
>>> }
>>>
>>> protected void setProperties(UIComponent component) {
>>>@@ -101,6 +91,7 @@
>>> data.getAttributes().put(ATTR_INNER_WIDTH, new Integer(-1));
>>> ComponentUtil.setValueBinding(component, ATTR_STATE, state);
>>> ComponentUtil.setStateChangeListener(data, stateChangeListener);
>>>+ ComponentUtil.setSortActionListener(data, sortActionListener);
>>>
>>> }
>>>
>>>@@ -280,5 +271,24 @@
>>> public void setStateChangeListener(String stateChangeListener) {
>>> this.stateChangeListener = stateChangeListener;
>>> }
>>>+
>>>+ /**
>>>+ * MethodBinding representing an actionListener method that will be
>>>+ * invoked when sorting was requested by the user.
>>>+ * Use this if your application needs special handling for sorting
>>>columns.
>>>+ * If this is not set and the sortable attribute column is not
>>>false the sheet
>>>+ * implementation will use a default sort method.
>>>+ * The expression must evaluate to a public method that takes an
>>>+ * ActionEvent parameter, with a return type of void.
>>>+ * The parent of the actionEvents source will be the UIColumn
>>>object for that
>>>+ * the sorting is requested,
>>>+ * <code>UIColumn column =
>>>(UIColumn)actionEvent.getSource().getParent()</code>.
>>>+ */
>>>+ @TagAttribute
>>>+ @UIComponentTagAttribute()
>>>+ public void setSortActionListener(String sortActionListener) {
>>>+ this.sortActionListener = sortActionListener;
>>>+ }
>>>+
>>> }
>>>
>>>
>>>Modified:
>>>incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/TobagoDemoController.java
>>>
>>>URL:
>>>http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/TobagoDemoController.java?rev=380866&r1=380865&r2=380866&view=diff
>>>
>>>==============================================================================
>>>
>>>---
>>>incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/TobagoDemoController.java
>>>(original)
>>>+++
>>>incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/TobagoDemoController.java
>>>Fri Feb 24 15:37:31 2006
>>>@@ -61,6 +61,8 @@
>>>
>>> private SolarObject[] solarArray;
>>>
>>>+ private List<SolarObject> solarList;
>>>+
>>> private List<UIColumn> solarArrayColumns;
>>>
>>> private String solarArrayColumnLayout;
>>>@@ -148,6 +150,7 @@
>>> = "**strong text**\n\n__emphasis__\n\nnormaler
>>>text\n\n__dieses "
>>> + "ist emphasis__\n\n**und nochmal strong**\n\n**__ strong
>>>und emphasis__**";
>>> solarArray = SolarObject.getArray();
>>>+ solarList = SolarObject.getList();
>>> solarArrayColumns = createSolarArrayColumns();
>>> solarArrayColumnLayout = "3*; 3*; 3*";
>>>
>>>@@ -292,6 +295,14 @@
>>>
>>> public void setSolarArray(SolarObject[] solarArray) {
>>> this.solarArray = solarArray;
>>>+ }
>>>+
>>>+ public List<SolarObject> getSolarList() {
>>>+ return solarList;
>>>+ }
>>>+
>>>+ public void setSolarList(List<SolarObject> solarList) {
>>>+ this.solarList = solarList;
>>> }
>>>
>>> public List<UIColumn> getSolarArrayColumns() {
>>>
>>>Modified:
>>>incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/model/solar/SolarObject.java
>>>
>>>URL:
>>>http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/model/solar/SolarObject.java?rev=380866&r1=380865&r2=380866&view=diff
>>>
>>>==============================================================================
>>>
>>>---
>>>incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/model/solar/SolarObject.java
>>>(original)
>>>+++
>>>incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/model/solar/SolarObject.java
>>>Fri Feb 24 15:37:31 2006
>>>@@ -176,7 +176,17 @@
>>> return array;
>>> }
>>>
>>>- public static List<SolarObject> getSatellites(String center) {
>>>+
>>>+ public static List<SolarObject> getList() {
>>>+ SolarObject[] array = getArray();
>>>+ List<SolarObject> list = new ArrayList<SolarObject>(array.length);
>>>+ for (SolarObject object : array) {
>>>+ list.add(object);
>>>+ }
>>>+ return list;
>>>+ }
>>>+
>>>+ public static List<SolarObject> getSatellites(String center) {
>>> List<SolarObject> collect = new ArrayList<SolarObject>();
>>> SolarObject[] all = getArray();
>>> for (int i = 0; i < all.length; i++) {
>>>
>>>Modified:
>>>incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/OverviewController.java
>>>
>>>URL:
>>>http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/OverviewController.java?rev=380866&r1=380865&r2=380866&view=diff
>>>
>>>==============================================================================
>>>
>>>---
>>>incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/OverviewController.java
>>>(original)
>>>+++
>>>incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/OverviewController.java
>>>Fri Feb 24 15:37:31 2006
>>>@@ -23,9 +23,12 @@
>>>
>>> import org.apache.commons.logging.Log;
>>> import org.apache.commons.logging.LogFactory;
>>>+import org.apache.myfaces.tobago.component.Sorter;
>>>+import org.apache.myfaces.tobago.component.UIData;
>>> import org.apache.myfaces.tobago.context.ResourceManager;
>>> import org.apache.myfaces.tobago.context.ResourceManagerFactory;
>>>
>>>+import javax.faces.component.UICommand;
>>> import javax.faces.context.FacesContext;
>>> import javax.faces.event.ActionEvent;
>>> import javax.faces.model.SelectItem;
>>>@@ -109,6 +112,19 @@
>>>
>>> public void click(ActionEvent actionEvent) {
>>> lastAction = actionEvent.getComponent().getId();
>>>+ }
>>>+
>>>+ + public void sheetSorter(ActionEvent event) {
>>>+ Object eventSource = event.getSource();
>>>+ UIData data = (UIData) ((UICommand)
>>>eventSource).getParent().getParent();
>>>+ List list = (List) data.getValue();
>>>+ Object sun = list.remove(0);
>>>+ Object[] objects = new Object[1];
>>>+ objects[0] = event;
>>>+ Sorter sorter = new Sorter();
>>>+ sorter.invoke(FacesContext.getCurrentInstance(), objects);
>>>+ list.add(0, sun);
>>> }
>>>
>>> public boolean getShowPopup() {
>>>
>>>Modified:
>>>incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/SheetConfig.java
>>>
>>>URL:
>>>http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/SheetConfig.java?rev=380866&r1=380865&r2=380866&view=diff
>>>
>>>==============================================================================
>>>
>>>---
>>>incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/SheetConfig.java
>>>(original)
>>>+++
>>>incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/SheetConfig.java
>>>Fri Feb 24 15:37:31 2006
>>>@@ -47,7 +47,7 @@
>>> private boolean sheetConfigPopup;
>>>
>>> public SheetConfig() {
>>>- sheetPagingStart = 1;
>>>+ sheetPagingStart = 0;
>>> sheetPagingLength = 7;
>>> sheetDirectLinkCount = 5;
>>> sheetDirectLinkCountItems = createSheetDirectLinkCountItems();
>>>
>>>Modified:
>>>incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/overview/sheetControl.jsp
>>>
>>>URL:
>>>http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/overview/sheetControl.jsp?rev=380866&r1=380865&r2=380866&view=diff
>>>
>>>==============================================================================
>>>
>>>---
>>>incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/overview/sheetControl.jsp
>>>(original)
>>>+++
>>>incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/overview/sheetControl.jsp
>>>Fri Feb 24 15:37:31 2006
>>>@@ -106,7 +106,7 @@
>>> </tc:toolBar>
>>> </f:facet>
>>>
>>>- <tc:sheet value="#{demo.solarArray}" id="sheet"
>>>+ <tc:sheet value="#{demo.solarList}" id="sheet"
>>> columns="3*;1*;3*;3*;3*;3*" var="luminary"
>>> state="#{demo.sheetState}"
>>>
>>>showHeader="#{overviewController.sheetConfig.sheetShowHeader}"
>>>@@ -116,7 +116,8 @@
>>>
>>>pagingStart="#{overviewController.sheetConfig.sheetPagingStart}"
>>>
>>>pagingLength="#{overviewController.sheetConfig.sheetPagingLength}"
>>>
>>>directLinkCount="#{overviewController.sheetConfig.sheetDirectLinkCount}"
>>>- stateChangeListener="#{demo.stateChangeListener}">
>>>+ stateChangeListener="#{demo.stateChangeListener}"
>>>+ sortActionListener="#{overviewController.sheetSorter}">
>>> <tc:column label="#{overviewBundle.solarArrayName}"
>>>id="name" sortable="true">
>>> <tc:out value="#{luminary.name}" id="t_name" />
>>> </tc:column>
>>>
>>>Modified:
>>>incubator/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SheetRenderer.java
>>>
>>>URL:
>>>http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SheetRenderer.java?rev=380866&r1=380865&r2=380866&view=diff
>>>
>>>==============================================================================
>>>
>>>---
>>>incubator/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SheetRenderer.java
>>>(original)
>>>+++
>>>incubator/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SheetRenderer.java
>>>Fri Feb 24 15:37:31 2006
>>>@@ -23,44 +23,11 @@
>>>
>>> import org.apache.commons.logging.Log;
>>> import org.apache.commons.logging.LogFactory;
>>>-import static
>>>org.apache.myfaces.tobago.TobagoConstants.ATTR_ACTION_STRING;
>>>-import static org.apache.myfaces.tobago.TobagoConstants.ATTR_ALIGN;
>>>-import static
>>>org.apache.myfaces.tobago.TobagoConstants.ATTR_COMMAND_TYPE;
>>>-import static
>>>org.apache.myfaces.tobago.TobagoConstants.ATTR_DIRECT_LINK_COUNT;
>>>-import static org.apache.myfaces.tobago.TobagoConstants.ATTR_DISABLED;
>>>-import static
>>>org.apache.myfaces.tobago.TobagoConstants.ATTR_FOOTER_HEIGHT;
>>>-import static
>>>org.apache.myfaces.tobago.TobagoConstants.ATTR_FORCE_VERTICAL_SCROLLBAR;
>>>-import static org.apache.myfaces.tobago.TobagoConstants.ATTR_IMAGE;
>>>-import static org.apache.myfaces.tobago.TobagoConstants.ATTR_INLINE;
>>>-import static org.apache.myfaces.tobago.TobagoConstants.ATTR_LABEL;
>>>-import static
>>>org.apache.myfaces.tobago.TobagoConstants.ATTR_LAYOUT_HEIGHT;
>>>-import static org.apache.myfaces.tobago.TobagoConstants.ATTR_MENU_POPUP;
>>>-import static
>>>org.apache.myfaces.tobago.TobagoConstants.ATTR_MENU_POPUP_TYPE;
>>>-import static
>>>org.apache.myfaces.tobago.TobagoConstants.ATTR_SELECTED_LIST_STRING;
>>>-import static
>>>org.apache.myfaces.tobago.TobagoConstants.ATTR_SHOW_DIRECT_LINKS;
>>>-import static
>>>org.apache.myfaces.tobago.TobagoConstants.ATTR_SHOW_PAGE_RANGE;
>>>-import static
>>>org.apache.myfaces.tobago.TobagoConstants.ATTR_SHOW_ROW_RANGE;
>>>-import static org.apache.myfaces.tobago.TobagoConstants.ATTR_SORTABLE;
>>>-import static org.apache.myfaces.tobago.TobagoConstants.ATTR_STYLE;
>>>-import static org.apache.myfaces.tobago.TobagoConstants.ATTR_STYLE_BODY;
>>>-import static
>>>org.apache.myfaces.tobago.TobagoConstants.ATTR_STYLE_CLASS;
>>>-import static
>>>org.apache.myfaces.tobago.TobagoConstants.ATTR_STYLE_HEADER;
>>>-import static org.apache.myfaces.tobago.TobagoConstants.ATTR_TYPE;
>>>-import static org.apache.myfaces.tobago.TobagoConstants.ATTR_WIDTH_LIST;
>>>-import static
>>>org.apache.myfaces.tobago.TobagoConstants.ATTR_WIDTH_LIST_STRING;
>>>-import static
>>>org.apache.myfaces.tobago.TobagoConstants.COMMAND_TYPE_SCRIPT;
>>>-import static org.apache.myfaces.tobago.TobagoConstants.FACET_MENUPOPUP;
>>>-import static
>>>org.apache.myfaces.tobago.TobagoConstants.FACET_PAGER_PAGE;
>>>-import static org.apache.myfaces.tobago.TobagoConstants.FACET_PAGER_ROW;
>>>-import static
>>>org.apache.myfaces.tobago.TobagoConstants.RENDERER_TYPE_LINK;
>>>-import static
>>>org.apache.myfaces.tobago.TobagoConstants.RENDERER_TYPE_MENUBAR;
>>>-import static
>>>org.apache.myfaces.tobago.TobagoConstants.RENDERER_TYPE_MENUCOMMAND;
>>>-import static
>>>org.apache.myfaces.tobago.TobagoConstants.SUBCOMPONENT_SEP;
>>>+import static org.apache.myfaces.tobago.TobagoConstants.*;
>>> import org.apache.myfaces.tobago.ajax.api.AjaxRenderer;
>>> import org.apache.myfaces.tobago.ajax.api.AjaxUtils;
>>> import org.apache.myfaces.tobago.component.ComponentUtil;
>>> import org.apache.myfaces.tobago.component.Pager;
>>>-import org.apache.myfaces.tobago.component.Sorter;
>>> import org.apache.myfaces.tobago.component.UIColumnSelector;
>>> import org.apache.myfaces.tobago.component.UIData;
>>> import org.apache.myfaces.tobago.config.TobagoConfig;
>>>@@ -77,22 +44,13 @@
>>> import org.apache.myfaces.tobago.webapp.TobagoResponseWriter;
>>>
>>> import javax.faces.application.Application;
>>>-import javax.faces.component.UIColumn;
>>>-import javax.faces.component.UICommand;
>>>-import javax.faces.component.UIComponent;
>>>-import javax.faces.component.UIPanel;
>>>-import javax.faces.component.UIViewRoot;
>>>+import javax.faces.component.*;
>>> import javax.faces.context.FacesContext;
>>> import javax.faces.context.ResponseWriter;
>>> import javax.faces.el.MethodBinding;
>>> import java.io.IOException;
>>> import java.text.MessageFormat;
>>>-import java.util.ArrayList;
>>>-import java.util.Collections;
>>>-import java.util.Iterator;
>>>-import java.util.List;
>>>-import java.util.Locale;
>>>-import java.util.Map;
>>>+import java.util.*;
>>>
>>> public class SheetRenderer extends RendererBase
>>> implements SheetRendererWorkaround, AjaxRenderer {
>>>@@ -774,7 +732,7 @@
>>> String image1x1, int sortMarkerWidth) throws IOException {
>>> String sheetId = component.getClientId(facesContext);
>>> Application application = facesContext.getApplication();
>>>- Sorter sorter = component.getSorter();
>>>+ MethodBinding sorter = component.getSortActionListener();
>>>
>>> List columnWidths
>>> = (List) component.getAttributes().get(ATTR_WIDTH_LIST);
>>>@@ -797,18 +755,23 @@
>>> ComponentUtil.getBooleanAttribute(column,
>>> ATTR_SORTABLE);
>>> if (sortable && !(column instanceof UIColumnSelector)) {
>>>- String sorterId = Sorter.ID_PREFIX + columnCount;
>>>+ UICommand sortCommand = (UICommand)
>>>column.getFacet(UIData.FACET_SORTER);
>>>+ if (sortCommand == null) {
>>>+ String columnId = column.getClientId(facesContext);
>>>+ String sorterId =
>>>columnId.substring(columnId.lastIndexOf(":") + 1 )
>>>+ + "_" + UIData.SORTER_ID;
>>>+ sortCommand
>>>+ = (UICommand)
>>>application.createComponent(UICommand.COMPONENT_TYPE);
>>>+ sortCommand.setRendererType(RENDERER_TYPE_LINK);
>>>+ sortCommand.setActionListener(sorter);
>>>+ sortCommand.setId(sorterId);
>>>+ column.getFacets().put(UIData.FACET_SORTER,
>>>sortCommand); + }
>>>+
>>> String onclick = "submitAction('"
>>> + ComponentUtil.findPage(component).getFormId(facesContext)
>>>- + "','" + component.getClientId(facesContext) + ":" +
>>>sorterId + "')";
>>>+ + "','" + sortCommand.getClientId(facesContext) + "')";
>>> writer.writeAttribute("onclick", onclick, null);
>>>- UICommand sortCommand = (UICommand)
>>>- application.createComponent(UICommand.COMPONENT_TYPE);
>>>- sortCommand.setRendererType(RENDERER_TYPE_LINK);
>>>- sortCommand.setActionListener(sorter);
>>>- sortCommand.setId(sorterId);
>>>- component.getFacets().put(sorterId, sortCommand);
>>>- sortCommand.getClientId(facesContext); // this must called here
>>>to fix the ClientId
>>>
>>> writer.writeAttribute("title",
>>> ResourceManagerUtil.getPropertyNotNull(facesContext, "tobago",
>>>
>>>Modified:
>>>incubator/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-sheet.js
>>>
>>>URL:
>>>http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-sheet.js?rev=380866&r1=380865&r2=380866&view=diff
>>>
>>>==============================================================================
>>>
>>>---
>>>incubator/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-sheet.js
>>>(original)
>>>+++
>>>incubator/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-sheet.js
>>>Fri Feb 24 15:37:31 2006
>>>@@ -34,6 +34,9 @@
>>> LOG.debug("New Sheet with id " + this.sheetId);
>>> },
>>>
>>>+ sortOnclickRegExp :
>>>+ new RegExp("submitAction\\(('|\")(.*?)('|\") *,
>>>*('|\")(.*?)('|\")\\)"),
>>>+
>>> setup: function() {
>>>
>>> // setup sorting headers
>>>@@ -42,7 +45,18 @@
>>> var headerBox = $(idPrefix + i++);
>>> while (headerBox) {
>>> if (headerBox.onclick) {
>>>+ var match =
>>>this.sortOnclickRegExp.exec(headerBox.onclick.valueOf());
>>>+// LOG.debug("match[0] = " + match[0]);
>>>+// LOG.debug("match[1] = " + match[1]);
>>>+// LOG.debug("*match[2] = " + match[2]);
>>>+// LOG.debug("match[3] = " + match[3]);
>>>+// LOG.debug("match[4] = " + match[4]);
>>>+// LOG.debug("*match[5] = " + match[5]);
>>>+// LOG.debug("match[6] = " + match[6]);
>>>+// headerBox.formId = match[2];
>>>+ headerBox.sorterId = match[5];
>>> headerBox.onclick = null;
>>>+// LOG.debug("headerBox.id = " + headerBox.id);
>>> Event.observe(headerBox, "click",
>>>this.doSort.bindAsEventListener(this));
>>> }
>>> headerBox = $(idPrefix + i++);
>>>@@ -97,10 +111,12 @@
>>>
>>> doSort: function(event) {
>>> var element = Event.element(event);
>>>- var idx = element.id.lastIndexOf('_');
>>>- idx = element.id.substring(idx + 1);
>>>- var action = this.sheetId + Tobago.componentSeparator + "sorter_"
>>>+ idx;
>>>- this.reloadWithAction(action);
>>>+ if (!element.sorterId) {
>>>+ element = element.parentNode;
>>>+ }
>>>+// LOG.debug("element.id = " + element.id);
>>>+// LOG.debug("sorterId = " + element.sorterId);
>>>+ this.reloadWithAction(element.sorterId);
>>> },
>>>
>>> doPagingDirect: function(event) {
>>>
>>>
>>>
>>
>
--
Dipl.-Ing. Bernd Bohmann - Atanion GmbH - Software Development
Bismarckstr. 13, 26122 Oldenburg, http://www.atanion.com
phone: +49 441 4082312, mobile: +49 173 8839471, fax: +49 441 4082333
Re: svn commit: r380866 - in /incubator/tobago/trunk: tobago-core/src/main/java/org/apache/myfaces/tobago/component/
tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/component/ tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/t...
Posted by Volker Weber <us...@weber-oldenburg.de>.
Hi Bernd,
the sheet was already using a actionListener methodBinding to do the
sort. The (mainly) only thing i did was to enable defining the
methodBinding to use in the sheetTag.
Hmmm, when i started to write this mail, i thought it where mutch more
complicated to change this to queue a SortActionEvent instead of an
standard ActionEvent, because the event is generated in the
CommandRendererBase, but i just got an idea how to catch and replace
this ActionEvent with a SortActionEvent.
This could be done in the queueEvent() method of UIData.
Thoughts?
Regards,
Volker
Bernd Bohmann wrote:
> Hi Volker,
>
> I would prefer an actionListener and a SortActionEvent instead of a
> sortActionListener.
>
> I don't like the x XYZActionListener.
>
> Can you change it?
>
> Regards
>
> Bernd
>
> weber@apache.org schrieb:
>
>> Author: weber
>> Date: Fri Feb 24 15:37:31 2006
>> New Revision: 380866
>>
>> URL: http://svn.apache.org/viewcvs?rev=380866&view=rev
>> Log:
>> add sortActionListener attribute to sheet
>>
>> Modified:
>>
>> incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/ComponentUtil.java
>>
>>
>> incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/Sorter.java
>>
>>
>> incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/UIData.java
>>
>>
>> incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/component/SheetTag.java
>>
>>
>> incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/TobagoDemoController.java
>>
>>
>> incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/model/solar/SolarObject.java
>>
>>
>> incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/OverviewController.java
>>
>>
>> incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/SheetConfig.java
>>
>>
>> incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/overview/sheetControl.jsp
>>
>>
>> incubator/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SheetRenderer.java
>>
>>
>> incubator/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-sheet.js
>>
>>
>> Modified:
>> incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/ComponentUtil.java
>>
>> URL:
>> http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/ComponentUtil.java?rev=380866&r1=380865&r2=380866&view=diff
>>
>> ==============================================================================
>>
>> ---
>> incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/ComponentUtil.java
>> (original)
>> +++
>> incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/ComponentUtil.java
>> Fri Feb 24 15:37:31 2006
>> @@ -23,30 +23,7 @@
>>
>> import org.apache.commons.logging.Log;
>> import org.apache.commons.logging.LogFactory;
>> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_ACCESS_KEY;
>> -import static
>> org.apache.myfaces.tobago.TobagoConstants.ATTR_ACTION_STRING;
>> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_ALIGN;
>> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_DISABLED;
>> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_FOR;
>> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_HOVER;
>> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_LABEL;
>> -import static
>> org.apache.myfaces.tobago.TobagoConstants.ATTR_LABEL_WITH_ACCESS_KEY;
>> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_READONLY;
>> -import static
>> org.apache.myfaces.tobago.TobagoConstants.ATTR_RENDER_RANGE;
>> -import static
>> org.apache.myfaces.tobago.TobagoConstants.ATTR_RENDER_RANGE_EXTERN;
>> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_SORTABLE;
>> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_VALUE;
>> -import static
>> org.apache.myfaces.tobago.TobagoConstants.COMMAND_TYPE_NAVIGATE;
>> -import static
>> org.apache.myfaces.tobago.TobagoConstants.COMMAND_TYPE_RESET;
>> -import static
>> org.apache.myfaces.tobago.TobagoConstants.COMMAND_TYPE_SCRIPT;
>> -import static org.apache.myfaces.tobago.TobagoConstants.FACET_CHECKBOX;
>> -import static org.apache.myfaces.tobago.TobagoConstants.FACET_LABEL;
>> -import static org.apache.myfaces.tobago.TobagoConstants.FACET_RADIO;
>> -import static
>> org.apache.myfaces.tobago.TobagoConstants.RENDERER_TYPE_OUT;
>> -import static
>> org.apache.myfaces.tobago.TobagoConstants.RENDERER_TYPE_SELECT_BOOLEAN_CHECKBOX;
>>
>> -import static
>> org.apache.myfaces.tobago.TobagoConstants.RENDERER_TYPE_SELECT_ONE_RADIO;
>> -import static
>> org.apache.myfaces.tobago.TobagoConstants.ATTR_CREATE_SPAN;
>> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_ESCAPE;
>> +import static org.apache.myfaces.tobago.TobagoConstants.*;
>> import org.apache.myfaces.tobago.el.ConstantMethodBinding;
>> import org.apache.myfaces.tobago.event.SheetStateChangeEvent;
>> import org.apache.myfaces.tobago.renderkit.RendererBase;
>> @@ -55,33 +32,22 @@
>>
>> import javax.faces.FactoryFinder;
>> import javax.faces.application.Application;
>> -import javax.faces.component.ActionSource;
>> -import javax.faces.component.EditableValueHolder;
>> -import javax.faces.component.UIColumn;
>> +import javax.faces.component.*;
>> import javax.faces.component.UICommand;
>> -import javax.faces.component.UIComponent;
>> -import javax.faces.component.UIGraphic;
>> import javax.faces.component.UIOutput;
>> -import javax.faces.component.UIParameter;
>> -import javax.faces.component.UISelectBoolean;
>> import javax.faces.component.UISelectItem;
>> -import javax.faces.component.UISelectItems;
>> -import javax.faces.component.ValueHolder;
>> import javax.faces.context.FacesContext;
>> import javax.faces.convert.Converter;
>> import javax.faces.el.MethodBinding;
>> import javax.faces.el.ValueBinding;
>> +import javax.faces.event.ActionEvent;
>> import javax.faces.event.ActionListener;
>> import javax.faces.model.SelectItem;
>> import javax.faces.render.RenderKit;
>> import javax.faces.render.RenderKitFactory;
>> import javax.faces.webapp.UIComponentTag;
>> import javax.servlet.jsp.JspException;
>> -import java.util.ArrayList;
>> -import java.util.Collection;
>> -import java.util.Iterator;
>> -import java.util.List;
>> -import java.util.Map;
>> +import java.util.*;
>>
>> public class ComponentUtil {
>>
>> @@ -90,6 +56,9 @@
>> private static final String RENDER_KEY_PREFIX
>> =
>> "org.apache.myfaces.tobago.component.ComponentUtil.RendererKeyPrefix_";
>>
>> + private static final Class[] ACTION_LISTENER_ARGS =
>> {ActionEvent.class};
>> +
>> +
>> private ComponentUtil() {
>> }
>>
>> @@ -917,13 +886,27 @@
>> final Application application = facesContext.getApplication();
>> if (actionListener != null) {
>> if (UIComponentTag.isValueReference(actionListener)) {
>> - Class[] arguments = {javax.faces.event.ActionEvent.class};
>> MethodBinding binding
>> - = application.createMethodBinding(actionListener,
>> arguments);
>> + = application.createMethodBinding(actionListener,
>> ACTION_LISTENER_ARGS);
>> command.setActionListener(binding);
>> } else {
>> throw new IllegalArgumentException(
>> "Must be a valueReference (actionListener): " +
>> actionListener);
>> + }
>> + }
>> + }
>> +
>> + public static void setSortActionListener(UIData data, String
>> actionListener) {
>> + final FacesContext facesContext = FacesContext.getCurrentInstance();
>> + final Application application = facesContext.getApplication();
>> + if (actionListener != null) {
>> + if (UIComponentTag.isValueReference(actionListener)) {
>> + MethodBinding binding
>> + = application.createMethodBinding(actionListener,
>> ACTION_LISTENER_ARGS);
>> + data.setSortActionListener(binding);
>> + } else {
>> + throw new IllegalArgumentException(
>> + "Must be a valueReference (sortActionListener): " +
>> actionListener);
>> }
>> }
>> }
>>
>> Modified:
>> incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/Sorter.java
>>
>> URL:
>> http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/Sorter.java?rev=380866&r1=380865&r2=380866&view=diff
>>
>> ==============================================================================
>>
>> ---
>> incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/Sorter.java
>> (original)
>> +++
>> incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/Sorter.java
>> Fri Feb 24 15:37:31 2006
>> @@ -21,15 +21,12 @@
>> import org.apache.myfaces.tobago.TobagoConstants;
>> import static org.apache.myfaces.tobago.TobagoConstants.ATTR_SORTABLE;
>> import org.apache.myfaces.tobago.model.SheetState;
>> -import org.apache.myfaces.tobago.model.SortableByApplication;
>> import org.apache.myfaces.tobago.util.BeanComparator;
>> import org.apache.myfaces.tobago.util.ValueBindingComparator;
>>
>> -import javax.faces.component.UIColumn;
>> -import javax.faces.component.UIComponent;
>> +import javax.faces.component.*;
>> import javax.faces.component.UIInput;
>> import javax.faces.component.UIOutput;
>> -import javax.faces.component.UISelectBoolean;
>> import javax.faces.context.FacesContext;
>> import javax.faces.el.EvaluationException;
>> import javax.faces.el.MethodBinding;
>> @@ -37,11 +34,7 @@
>> import javax.faces.el.ValueBinding;
>> import javax.faces.event.ActionEvent;
>> import javax.faces.model.DataModel;
>> -import java.util.Arrays;
>> -import java.util.Collections;
>> -import java.util.Comparator;
>> -import java.util.Iterator;
>> -import java.util.List;
>> +import java.util.*;
>>
>> /**
>> * User: weber
>> @@ -52,8 +45,6 @@
>>
>> private static final Log LOG = LogFactory.getLog(Sorter.class);
>>
>> - public static final String ID_PREFIX = "sorter_";
>> -
>>
>> public Object invoke(FacesContext facesContext, Object[] aobj)
>> throws EvaluationException {
>> @@ -63,87 +54,66 @@
>> if (LOG.isDebugEnabled()) {
>> LOG.debug("sorterId = " + command.getId());
>> }
>> - UIData data = (UIData) command.getParent();
>> + UIColumn column = (UIColumn) command.getParent();
>> + UIData data = (UIData) column.getParent();
>> +
>> Object value = data.getValue();
>> if (value instanceof DataModel) {
>> value = ((DataModel) value).getWrappedData();
>> }
>> SheetState sheetState = data.getSheetState(facesContext);
>> - int column = sheetState.getSortedColumn();
>> - boolean ascending = sheetState.isAscending();
>>
>> Comparator comparator = null;
>>
>> - if (value instanceof SortableByApplication
>> - || value instanceof List
>> - || value instanceof Object[]) {
>> + if (value instanceof List || value instanceof Object[]) {
>> String sortProperty;
>>
>> - if (command.getId() != null &&
>> command.getId().startsWith(ID_PREFIX)) {
>> - UIColumn uiColumn = null;
>> - try {
>> - int actualColumn =
>> - Integer.parseInt(
>> - command.getId().substring(ID_PREFIX.length()));
>> - if (actualColumn == column) {
>> - ascending = !ascending;
>> - } else {
>> - ascending = true;
>> - column = actualColumn;
>> - }
>> - sheetState.setAscending(ascending);
>> - sheetState.setSortedColumn(column);
>> + try {
>> + if (!updateSheetState(data, column, sheetState)) {
>> + return null;
>> + }
>>
>> - uiColumn = data.getRendererdColumns().get(column);
>> - UIComponent child =
>> getFirstSortableChild(uiColumn.getChildren());
>> - if (child != null) {
>> - ValueBinding valueBinding =
>> child.getValueBinding("value");
>> - String var = data.getVar();
>> -
>> - if (valueBinding != null) {
>> - if
>> (isSimpleProperty(valueBinding.getExpressionString())) {
>> - String expressionString =
>> valueBinding.getExpressionString();
>> - if (expressionString.startsWith("#{")
>> - && expressionString.endsWith("}")) {
>> - expressionString =
>> - expressionString.substring(2,
>> - expressionString.length() - 1);
>> - }
>> - sortProperty =
>> expressionString.substring(var.length() + 1);
>> -
>> - comparator = new BeanComparator(sortProperty, null,
>> !ascending);
>> -
>> - if (LOG.isDebugEnabled()) {
>> - LOG.debug("Sort property is " + sortProperty);
>> - }
>> - } else {
>> - comparator = new
>> ValueBindingComparator(facesContext, var, valueBinding, !ascending);
>> + UIComponent child =
>> getFirstSortableChild(column.getChildren());
>> + if (child != null) {
>> + ValueBinding valueBinding = child.getValueBinding("value");
>> + String var = data.getVar();
>> +
>> + if (valueBinding != null) {
>> + if
>> (isSimpleProperty(valueBinding.getExpressionString())) {
>> + String expressionString =
>> valueBinding.getExpressionString();
>> + if (expressionString.startsWith("#{")
>> + && expressionString.endsWith("}")) {
>> + expressionString =
>> + expressionString.substring(2,
>> + expressionString.length() - 1);
>> }
>> - }
>> + sortProperty =
>> expressionString.substring(var.length() + 1);
>>
>> - } else {
>> - LOG.error("No sortable component found!");
>> - removeSortableAttribute(uiColumn);
>> - return null;
>> - }
>> - } catch (Exception e) {
>> - LOG.error("Error while extracting sortMethod :" +
>> e.getMessage(), e);
>> - if (uiColumn != null) {
>> - removeSortableAttribute(uiColumn);
>> + comparator = new BeanComparator(
>> + sortProperty, null, !sheetState.isAscending());
>> +
>> + if (LOG.isDebugEnabled()) {
>> + LOG.debug("Sort property is " + sortProperty);
>> + }
>> + } else {
>> + comparator = new ValueBindingComparator(
>> + facesContext, var, valueBinding,
>> !sheetState.isAscending());
>> + }
>> }
>> +
>> + } else {
>> + LOG.error("No sortable component found!");
>> + removeSortableAttribute(column);
>> return null;
>> }
>> - } else {
>> - LOG.error(
>> - "Sorter.invoke() with illegal id in ActionEvent's
>> source");
>> + } catch (Exception e) {
>> + LOG.error("Error while extracting sortMethod :" +
>> e.getMessage(), e);
>> + if (column != null) {
>> + removeSortableAttribute(column);
>> + }
>> return null;
>> }
>>
>> - //if (value instanceof SortableByApplication) {
>> - //((SortableByApplication) value).sortBy(sortProperty);
>> -
>> - // TODO ???? sortable by application
>> - if (!(value instanceof SortableByApplication)) {
>> // TODO: locale / comparator parameter?
>> // don't compare numbers with Collator.getInstance()
>> comparator
>> // Comparator comparator = Collator.getInstance();
>> @@ -151,16 +121,43 @@
>>
>> if (value instanceof List) {
>> Collections.sort((List) value, comparator);
>> - } else { // if (value instanceof Object[]) {
>> + } else { // value is instanceof Object[]
>> Arrays.sort((Object[]) value, comparator);
>> }
>> - }
>> +
>> } else { // DataModel?, ResultSet, Result or Object
>> LOG.warn("Sorting not supported for type "
>> + (value != null ? value.getClass().toString() :
>> "null"));
>> }
>> }
>> return null;
>> + }
>> +
>> + private boolean updateSheetState(UIData data, UIColumn uiColumn,
>> SheetState sheetState) {
>> + int actualColumn = -1;
>> + List<UIColumn> rendererdColumns = data.getRendererdColumns();
>> + for (int i = 0; i < rendererdColumns.size(); i++) {
>> + if (uiColumn == rendererdColumns.get(i)) {
>> + actualColumn = i;
>> + break;
>> + }
>> + }
>> + if (actualColumn == -1) {
>> + LOG.warn("Can't find column to sort in rendered columns of
>> sheet!");
>> + return false;
>> + }
>> +
>> + int column = sheetState.getSortedColumn();
>> + boolean ascending = sheetState.isAscending();
>> + if (actualColumn == column) {
>> + ascending = !ascending;
>> + } else {
>> + ascending = true;
>> + column = actualColumn;
>> + }
>> + sheetState.setAscending(ascending);
>> + sheetState.setSortedColumn(column);
>> + return true;
>> }
>>
>> private boolean isSimpleProperty(String expressionString) {
>>
>> Modified:
>> incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/UIData.java
>>
>> URL:
>> http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/UIData.java?rev=380866&r1=380865&r2=380866&view=diff
>>
>> ==============================================================================
>>
>> ---
>> incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/UIData.java
>> (original)
>> +++
>> incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/UIData.java
>> Fri Feb 24 15:37:31 2006
>> @@ -53,12 +53,14 @@
>>
>> public static final String COMPONENT_TYPE =
>> "org.apache.myfaces.tobago.Data";
>>
>> + public static final String FACET_SORTER = "sorter";
>> + public static final String SORTER_ID = "sorter";
>> +
>> private MethodBinding stateChangeListener;
>>
>> private List<Integer> widthList;
>>
>> - // TODO: should be removed?
>> - private Sorter sorter;
>> + private MethodBinding sortActionListener;
>>
>> private SheetState sheetState;
>>
>> @@ -320,10 +322,10 @@
>> private void updateSheetState(FacesContext facesContext) {
>> SheetState state = getSheetState(facesContext);
>> if (state != null) {
>> - // ensure sorter
>> -// getSorter();
>> -// state.setSortedColumn(sorter != null ? sorter.getColumn() : -1);
>> -// state.setAscending(sorter != null && sorter.isAscending());
>> + // ensure sortActionListener
>> +// getSortActionListener();
>> +// state.setSortedColumn(sortActionListener != null ?
>> sortActionListener.getColumn() : -1);
>> +// state.setAscending(sortActionListener != null &&
>> sortActionListener.isAscending());
>> state.setSelectedRows((List<Integer>)
>> getAttributes().get(ATTR_SELECTED_LIST_STRING));
>> state.setColumnWidths((String)
>> @@ -335,7 +337,7 @@
>> Object[] saveState = new Object[5];
>> saveState[0] = super.saveState(context);
>> saveState[1] = sheetState;
>> - saveState[2] = sorter;
>> + saveState[2] = saveAttachedState(context, sortActionListener);
>> saveState[3] = saveAttachedState(context, stateChangeListener);
>> if (showHeaderSet) {
>> saveState[4] = showHeader;
>> @@ -347,7 +349,7 @@
>> Object[] values = (Object[]) savedState;
>> super.restoreState(context, values[0]);
>> sheetState = (SheetState) values[1];
>> - sorter = (Sorter) values[2];
>> + sortActionListener = (MethodBinding)
>> restoreAttachedState(context, values[2]);
>> stateChangeListener = (MethodBinding)
>> restoreAttachedState(context, values[3]);
>> if (values[4] != null) {
>> showHeaderSet = true;
>> @@ -376,17 +378,16 @@
>> return columns;
>> }
>>
>> - // TODO: should be removed?
>> - public Sorter getSorter() {
>> - if (sorter != null) {
>> - return sorter;
>> + public MethodBinding getSortActionListener() {
>> + if (sortActionListener != null) {
>> + return sortActionListener;
>> } else {
>> return new Sorter();
>> }
>> }
>>
>> - public void setSorter(Sorter sorter) {
>> - this.sorter = sorter;
>> + public void setSortActionListener(MethodBinding sortActionListener) {
>> + this.sortActionListener = sortActionListener;
>> }
>>
>> public void queueEvent(FacesEvent facesEvent) {
>>
>> Modified:
>> incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/component/SheetTag.java
>>
>> URL:
>> http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/component/SheetTag.java?rev=380866&r1=380865&r2=380866&view=diff
>>
>> ==============================================================================
>>
>> ---
>> incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/component/SheetTag.java
>> (original)
>> +++
>> incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/component/SheetTag.java
>> Fri Feb 24 15:37:31 2006
>> @@ -16,19 +16,7 @@
>> * limitations under the License.
>> */
>>
>> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_COLUMNS;
>> -import static
>> org.apache.myfaces.tobago.TobagoConstants.ATTR_DIRECT_LINK_COUNT;
>> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_FIRST;
>> -import static
>> org.apache.myfaces.tobago.TobagoConstants.ATTR_FORCE_VERTICAL_SCROLLBAR;
>> -import static
>> org.apache.myfaces.tobago.TobagoConstants.ATTR_INNER_WIDTH;
>> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_ROWS;
>> -import static
>> org.apache.myfaces.tobago.TobagoConstants.ATTR_SHOW_DIRECT_LINKS;
>> -import static
>> org.apache.myfaces.tobago.TobagoConstants.ATTR_SHOW_HEADER;
>> -import static
>> org.apache.myfaces.tobago.TobagoConstants.ATTR_SHOW_PAGE_RANGE;
>> -import static
>> org.apache.myfaces.tobago.TobagoConstants.ATTR_SHOW_ROW_RANGE;
>> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_STATE;
>> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_VALUE;
>> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_VAR;
>> +import static org.apache.myfaces.tobago.TobagoConstants.*;
>> import org.apache.myfaces.tobago.apt.annotation.BodyContentDescription;
>> import org.apache.myfaces.tobago.apt.annotation.Tag;
>> import org.apache.myfaces.tobago.apt.annotation.TagAttribute;
>> @@ -59,6 +47,7 @@
>> private String forceVerticalScrollbar;
>> private String state;
>> private String stateChangeListener;
>> + private String sortActionListener;
>>
>> public String getComponentType() {
>> // TODO: implement uidata with overridden processUpdates to store
>> state
>> @@ -80,6 +69,7 @@
>> forceVerticalScrollbar = null;
>> state = null;
>> stateChangeListener = null;
>> + sortActionListener = null;
>> }
>>
>> protected void setProperties(UIComponent component) {
>> @@ -101,6 +91,7 @@
>> data.getAttributes().put(ATTR_INNER_WIDTH, new Integer(-1));
>> ComponentUtil.setValueBinding(component, ATTR_STATE, state);
>> ComponentUtil.setStateChangeListener(data, stateChangeListener);
>> + ComponentUtil.setSortActionListener(data, sortActionListener);
>>
>> }
>>
>> @@ -280,5 +271,24 @@
>> public void setStateChangeListener(String stateChangeListener) {
>> this.stateChangeListener = stateChangeListener;
>> }
>> +
>> + /**
>> + * MethodBinding representing an actionListener method that will be
>> + * invoked when sorting was requested by the user.
>> + * Use this if your application needs special handling for sorting
>> columns.
>> + * If this is not set and the sortable attribute column is not
>> false the sheet
>> + * implementation will use a default sort method.
>> + * The expression must evaluate to a public method that takes an
>> + * ActionEvent parameter, with a return type of void.
>> + * The parent of the actionEvents source will be the UIColumn
>> object for that
>> + * the sorting is requested,
>> + * <code>UIColumn column =
>> (UIColumn)actionEvent.getSource().getParent()</code>.
>> + */
>> + @TagAttribute
>> + @UIComponentTagAttribute()
>> + public void setSortActionListener(String sortActionListener) {
>> + this.sortActionListener = sortActionListener;
>> + }
>> +
>> }
>>
>>
>> Modified:
>> incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/TobagoDemoController.java
>>
>> URL:
>> http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/TobagoDemoController.java?rev=380866&r1=380865&r2=380866&view=diff
>>
>> ==============================================================================
>>
>> ---
>> incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/TobagoDemoController.java
>> (original)
>> +++
>> incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/TobagoDemoController.java
>> Fri Feb 24 15:37:31 2006
>> @@ -61,6 +61,8 @@
>>
>> private SolarObject[] solarArray;
>>
>> + private List<SolarObject> solarList;
>> +
>> private List<UIColumn> solarArrayColumns;
>>
>> private String solarArrayColumnLayout;
>> @@ -148,6 +150,7 @@
>> = "**strong text**\n\n__emphasis__\n\nnormaler
>> text\n\n__dieses "
>> + "ist emphasis__\n\n**und nochmal strong**\n\n**__ strong
>> und emphasis__**";
>> solarArray = SolarObject.getArray();
>> + solarList = SolarObject.getList();
>> solarArrayColumns = createSolarArrayColumns();
>> solarArrayColumnLayout = "3*; 3*; 3*";
>>
>> @@ -292,6 +295,14 @@
>>
>> public void setSolarArray(SolarObject[] solarArray) {
>> this.solarArray = solarArray;
>> + }
>> +
>> + public List<SolarObject> getSolarList() {
>> + return solarList;
>> + }
>> +
>> + public void setSolarList(List<SolarObject> solarList) {
>> + this.solarList = solarList;
>> }
>>
>> public List<UIColumn> getSolarArrayColumns() {
>>
>> Modified:
>> incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/model/solar/SolarObject.java
>>
>> URL:
>> http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/model/solar/SolarObject.java?rev=380866&r1=380865&r2=380866&view=diff
>>
>> ==============================================================================
>>
>> ---
>> incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/model/solar/SolarObject.java
>> (original)
>> +++
>> incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/model/solar/SolarObject.java
>> Fri Feb 24 15:37:31 2006
>> @@ -176,7 +176,17 @@
>> return array;
>> }
>>
>> - public static List<SolarObject> getSatellites(String center) {
>> +
>> + public static List<SolarObject> getList() {
>> + SolarObject[] array = getArray();
>> + List<SolarObject> list = new ArrayList<SolarObject>(array.length);
>> + for (SolarObject object : array) {
>> + list.add(object);
>> + }
>> + return list;
>> + }
>> +
>> + public static List<SolarObject> getSatellites(String center) {
>> List<SolarObject> collect = new ArrayList<SolarObject>();
>> SolarObject[] all = getArray();
>> for (int i = 0; i < all.length; i++) {
>>
>> Modified:
>> incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/OverviewController.java
>>
>> URL:
>> http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/OverviewController.java?rev=380866&r1=380865&r2=380866&view=diff
>>
>> ==============================================================================
>>
>> ---
>> incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/OverviewController.java
>> (original)
>> +++
>> incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/OverviewController.java
>> Fri Feb 24 15:37:31 2006
>> @@ -23,9 +23,12 @@
>>
>> import org.apache.commons.logging.Log;
>> import org.apache.commons.logging.LogFactory;
>> +import org.apache.myfaces.tobago.component.Sorter;
>> +import org.apache.myfaces.tobago.component.UIData;
>> import org.apache.myfaces.tobago.context.ResourceManager;
>> import org.apache.myfaces.tobago.context.ResourceManagerFactory;
>>
>> +import javax.faces.component.UICommand;
>> import javax.faces.context.FacesContext;
>> import javax.faces.event.ActionEvent;
>> import javax.faces.model.SelectItem;
>> @@ -109,6 +112,19 @@
>>
>> public void click(ActionEvent actionEvent) {
>> lastAction = actionEvent.getComponent().getId();
>> + }
>> +
>> + + public void sheetSorter(ActionEvent event) {
>> + Object eventSource = event.getSource();
>> + UIData data = (UIData) ((UICommand)
>> eventSource).getParent().getParent();
>> + List list = (List) data.getValue();
>> + Object sun = list.remove(0);
>> + Object[] objects = new Object[1];
>> + objects[0] = event;
>> + Sorter sorter = new Sorter();
>> + sorter.invoke(FacesContext.getCurrentInstance(), objects);
>> + list.add(0, sun);
>> }
>>
>> public boolean getShowPopup() {
>>
>> Modified:
>> incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/SheetConfig.java
>>
>> URL:
>> http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/SheetConfig.java?rev=380866&r1=380865&r2=380866&view=diff
>>
>> ==============================================================================
>>
>> ---
>> incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/SheetConfig.java
>> (original)
>> +++
>> incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/SheetConfig.java
>> Fri Feb 24 15:37:31 2006
>> @@ -47,7 +47,7 @@
>> private boolean sheetConfigPopup;
>>
>> public SheetConfig() {
>> - sheetPagingStart = 1;
>> + sheetPagingStart = 0;
>> sheetPagingLength = 7;
>> sheetDirectLinkCount = 5;
>> sheetDirectLinkCountItems = createSheetDirectLinkCountItems();
>>
>> Modified:
>> incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/overview/sheetControl.jsp
>>
>> URL:
>> http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/overview/sheetControl.jsp?rev=380866&r1=380865&r2=380866&view=diff
>>
>> ==============================================================================
>>
>> ---
>> incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/overview/sheetControl.jsp
>> (original)
>> +++
>> incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/overview/sheetControl.jsp
>> Fri Feb 24 15:37:31 2006
>> @@ -106,7 +106,7 @@
>> </tc:toolBar>
>> </f:facet>
>>
>> - <tc:sheet value="#{demo.solarArray}" id="sheet"
>> + <tc:sheet value="#{demo.solarList}" id="sheet"
>> columns="3*;1*;3*;3*;3*;3*" var="luminary"
>> state="#{demo.sheetState}"
>>
>> showHeader="#{overviewController.sheetConfig.sheetShowHeader}"
>> @@ -116,7 +116,8 @@
>>
>> pagingStart="#{overviewController.sheetConfig.sheetPagingStart}"
>>
>> pagingLength="#{overviewController.sheetConfig.sheetPagingLength}"
>>
>> directLinkCount="#{overviewController.sheetConfig.sheetDirectLinkCount}"
>> - stateChangeListener="#{demo.stateChangeListener}">
>> + stateChangeListener="#{demo.stateChangeListener}"
>> + sortActionListener="#{overviewController.sheetSorter}">
>> <tc:column label="#{overviewBundle.solarArrayName}"
>> id="name" sortable="true">
>> <tc:out value="#{luminary.name}" id="t_name" />
>> </tc:column>
>>
>> Modified:
>> incubator/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SheetRenderer.java
>>
>> URL:
>> http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SheetRenderer.java?rev=380866&r1=380865&r2=380866&view=diff
>>
>> ==============================================================================
>>
>> ---
>> incubator/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SheetRenderer.java
>> (original)
>> +++
>> incubator/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SheetRenderer.java
>> Fri Feb 24 15:37:31 2006
>> @@ -23,44 +23,11 @@
>>
>> import org.apache.commons.logging.Log;
>> import org.apache.commons.logging.LogFactory;
>> -import static
>> org.apache.myfaces.tobago.TobagoConstants.ATTR_ACTION_STRING;
>> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_ALIGN;
>> -import static
>> org.apache.myfaces.tobago.TobagoConstants.ATTR_COMMAND_TYPE;
>> -import static
>> org.apache.myfaces.tobago.TobagoConstants.ATTR_DIRECT_LINK_COUNT;
>> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_DISABLED;
>> -import static
>> org.apache.myfaces.tobago.TobagoConstants.ATTR_FOOTER_HEIGHT;
>> -import static
>> org.apache.myfaces.tobago.TobagoConstants.ATTR_FORCE_VERTICAL_SCROLLBAR;
>> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_IMAGE;
>> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_INLINE;
>> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_LABEL;
>> -import static
>> org.apache.myfaces.tobago.TobagoConstants.ATTR_LAYOUT_HEIGHT;
>> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_MENU_POPUP;
>> -import static
>> org.apache.myfaces.tobago.TobagoConstants.ATTR_MENU_POPUP_TYPE;
>> -import static
>> org.apache.myfaces.tobago.TobagoConstants.ATTR_SELECTED_LIST_STRING;
>> -import static
>> org.apache.myfaces.tobago.TobagoConstants.ATTR_SHOW_DIRECT_LINKS;
>> -import static
>> org.apache.myfaces.tobago.TobagoConstants.ATTR_SHOW_PAGE_RANGE;
>> -import static
>> org.apache.myfaces.tobago.TobagoConstants.ATTR_SHOW_ROW_RANGE;
>> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_SORTABLE;
>> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_STYLE;
>> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_STYLE_BODY;
>> -import static
>> org.apache.myfaces.tobago.TobagoConstants.ATTR_STYLE_CLASS;
>> -import static
>> org.apache.myfaces.tobago.TobagoConstants.ATTR_STYLE_HEADER;
>> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_TYPE;
>> -import static org.apache.myfaces.tobago.TobagoConstants.ATTR_WIDTH_LIST;
>> -import static
>> org.apache.myfaces.tobago.TobagoConstants.ATTR_WIDTH_LIST_STRING;
>> -import static
>> org.apache.myfaces.tobago.TobagoConstants.COMMAND_TYPE_SCRIPT;
>> -import static org.apache.myfaces.tobago.TobagoConstants.FACET_MENUPOPUP;
>> -import static
>> org.apache.myfaces.tobago.TobagoConstants.FACET_PAGER_PAGE;
>> -import static org.apache.myfaces.tobago.TobagoConstants.FACET_PAGER_ROW;
>> -import static
>> org.apache.myfaces.tobago.TobagoConstants.RENDERER_TYPE_LINK;
>> -import static
>> org.apache.myfaces.tobago.TobagoConstants.RENDERER_TYPE_MENUBAR;
>> -import static
>> org.apache.myfaces.tobago.TobagoConstants.RENDERER_TYPE_MENUCOMMAND;
>> -import static
>> org.apache.myfaces.tobago.TobagoConstants.SUBCOMPONENT_SEP;
>> +import static org.apache.myfaces.tobago.TobagoConstants.*;
>> import org.apache.myfaces.tobago.ajax.api.AjaxRenderer;
>> import org.apache.myfaces.tobago.ajax.api.AjaxUtils;
>> import org.apache.myfaces.tobago.component.ComponentUtil;
>> import org.apache.myfaces.tobago.component.Pager;
>> -import org.apache.myfaces.tobago.component.Sorter;
>> import org.apache.myfaces.tobago.component.UIColumnSelector;
>> import org.apache.myfaces.tobago.component.UIData;
>> import org.apache.myfaces.tobago.config.TobagoConfig;
>> @@ -77,22 +44,13 @@
>> import org.apache.myfaces.tobago.webapp.TobagoResponseWriter;
>>
>> import javax.faces.application.Application;
>> -import javax.faces.component.UIColumn;
>> -import javax.faces.component.UICommand;
>> -import javax.faces.component.UIComponent;
>> -import javax.faces.component.UIPanel;
>> -import javax.faces.component.UIViewRoot;
>> +import javax.faces.component.*;
>> import javax.faces.context.FacesContext;
>> import javax.faces.context.ResponseWriter;
>> import javax.faces.el.MethodBinding;
>> import java.io.IOException;
>> import java.text.MessageFormat;
>> -import java.util.ArrayList;
>> -import java.util.Collections;
>> -import java.util.Iterator;
>> -import java.util.List;
>> -import java.util.Locale;
>> -import java.util.Map;
>> +import java.util.*;
>>
>> public class SheetRenderer extends RendererBase
>> implements SheetRendererWorkaround, AjaxRenderer {
>> @@ -774,7 +732,7 @@
>> String image1x1, int sortMarkerWidth) throws IOException {
>> String sheetId = component.getClientId(facesContext);
>> Application application = facesContext.getApplication();
>> - Sorter sorter = component.getSorter();
>> + MethodBinding sorter = component.getSortActionListener();
>>
>> List columnWidths
>> = (List) component.getAttributes().get(ATTR_WIDTH_LIST);
>> @@ -797,18 +755,23 @@
>> ComponentUtil.getBooleanAttribute(column,
>> ATTR_SORTABLE);
>> if (sortable && !(column instanceof UIColumnSelector)) {
>> - String sorterId = Sorter.ID_PREFIX + columnCount;
>> + UICommand sortCommand = (UICommand)
>> column.getFacet(UIData.FACET_SORTER);
>> + if (sortCommand == null) {
>> + String columnId = column.getClientId(facesContext);
>> + String sorterId =
>> columnId.substring(columnId.lastIndexOf(":") + 1 )
>> + + "_" + UIData.SORTER_ID;
>> + sortCommand
>> + = (UICommand)
>> application.createComponent(UICommand.COMPONENT_TYPE);
>> + sortCommand.setRendererType(RENDERER_TYPE_LINK);
>> + sortCommand.setActionListener(sorter);
>> + sortCommand.setId(sorterId);
>> + column.getFacets().put(UIData.FACET_SORTER,
>> sortCommand); + }
>> +
>> String onclick = "submitAction('"
>> + ComponentUtil.findPage(component).getFormId(facesContext)
>> - + "','" + component.getClientId(facesContext) + ":" +
>> sorterId + "')";
>> + + "','" + sortCommand.getClientId(facesContext) + "')";
>> writer.writeAttribute("onclick", onclick, null);
>> - UICommand sortCommand = (UICommand)
>> - application.createComponent(UICommand.COMPONENT_TYPE);
>> - sortCommand.setRendererType(RENDERER_TYPE_LINK);
>> - sortCommand.setActionListener(sorter);
>> - sortCommand.setId(sorterId);
>> - component.getFacets().put(sorterId, sortCommand);
>> - sortCommand.getClientId(facesContext); // this must called here
>> to fix the ClientId
>>
>> writer.writeAttribute("title",
>> ResourceManagerUtil.getPropertyNotNull(facesContext, "tobago",
>>
>> Modified:
>> incubator/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-sheet.js
>>
>> URL:
>> http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-sheet.js?rev=380866&r1=380865&r2=380866&view=diff
>>
>> ==============================================================================
>>
>> ---
>> incubator/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-sheet.js
>> (original)
>> +++
>> incubator/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-sheet.js
>> Fri Feb 24 15:37:31 2006
>> @@ -34,6 +34,9 @@
>> LOG.debug("New Sheet with id " + this.sheetId);
>> },
>>
>> + sortOnclickRegExp :
>> + new RegExp("submitAction\\(('|\")(.*?)('|\") *,
>> *('|\")(.*?)('|\")\\)"),
>> +
>> setup: function() {
>>
>> // setup sorting headers
>> @@ -42,7 +45,18 @@
>> var headerBox = $(idPrefix + i++);
>> while (headerBox) {
>> if (headerBox.onclick) {
>> + var match =
>> this.sortOnclickRegExp.exec(headerBox.onclick.valueOf());
>> +// LOG.debug("match[0] = " + match[0]);
>> +// LOG.debug("match[1] = " + match[1]);
>> +// LOG.debug("*match[2] = " + match[2]);
>> +// LOG.debug("match[3] = " + match[3]);
>> +// LOG.debug("match[4] = " + match[4]);
>> +// LOG.debug("*match[5] = " + match[5]);
>> +// LOG.debug("match[6] = " + match[6]);
>> +// headerBox.formId = match[2];
>> + headerBox.sorterId = match[5];
>> headerBox.onclick = null;
>> +// LOG.debug("headerBox.id = " + headerBox.id);
>> Event.observe(headerBox, "click",
>> this.doSort.bindAsEventListener(this));
>> }
>> headerBox = $(idPrefix + i++);
>> @@ -97,10 +111,12 @@
>>
>> doSort: function(event) {
>> var element = Event.element(event);
>> - var idx = element.id.lastIndexOf('_');
>> - idx = element.id.substring(idx + 1);
>> - var action = this.sheetId + Tobago.componentSeparator + "sorter_"
>> + idx;
>> - this.reloadWithAction(action);
>> + if (!element.sorterId) {
>> + element = element.parentNode;
>> + }
>> +// LOG.debug("element.id = " + element.id);
>> +// LOG.debug("sorterId = " + element.sorterId);
>> + this.reloadWithAction(element.sorterId);
>> },
>>
>> doPagingDirect: function(event) {
>>
>>
>>
>
--
Don't answer to From: address!
Mail to this account are droped if not recieved via mailinglist.
To contact me direct create the mail address by
concatenating my forename to my senders domain.