Save This Page
Home » tomahawk-1.1.6-src » org.apache.myfaces.component.html » ext » [javadoc | source]
    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one
    3    * or more contributor license agreements.  See the NOTICE file
    4    * distributed with this work for additional information
    5    * regarding copyright ownership.  The ASF licenses this file
    6    * to you under the Apache License, Version 2.0 (the
    7    * "License"); you may not use this file except in compliance
    8    * with the License.  You may obtain a copy of the License at
    9    *
   10    *   http://www.apache.org/licenses/LICENSE-2.0
   11    *
   12    * Unless required by applicable law or agreed to in writing,
   13    * software distributed under the License is distributed on an
   14    * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   15    * KIND, either express or implied.  See the License for the
   16    * specific language governing permissions and limitations
   17    * under the License.
   18    */
   19   package org.apache.myfaces.component.html.ext;
   20   
   21   import org.apache.commons.logging.Log;
   22   import org.apache.commons.logging.LogFactory;
   23   import org.apache.myfaces.component.NewspaperTable;
   24   import org.apache.myfaces.component.UserRoleAware;
   25   import org.apache.myfaces.component.UserRoleUtils;
   26   import org.apache.myfaces.custom.crosstable.UIColumns;
   27   import org.apache.myfaces.custom.sortheader.HtmlCommandSortHeader;
   28   import org.apache.myfaces.renderkit.html.ext.HtmlTableRenderer;
   29   import org.apache.myfaces.renderkit.html.util.TableContext;
   30   import org.apache.myfaces.shared_tomahawk.renderkit.JSFAttr;
   31   
   32   import javax.faces.context.FacesContext;
   33   import javax.faces.el.ValueBinding;
   34   import javax.faces.model.DataModel;
   35   import java.io.IOException;
   36   import java.sql.ResultSet;
   37   import java.util;
   38   import javax.faces.application.Application;
   39   import javax.faces.component;
   40   
   41   import org.apache.myfaces.custom.column.HtmlSimpleColumn;
   42   
   43   /**
   44    * @author Thomas Spiegl (latest modification by $Author: mmarinschek $)
   45    * @author Manfred Geiler
   46    * @version $Revision: 483569 $ $Date: 2006-12-07 18:49:35 +0100 (Do, 07 Dez 2006) $
   47    */
   48   public class HtmlDataTable extends HtmlDataTableHack implements UserRoleAware, NewspaperTable
   49   {
   50       private static final Log log = LogFactory.getLog(HtmlDataTable.class);
   51   
   52       private static final int PROCESS_DECODES = 1;
   53       private static final int PROCESS_VALIDATORS = 2;
   54       private static final int PROCESS_UPDATES = 3;
   55   
   56       private static final boolean DEFAULT_SORTASCENDING = true;
   57       private static final boolean DEFAULT_SORTABLE = false;
   58       private static final Class OBJECT_ARRAY_CLASS = (new Object[0]).getClass();
   59   
   60       /**
   61        * the property names
   62        */
   63       public static final String NEWSPAPER_COLUMNS_PROPERTY = "newspaperColumns";
   64       public static final String SPACER_FACET_NAME = "spacer";
   65       public static final String NEWSPAPER_ORIENTATION_PROPERTY = "newspaperOrientation";
   66   
   67       /**
   68        * the value of the column count property
   69        */
   70       private int _newspaperColumns = 1;
   71       /**
   72        * the value of the newspaper orientation property
   73        */
   74       private String _newspaperOrientation = null;
   75   
   76       private _SerializableDataModel _preservedDataModel;
   77   
   78       private String _forceIdIndexFormula = null;
   79       private String _sortColumn = null;
   80       private Boolean _sortAscending = null;
   81       private String _sortProperty = null;
   82       private Boolean _sortable = null;
   83       private String _rowOnClick = null;
   84       private String _rowOnDblClick = null;
   85       private String _rowOnMouseDown = null;
   86       private String _rowOnMouseUp = null;
   87       private String _rowOnMouseOver = null;
   88       private String _rowOnMouseMove = null;
   89       private String _rowOnMouseOut = null;
   90       private String _rowOnKeyPress = null;
   91       private String _rowOnKeyDown = null;
   92       private String _rowOnKeyUp = null;
   93       private String _rowStyleClass = null;
   94       private String _rowStyle = null;
   95       private String _rowGroupStyle = null;
   96       private String _rowGroupStyleClass = null;
   97       private String _varDetailToggler = null;
   98       private String _bodyStyleClass = null;
   99       private String _bodyStyle = null;
  100   
  101       private int _sortColumnIndex = -1;
  102   
  103       private boolean _isValidChildren = true;
  104   
  105       private Set _expandedNodes = new HashSet();
  106   
  107       private Map _detailRowStates = new HashMap();
  108   
  109       private TableContext _tableContext = null;
  110   
  111       public TableContext getTableContext()
  112       {
  113           if (_tableContext == null)
  114           {
  115               _tableContext = new TableContext();
  116           }
  117           return _tableContext;
  118       }
  119   
  120       public String getClientId(FacesContext context)
  121       {
  122           String standardClientId = super.getClientId(context);
  123           int rowIndex = getRowIndex();
  124           if (rowIndex == -1)
  125           {
  126               return standardClientId;
  127           }
  128   
  129           String forcedIdIndex = getForceIdIndexFormula();
  130           if (forcedIdIndex == null || forcedIdIndex.length() == 0)
  131               return standardClientId;
  132   
  133           // Trick : Remove the last part starting with NamingContainer.SEPARATOR_CHAR that contains the rowIndex.
  134           // It would be best to not resort to String manipulation,
  135           // but we can't get super.super.getClientId() :-(
  136           int indexLast_ = standardClientId.lastIndexOf(NamingContainer.SEPARATOR_CHAR);
  137           if (indexLast_ == -1)
  138           {
  139               log.info("Could not parse super.getClientId. forcedIdIndex will contain the rowIndex.");
  140               return standardClientId + NamingContainer.SEPARATOR_CHAR + forcedIdIndex;
  141           }
  142   
  143           //noinspection UnnecessaryLocalVariable
  144           String parsedForcedClientId = standardClientId.substring(0, indexLast_ + 1) + forcedIdIndex;
  145           return parsedForcedClientId;
  146       }
  147   
  148       public UIComponent findComponent(String expr)
  149       {
  150           if (expr.length() > 0 && Character.isDigit(expr.charAt(0)))
  151           {
  152               int separatorIndex = expr.indexOf(NamingContainer.SEPARATOR_CHAR);
  153   
  154               String rowIndexStr = expr;
  155               String remainingPart = null;
  156   
  157               if (separatorIndex != -1)
  158               {
  159                   rowIndexStr = expr.substring(0, separatorIndex);
  160                   remainingPart = expr.substring(separatorIndex + 1);
  161               }
  162   
  163               int rowIndex = Integer.valueOf(rowIndexStr).intValue();
  164   
  165               if (remainingPart == null)
  166               {
  167                   log.error("Wrong syntax of expression : " + expr +
  168                           " rowIndex was provided, but no component name.");
  169                   return null;
  170               }
  171   
  172               UIComponent comp = super.findComponent(remainingPart);
  173   
  174               if (comp == null)
  175                   return null;
  176   
  177               //noinspection UnnecessaryLocalVariable
  178               UIComponentPerspective perspective = new UIComponentPerspective(this, comp, rowIndex);
  179               return perspective;
  180           }
  181           else
  182           {
  183               return super.findComponent(expr);
  184           }
  185       }
  186   
  187       public void setRowIndex(int rowIndex)
  188       {
  189           FacesContext facesContext = FacesContext.getCurrentInstance();
  190   
  191           if (rowIndex < -1)
  192           {
  193               throw new IllegalArgumentException("rowIndex is less than -1");
  194           }
  195   
  196           UIComponent facet = getFacet(HtmlTableRenderer.DETAIL_STAMP_FACET_NAME);
  197           /*Just for obtaining an iterator which must be passed to saveDescendantComponentStates()*/
  198           Set set = new HashSet();
  199           set.add(facet);
  200           if (rowIndex != -1 && facet != null)
  201           {
  202               _detailRowStates.put(getClientId(facesContext), saveDescendantComponentStates(set.iterator(), false));
  203           }
  204   
  205           String rowIndexVar = getRowIndexVar();
  206           String rowCountVar = getRowCountVar();
  207           String previousRowDataVar = getPreviousRowDataVar();
  208           if (rowIndexVar != null || rowCountVar != null || previousRowDataVar != null)
  209           {
  210               Map requestMap = FacesContext.getCurrentInstance().getExternalContext().getRequestMap();
  211   
  212               if (previousRowDataVar != null && rowIndex >= 0) //we only need to provide the previousRowDataVar for a valid rowIndex
  213               {
  214                   if (isRowAvailable())
  215                   {
  216                       //previous row is available
  217                       requestMap.put(previousRowDataVar, getRowData());
  218                   }
  219                   else
  220                   {
  221                       //no previous row available
  222                       requestMap.put(previousRowDataVar, null);
  223                   }
  224               }
  225   
  226               super.setRowIndex(rowIndex);
  227   
  228               if (rowIndex >= 0)
  229               {
  230                   //regular row index, update request scope variables
  231                   if (rowIndexVar != null)
  232                   {
  233                       requestMap.put(rowIndexVar, new Integer(rowIndex));
  234                   }
  235   
  236                   if (rowCountVar != null)
  237                   {
  238                       requestMap.put(rowCountVar, new Integer(getRowCount()));
  239                   }
  240               }
  241               else
  242               {
  243                   //rowIndex == -1 means end of loop --> remove request scope variables
  244                   if (rowIndexVar != null)
  245                   {
  246                       requestMap.remove(rowIndexVar);
  247                   }
  248   
  249                   if (rowCountVar != null)
  250                   {
  251                       requestMap.remove(rowCountVar);
  252                   }
  253   
  254                   if (previousRowDataVar != null)
  255                   {
  256                       requestMap.remove(previousRowDataVar);
  257                   }
  258               }
  259           }
  260           else
  261           {
  262               // no extended var attributes defined, no special treatment
  263               super.setRowIndex(rowIndex);
  264           }
  265   
  266           if (rowIndex != -1 && facet != null)
  267           {
  268               Object rowState = _detailRowStates.get(getClientId(facesContext));
  269   
  270               restoreDescendantComponentStates(set.iterator(),
  271                       rowState, false);
  272   
  273           }
  274   
  275           if (_varDetailToggler != null)
  276           {
  277               Map requestMap = getFacesContext().getExternalContext().getRequestMap();
  278               requestMap.put(_varDetailToggler, this);
  279           }
  280       }
  281   
  282       public void processDecodes(FacesContext context)
  283       {
  284           if (!isRendered())
  285           {
  286               return;
  287           }
  288   
  289           // We must remove and then replace the facet so that
  290           // it is not processed by default facet handling code
  291           //
  292           Object facet = getFacets().remove(HtmlTableRenderer.DETAIL_STAMP_FACET_NAME);
  293           super.processDecodes(context);
  294           if ( facet != null ) getFacets().put(HtmlTableRenderer.DETAIL_STAMP_FACET_NAME, facet);
  295   
  296           setRowIndex(-1);
  297           processColumns(context, PROCESS_DECODES);
  298           setRowIndex(-1);
  299           processDetails(context, PROCESS_DECODES);
  300           setRowIndex(-1);
  301       }
  302   
  303       /**
  304        * @param context
  305        * @param processAction
  306        */
  307       private void processDetails(FacesContext context, int processAction)
  308       {
  309           UIComponent facet = getFacet(HtmlTableRenderer.DETAIL_STAMP_FACET_NAME);
  310   
  311           if (facet != null)
  312           {
  313               int first = getFirst();
  314               int rows = getRows();
  315               int last;
  316               if (rows == 0)
  317               {
  318                   last = getRowCount();
  319               }
  320               else
  321               {
  322                   last = first + rows;
  323               }
  324               for (int rowIndex = first; last == -1 || rowIndex < last; rowIndex++)
  325               {
  326                   setRowIndex(rowIndex);
  327   
  328                   if (!isCurrentDetailExpanded())
  329                   {
  330                       continue;
  331                   }
  332   
  333                   //scrolled past the last row
  334                   if (!isRowAvailable())
  335                       break;
  336   
  337                   // If we are in the decode phase, the values restored into our
  338                   // facet in setRowIndex() may be incorrect. This will happen
  339                   // if some input fields are rendered in some rows, but not
  340                   // rendered in others. In this case the input field components
  341                   // will still contain the _submittedValue from the previous row
  342                   // that had that input field and _submittedValue will not be set to
  343                   // null by the process() method if there was no value submitted.
  344                   // Thus, an invalid component state for that row will be saved in
  345                   // _detailRowStates. The validation phase will not put a null into
  346                   // _sumbittedValue either, b/c the component is not rendered, so
  347                   // validation code doesn't run. This erroneous value will propagate all the way
  348                   // to the render phase, and result in all rows on the current page being
  349                   // rendered with the "stuck" _submittedValue, rather than evaluating the
  350                   // value to render for every row.
  351                   //
  352                   // We can fix this by initializing _submittedValue of all input fields in the facet
  353                   // to null before calling the process() method below during the decode phase.
  354                   //
  355                   if (PROCESS_DECODES == processAction)
  356                   {
  357                       resetAllSubmittedValues(facet);
  358                   }
  359   
  360                   process(context, facet, processAction);
  361   
  362                   if ( rowIndex == (last - 1) )
  363                   {
  364                       Set set = new HashSet();
  365                       set.add(facet);
  366                       _detailRowStates.put(
  367                               getClientId(FacesContext.getCurrentInstance()),
  368                                   saveDescendantComponentStates(set.iterator(),false));
  369                   }
  370               }
  371           }
  372       }
  373   
  374       private void resetAllSubmittedValues(UIComponent component)
  375       {
  376           if (component instanceof EditableValueHolder)
  377           {
  378               ((EditableValueHolder) component).setSubmittedValue(null);
  379           }
  380   
  381           for (Iterator it = component.getFacetsAndChildren(); it.hasNext();)
  382           {
  383               resetAllSubmittedValues((UIComponent) it.next());
  384           }
  385       }
  386   
  387       /**
  388        * @param context
  389        * @param processAction
  390        */
  391       private void processColumns(FacesContext context, int processAction)
  392       {
  393           for (Iterator it = getChildren().iterator(); it.hasNext();)
  394           {
  395               UIComponent child = (UIComponent) it.next();
  396               if (child instanceof UIColumns)
  397               {
  398                   process(context, child, processAction);
  399               }
  400           }
  401       }
  402   
  403       private void process(FacesContext context, UIComponent component, int processAction)
  404       {
  405           switch (processAction)
  406           {
  407               case PROCESS_DECODES:
  408                   component.processDecodes(context);
  409                   break;
  410               case PROCESS_VALIDATORS:
  411                   component.processValidators(context);
  412                   break;
  413               case PROCESS_UPDATES:
  414                   component.processUpdates(context);
  415                   break;
  416           }
  417       }
  418   
  419       public void processValidators(FacesContext context)
  420       {
  421           if (!isRendered())
  422           {
  423               return;
  424           }
  425           // We must remove and then replace the facet so that
  426           // it is not processed by default facet handling code
  427           //
  428           Object facet = getFacets().remove(HtmlTableRenderer.DETAIL_STAMP_FACET_NAME);
  429           super.processValidators(context);
  430           if ( facet != null ) getFacets().put(HtmlTableRenderer.DETAIL_STAMP_FACET_NAME, facet);
  431   
  432           processColumns(context, PROCESS_VALIDATORS);
  433           setRowIndex(-1);
  434           processDetails(context, PROCESS_VALIDATORS);
  435           setRowIndex(-1);
  436   
  437           if (context.getRenderResponse())
  438           {
  439               _isValidChildren = false;
  440           }
  441       }
  442   
  443       public void processUpdates(FacesContext context)
  444       {
  445           if (!isRendered())
  446           {
  447               return;
  448           }
  449   
  450           // We must remove and then replace the facet so that
  451           // it is not processed by default facet handling code
  452           //
  453           Object facet = getFacets().remove(HtmlTableRenderer.DETAIL_STAMP_FACET_NAME);
  454           super.processUpdates(context);
  455           if ( facet != null ) getFacets().put(HtmlTableRenderer.DETAIL_STAMP_FACET_NAME, facet);
  456   
  457           processColumns(context, PROCESS_UPDATES);
  458           setRowIndex(-1);
  459           processDetails(context, PROCESS_UPDATES);
  460           setRowIndex(-1);
  461   
  462           if (isPreserveDataModel())
  463           {
  464               updateModelFromPreservedDataModel(context);
  465           }
  466   
  467           if (context.getRenderResponse())
  468           {
  469               _isValidChildren = false;
  470           }
  471       }
  472   
  473       private void updateModelFromPreservedDataModel(FacesContext context)
  474       {
  475           ValueBinding vb = getValueBinding("value");
  476           if (vb != null && !vb.isReadOnly(context))
  477           {
  478               _SerializableDataModel dm = (_SerializableDataModel) getDataModel();
  479               Class type = vb.getType(context);
  480               if (DataModel.class.isAssignableFrom(type))
  481               {
  482                   vb.setValue(context, dm);
  483               }
  484               else if (List.class.isAssignableFrom(type))
  485               {
  486                   vb.setValue(context, dm.getWrappedData());
  487               }
  488               else if (OBJECT_ARRAY_CLASS.isAssignableFrom(type))
  489               {
  490                   List lst = (List) dm.getWrappedData();
  491                   vb.setValue(context, lst.toArray(new Object[lst.size()]));
  492               }
  493               else if (ResultSet.class.isAssignableFrom(type))
  494               {
  495                   throw new UnsupportedOperationException(this.getClass().getName()
  496                           + " UnsupportedOperationException");
  497               }
  498               else
  499               {
  500                   //Assume scalar data model
  501                   List lst = (List) dm.getWrappedData();
  502                   if (lst.size() > 0)
  503                   {
  504                       vb.setValue(context, lst.get(0));
  505                   }
  506                   else
  507                   {
  508                       vb.setValue(context, null);
  509                   }
  510               }
  511           }
  512           _preservedDataModel = null;
  513       }
  514   
  515       public void encodeBegin(FacesContext context) throws IOException
  516       {
  517           if (!isRendered())
  518               return;
  519   
  520           if (_isValidChildren && !hasErrorMessages(context))
  521           {
  522               _preservedDataModel = null;
  523           }
  524   
  525           for (Iterator iter = getChildren().iterator(); iter.hasNext();)
  526           {
  527               UIComponent component = (UIComponent) iter.next();
  528               if (component instanceof UIColumns)
  529               {
  530                   // Merge the columns from the tomahawk dynamic component
  531                   // into this object.
  532                   ((UIColumns) component).encodeTableBegin(context);
  533               }
  534           }
  535   
  536           //replace facet header content component of the columns, with a new command sort header component
  537           //if sortable=true, replace it for all, if not just for the columns marked as sortable
  538           for (Iterator iter = getChildren().iterator(); iter.hasNext();)
  539           {
  540               UIComponent component = (UIComponent) iter.next();
  541               if (component instanceof UIColumn)
  542               {
  543                   UIColumn aColumn = (UIColumn) component;
  544                   UIComponent headerFacet = aColumn.getHeader();
  545   
  546                   boolean replaceHeaderFacets = isSortable(); //if the table is sortable, all
  547                   //header facets can be changed if needed
  548                   String columnName = null;
  549                   String propertyName = null;
  550                   boolean defaultSorted = false;
  551   
  552                   if (aColumn instanceof HtmlSimpleColumn)
  553                   {
  554                       HtmlSimpleColumn asColumn = (HtmlSimpleColumn) aColumn;
  555                       propertyName = asColumn.getSortPropertyName();
  556                       defaultSorted = asColumn.isDefaultSorted();
  557   
  558                       if (asColumn.isSortable())
  559                           replaceHeaderFacets = true;
  560                   }
  561   
  562                   //replace header facet with a sortable header component if needed
  563                   if (replaceHeaderFacets && isSortHeaderNeeded(aColumn, headerFacet))
  564                   {
  565                       propertyName = propertyName != null ? propertyName : getSortPropertyFromEL(aColumn);
  566                       if (propertyName == null)
  567                           log.warn("Couldn't determine sort property for column [" + aColumn.getId() + "].");
  568   
  569                       if (headerFacet != null)
  570                       {
  571                           HtmlCommandSortHeader sortHeader = createSortHeaderComponent(context, aColumn, headerFacet, propertyName);
  572                           columnName = sortHeader.getColumnName();
  573   
  574                           aColumn.setHeader(sortHeader);
  575                           sortHeader.setParent(aColumn);
  576                       }
  577                   }
  578                   else if (headerFacet instanceof HtmlCommandSortHeader)
  579                   {
  580                       //command sort headers are already in place, just store the column name and sort property name
  581                       HtmlCommandSortHeader sortHeader = (HtmlCommandSortHeader) headerFacet;
  582                       columnName = sortHeader.getColumnName();
  583                       propertyName = sortHeader.getPropertyName();
  584   
  585                       //if the command sort header component doesn't specify a sort property, determine it
  586                       if (propertyName == null)
  587                       {
  588                           propertyName = getSortPropertyFromEL(aColumn);
  589                           sortHeader.setPropertyName(propertyName);
  590                       }
  591   
  592                       if (propertyName == null)
  593                           log.warn("Couldn't determine sort property for column [" + aColumn.getId() + "].");
  594                   }
  595   
  596                   //make the column marked as default sorted be the current sorted column
  597                   if (defaultSorted && getSortColumn() == null)
  598                   {
  599                       setSortColumn(columnName);
  600                       setSortProperty(propertyName);
  601                   }
  602               }
  603           }
  604   
  605           // Now invoke the superclass encodeBegin, which will eventually
  606           // execute the encodeBegin for the associated renderer.
  607           super.encodeBegin(context);
  608       }
  609   
  610       /**
  611        *
  612        */
  613       protected boolean isSortHeaderNeeded(UIColumn parentColumn, UIComponent headerFacet)
  614       {
  615           return !(headerFacet instanceof HtmlCommandSortHeader);
  616       }
  617   
  618       /**
  619        *
  620        */
  621       protected HtmlCommandSortHeader createSortHeaderComponent(FacesContext context, UIColumn parentColumn, UIComponent initialHeaderFacet, String propertyName)
  622       {
  623           Application application = context.getApplication();
  624   
  625           HtmlCommandSortHeader sortHeader = (HtmlCommandSortHeader) application.createComponent(HtmlCommandSortHeader.COMPONENT_TYPE);
  626           String id = context.getViewRoot().createUniqueId();
  627           sortHeader.setId(id);
  628           sortHeader.setColumnName(id);
  629           sortHeader.setPropertyName(propertyName);
  630           sortHeader.setArrow(true);
  631           sortHeader.setImmediate(true); //needed to work when dataScroller is present
  632           sortHeader.getChildren().add(initialHeaderFacet);
  633           initialHeaderFacet.setParent(sortHeader);
  634   
  635           return sortHeader;
  636       }
  637   
  638       /**
  639        *
  640        */
  641       protected String getSortPropertyFromEL(UIComponent component)
  642       {
  643           if (getVar() == null)
  644           {
  645               log.warn("There is no 'var' specified on the dataTable, sort properties cannot be determined automaticaly.");
  646               return null;
  647           }
  648   
  649           for (Iterator iter = component.getChildren().iterator(); iter.hasNext();)
  650           {
  651               UIComponent aChild = (UIComponent) iter.next();
  652               if (aChild.isRendered())
  653               {
  654                   ValueBinding vb = aChild.getValueBinding("value");
  655                   if (vb != null)
  656                   {
  657                       String expressionString = vb.getExpressionString();
  658   
  659                       int varIndex = expressionString.indexOf(getVar() + ".");
  660                       if (varIndex != -1)
  661                       {
  662                           int varEndIndex = varIndex + getVar().length();
  663                           String tempProp = expressionString.substring(varEndIndex + 1, expressionString.length());
  664   
  665                           StringTokenizer tokenizer = new StringTokenizer(tempProp, " +[]{}-/*|?:&<>!=()%");
  666                           if (tokenizer.hasMoreTokens())
  667                               return tokenizer.nextToken();
  668                       }
  669                   }
  670                   else
  671                   {
  672                       String sortProperty = getSortPropertyFromEL(aChild);
  673                       if (sortProperty != null)
  674                           return sortProperty;
  675                   }
  676               }
  677           }
  678   
  679           return null;
  680       }
  681   
  682       /**
  683        * @return the index coresponding to the given column name.
  684        */
  685       protected int columnNameToIndex(String columnName)
  686       {
  687           int index = 0;
  688           for (Iterator iter = getChildren().iterator(); iter.hasNext();)
  689           {
  690               UIComponent aChild = (UIComponent) iter.next();
  691               if (aChild instanceof UIColumn)
  692               {
  693                   UIComponent headerFacet = ((UIColumn) aChild).getHeader();
  694                   if (headerFacet != null && headerFacet instanceof HtmlCommandSortHeader)
  695                   {
  696                       HtmlCommandSortHeader sortHeader = (HtmlCommandSortHeader) headerFacet;
  697                       if (columnName != null && columnName.equals(sortHeader.getColumnName()))
  698                           return index;
  699                   }
  700               }
  701   
  702               index += 1;
  703           }
  704   
  705           return -1;
  706       }
  707   
  708       /**
  709        * @see javax.faces.component.UIData#encodeEnd(javax.faces.context.FacesContext)
  710        */
  711       public void encodeEnd(FacesContext context) throws IOException
  712       {
  713           super.encodeEnd(context);
  714           for (Iterator iter = getChildren().iterator(); iter.hasNext();)
  715           {
  716               UIComponent component = (UIComponent) iter.next();
  717               if (component instanceof UIColumns)
  718               {
  719                   ((UIColumns) component).encodeTableEnd(context);
  720               }
  721           }
  722       }
  723   
  724       public int getFirst()
  725       {
  726           if (_preservedDataModel != null)
  727           {
  728               //Rather get the currently restored DataModel attribute
  729               return _preservedDataModel.getFirst();
  730           }
  731           else
  732           {
  733               return super.getFirst();
  734           }
  735       }
  736   
  737       public void setFirst(int first)
  738       {
  739           if (_preservedDataModel != null)
  740           {
  741               //Also change the currently restored DataModel attribute
  742               _preservedDataModel.setFirst(first);
  743           }
  744           super.setFirst(first);
  745       }
  746   
  747       public int getRows()
  748       {
  749           if (_preservedDataModel != null)
  750           {
  751               //Rather get the currently restored DataModel attribute
  752               return _preservedDataModel.getRows();
  753           }
  754           else
  755           {
  756               return super.getRows();
  757           }
  758       }
  759   
  760       public void setRows(int rows)
  761       {
  762           if (_preservedDataModel != null)
  763           {
  764               //Also change the currently restored DataModel attribute
  765               _preservedDataModel.setRows(rows);
  766           }
  767           super.setRows(rows);
  768       }
  769   
  770       public Object saveState(FacesContext context)
  771       {
  772           boolean preserveSort = isPreserveSort();
  773   
  774           Object values[] = new Object[36];
  775           values[0] = super.saveState(context);
  776           values[1] = _preserveDataModel;
  777   
  778           if (isPreserveDataModel())
  779           {
  780               values[2] = saveAttachedState(context, getSerializableDataModel());
  781           }
  782           else
  783           {
  784               values[2] = null;
  785           }
  786           values[3] = _preserveSort;
  787           values[4] = _forceIdIndexFormula;
  788           values[5] = _sortColumn;
  789           values[6] = _sortAscending;
  790           values[7] = _sortProperty;
  791           values[8] = _sortable;
  792           values[9] = _renderedIfEmpty;
  793           values[10] = _rowCountVar;
  794           values[11] = _rowIndexVar;
  795   
  796           values[12] = _rowOnClick;
  797           values[13] = _rowOnDblClick;
  798           values[14] = _rowOnMouseDown;
  799           values[15] = _rowOnMouseUp;
  800           values[16] = _rowOnMouseOver;
  801           values[17] = _rowOnMouseMove;
  802           values[18] = _rowOnMouseOut;
  803           values[19] = _rowOnKeyPress;
  804           values[20] = _rowOnKeyDown;
  805           values[21] = _rowOnKeyUp;
  806   
  807           values[22] = _rowStyleClass;
  808           values[23] = _rowStyle;
  809   
  810           values[24] = preserveSort ? getSortColumn() : null;
  811           values[25] = preserveSort ? Boolean.valueOf(isSortAscending()) : null;
  812   
  813           values[26] = _varDetailToggler;
  814           values[27] = _expandedNodes;
  815           values[28] = _rowGroupStyle;
  816           values[29] = _rowGroupStyleClass;
  817           values[30] = _sortedColumnVar;
  818           values[31] = new Integer(_sortColumnIndex);
  819   
  820           values[32] = new Integer(_newspaperColumns);
  821           values[33] = _newspaperOrientation;
  822           values[34] = _bodyStyle;
  823           values[35] = _bodyStyleClass;
  824   
  825           return values;
  826       }
  827   
  828       /**
  829        * @see org.apache.myfaces.component.html.ext.HtmlDataTableHack#getDataModel()
  830        */
  831       protected DataModel getDataModel()
  832       {
  833           if (_preservedDataModel != null)
  834           {
  835               setDataModel(_preservedDataModel);
  836               _preservedDataModel = null;
  837           }
  838   
  839           return super.getDataModel();
  840       }
  841   
  842       /**
  843        * @see org.apache.myfaces.component.html.ext.HtmlDataTableHack#createDataModel()
  844        */
  845       protected DataModel createDataModel()
  846       {
  847           DataModel dataModel = super.createDataModel();
  848   
  849           boolean isSortable = isSortable();
  850   
  851           if (!(dataModel instanceof SortableModel))
  852           {
  853               //if sortable=true make each column sortable
  854               //if sortable=false, check to see if at least one column sortable case in which
  855               //the current model needs to be wrapped by a sortable one.
  856               for (Iterator iter = getChildren().iterator(); iter.hasNext();)
  857               {
  858                   UIComponent component = (UIComponent) iter.next();
  859                   if (component instanceof HtmlSimpleColumn)
  860                   {
  861                       HtmlSimpleColumn aColumn = (HtmlSimpleColumn) component;
  862                       if (isSortable())
  863                           aColumn.setSortable(true);
  864   
  865                       if (aColumn.isSortable())
  866                           isSortable = true;
  867   
  868                       if (aColumn.isDefaultSorted() && getSortColumn() == null)
  869                           setSortProperty(aColumn.getSortPropertyName());
  870                   }
  871               }
  872   
  873               if (isSortable)
  874                   dataModel = new SortableModel(dataModel);
  875           }
  876   
  877           if (isSortable && getSortProperty() != null)
  878           {
  879               SortCriterion criterion = new SortCriterion(getSortProperty(), isSortAscending());
  880               List criteria = new ArrayList();
  881               criteria.add(criterion);
  882   
  883               ((SortableModel) dataModel).setSortCriteria(criteria);
  884           }
  885   
  886           return dataModel;
  887       }
  888   
  889       public void restoreState(FacesContext context, Object state)
  890       {
  891           Object values[] = (Object[]) state;
  892           super.restoreState(context, values[0]);
  893           _preserveDataModel = (Boolean) values[1];
  894           if (isPreserveDataModel())
  895           {
  896               _preservedDataModel = (_SerializableDataModel) restoreAttachedState(context, values[2]);
  897           }
  898           else
  899           {
  900               _preservedDataModel = null;
  901           }
  902           _preserveSort = (Boolean) values[3];
  903           _forceIdIndexFormula = (String) values[4];
  904           _sortColumn = (String) values[5];
  905           _sortAscending = (Boolean) values[6];
  906           _sortProperty = (String) values[7];
  907           _sortable = (Boolean) values[8];
  908           _renderedIfEmpty = (Boolean) values[9];
  909           _rowCountVar = (String) values[10];
  910           _rowIndexVar = (String) values[11];
  911   
  912           _rowOnClick = (String) values[12];
  913           _rowOnDblClick = (String) values[13];
  914           _rowOnMouseDown = (String) values[14];
  915           _rowOnMouseUp = (String) values[15];
  916           _rowOnMouseOver = (String) values[16];
  917           _rowOnMouseMove = (String) values[17];
  918           _rowOnMouseOut = (String) values[18];
  919           _rowOnKeyPress = (String) values[19];
  920           _rowOnKeyDown = (String) values[20];
  921           _rowOnKeyUp = (String) values[21];
  922   
  923           _rowStyleClass = (String) values[22];
  924           _rowStyle = (String) values[23];
  925   
  926           if (isPreserveSort())
  927           {
  928               String sortColumn = (String) values[24];
  929               Boolean sortAscending = (Boolean) values[25];
  930               if (sortColumn != null && sortAscending != null)
  931               {
  932                   ValueBinding vb = getValueBinding("sortColumn");
  933                   if (vb != null && !vb.isReadOnly(context))
  934                   {
  935                       vb.setValue(context, sortColumn);
  936                   }
  937   
  938                   vb = getValueBinding("sortAscending");
  939                   if (vb != null && !vb.isReadOnly(context))
  940                   {
  941                       vb.setValue(context, sortAscending);
  942                   }
  943               }
  944           }
  945   
  946           _varDetailToggler = (String) values[26];
  947           _expandedNodes = (Set) values[27];
  948           _rowGroupStyle = (String) values[28];
  949           _rowGroupStyleClass = (String) values[29];
  950           _sortedColumnVar = (String) values[30];
  951           _sortColumnIndex = values[31] != null ? ((Integer) values[31]).intValue() : -1;
  952           _newspaperColumns = ((Integer) values[32]).intValue();
  953           _newspaperOrientation = (String) values[33];
  954           _bodyStyle = (String) values[34];
  955           _bodyStyleClass = (String) values[35];
  956       }
  957   
  958       public _SerializableDataModel getSerializableDataModel()
  959       {
  960           DataModel dm = getDataModel();
  961           if (dm instanceof _SerializableDataModel)
  962           {
  963               return (_SerializableDataModel) dm;
  964           }
  965           return createSerializableDataModel();
  966       }
  967   
  968       /**
  969        * @return _SerializableDataModel
  970        */
  971       private _SerializableDataModel createSerializableDataModel()
  972       {
  973           Object value = getValue();
  974           if (value == null)
  975           {
  976               return null;
  977           }
  978           else if (value instanceof DataModel)
  979           {
  980               return new _SerializableDataModel(getFirst(), getRows(), (DataModel) value);
  981           }
  982           else if (value instanceof List)
  983           {
  984               return new _SerializableListDataModel(getFirst(), getRows(), (List) value);
  985           }
  986           // accept a Collection is not supported in the Spec
  987           else if (value instanceof Collection)
  988           {
  989               return new _SerializableListDataModel(getFirst(), getRows(), new ArrayList((Collection) value));
  990           }
  991           else if (OBJECT_ARRAY_CLASS.isAssignableFrom(value.getClass()))
  992           {
  993               return new _SerializableArrayDataModel(getFirst(), getRows(), (Object[]) value);
  994           }
  995           else if (value instanceof ResultSet)
  996           {
  997               return new _SerializableResultSetDataModel(getFirst(), getRows(), (ResultSet) value);
  998           }
  999           else if (value instanceof javax.servlet.jsp.jstl.sql.Result)
 1000           {
 1001               return new _SerializableResultDataModel(getFirst(), getRows(),
 1002                       (javax.servlet.jsp.jstl.sql.Result) value);
 1003           }
 1004           else
 1005           {
 1006               return new _SerializableScalarDataModel(getFirst(), getRows(), value);
 1007           }
 1008       }
 1009   
 1010       public boolean isRendered()
 1011       {
 1012           if (!UserRoleUtils.isVisibleOnUserRole(this))
 1013               return false;
 1014           return super.isRendered();
 1015       }
 1016   
 1017       public void setForceIdIndexFormula(String forceIdIndexFormula)
 1018       {
 1019           _forceIdIndexFormula = forceIdIndexFormula;
 1020           ValueBinding vb = getValueBinding("forceIdIndexFormula");
 1021           if (vb != null)
 1022           {
 1023               vb.setValue(getFacesContext(), _forceIdIndexFormula);
 1024               _forceIdIndexFormula = null;
 1025           }
 1026       }
 1027   
 1028       public String getForceIdIndexFormula()
 1029       {
 1030           if (_forceIdIndexFormula != null)
 1031               return _forceIdIndexFormula;
 1032           ValueBinding vb = getValueBinding("forceIdIndexFormula");
 1033           if (vb == null)
 1034               return null;
 1035           Object eval = vb.getValue(getFacesContext());
 1036           return eval == null ? null : eval.toString();
 1037       }
 1038   
 1039       /**
 1040        * Specify what column the data should be sorted on.
 1041        * <p/>
 1042        * Note that calling this method <i>immediately</i> stores the value
 1043        * via any value-binding with name "sortColumn". This is done because
 1044        * this method is called by the HtmlCommandSortHeader component when
 1045        * the user has clicked on a column's sort header. In this case, the
 1046        * the model getter method mapped for name "value" needs to read this
 1047        * value in able to return the data in the desired order - but the
 1048        * HtmlCommandSortHeader component is usually "immediate" in order to
 1049        * avoid validating the enclosing form. Yes, this is rather hacky -
 1050        * but it works.
 1051        */
 1052       public void setSortColumn(String sortColumn)
 1053       {
 1054           _sortColumn = sortColumn;
 1055           // update model is necessary here, because processUpdates is never called
 1056           // reason: HtmlCommandSortHeader.isImmediate() == true
 1057           ValueBinding vb = getValueBinding("sortColumn");
 1058           if (vb != null)
 1059           {
 1060               vb.setValue(getFacesContext(), _sortColumn);
 1061               _sortColumn = null;
 1062           }
 1063   
 1064           setSortColumnIndex(columnNameToIndex(sortColumn));
 1065       }
 1066   
 1067       public String getSortColumn()
 1068       {
 1069           if (_sortColumn != null) return _sortColumn;
 1070           ValueBinding vb = getValueBinding("sortColumn");
 1071           return vb != null ? (String) vb.getValue(getFacesContext()) : null;
 1072       }
 1073   
 1074       public void setSortAscending(boolean sortAscending)
 1075       {
 1076           _sortAscending = Boolean.valueOf(sortAscending);
 1077           // update model is necessary here, because processUpdates is never called
 1078           // reason: HtmlCommandSortHeader.isImmediate() == true
 1079           ValueBinding vb = getValueBinding("sortAscending");
 1080           if (vb != null)
 1081           {
 1082               vb.setValue(getFacesContext(), _sortAscending);
 1083               _sortAscending = null;
 1084           }
 1085       }
 1086   
 1087       public boolean isSortAscending()
 1088       {
 1089           if (_sortAscending != null)
 1090               return _sortAscending.booleanValue();
 1091           ValueBinding vb = getValueBinding("sortAscending");
 1092           Boolean v = vb != null ? (Boolean) vb.getValue(getFacesContext()) : null;
 1093           return v != null ? v.booleanValue() : DEFAULT_SORTASCENDING;
 1094       }
 1095   
 1096       public void setSortProperty(String sortProperty)
 1097       {
 1098           _sortProperty = sortProperty;
 1099       }
 1100   
 1101       public String getSortProperty()
 1102       {
 1103           return _sortProperty;
 1104       }
 1105   
 1106       public void setSortable(boolean sortable)
 1107       {
 1108           _sortable = sortable ? Boolean.TRUE : Boolean.FALSE;
 1109       }
 1110   
 1111       public boolean isSortable()
 1112       {
 1113           if (_sortable != null) return _sortable.booleanValue();
 1114           ValueBinding vb = getValueBinding("sortable");
 1115           Boolean v = vb != null ? (Boolean) vb.getValue(getFacesContext()) : null;
 1116           return v != null ? v.booleanValue() : DEFAULT_SORTABLE;
 1117       }
 1118   
 1119       public void setRowOnMouseOver(String rowOnMouseOver)
 1120       {
 1121           _rowOnMouseOver = rowOnMouseOver;
 1122       }
 1123   
 1124       public String getRowOnMouseOver()
 1125       {
 1126           if (_rowOnMouseOver != null)
 1127               return _rowOnMouseOver;
 1128           ValueBinding vb = getValueBinding("rowOnMouseOver");
 1129           return vb != null ? (String) vb.getValue(getFacesContext()) : null;
 1130       }
 1131   
 1132       public void setRowOnMouseOut(String rowOnMouseOut)
 1133       {
 1134           _rowOnMouseOut = rowOnMouseOut;
 1135       }
 1136   
 1137       public String getRowOnMouseOut()
 1138       {
 1139           if (_rowOnMouseOut != null)
 1140               return _rowOnMouseOut;
 1141           ValueBinding vb = getValueBinding("rowOnMouseOut");
 1142           return vb != null ? (String) vb.getValue(getFacesContext()) : null;
 1143       }
 1144   
 1145       public void setRowOnClick(String rowOnClick)
 1146       {
 1147           _rowOnClick = rowOnClick;
 1148       }
 1149   
 1150       public String getRowOnClick()
 1151       {
 1152           if (_rowOnClick != null)
 1153               return _rowOnClick;
 1154           ValueBinding vb = getValueBinding("rowOnClick");
 1155           return vb != null ? (String) vb.getValue(getFacesContext()) : null;
 1156       }
 1157   
 1158       public void setRowOnDblClick(String rowOnDblClick)
 1159       {
 1160           _rowOnDblClick = rowOnDblClick;
 1161       }
 1162   
 1163       public String getRowOnDblClick()
 1164       {
 1165           if (_rowOnDblClick != null)
 1166               return _rowOnDblClick;
 1167           ValueBinding vb = getValueBinding("rowOnDblClick");
 1168           return vb != null ? (String) vb.getValue(getFacesContext()) : null;
 1169       }
 1170   
 1171       public String getRowOnKeyDown()
 1172       {
 1173           if (_rowOnKeyDown != null)
 1174               return _rowOnKeyDown;
 1175           ValueBinding vb = getValueBinding("rowOnKeyDown");
 1176           return vb != null ? (String) vb.getValue(getFacesContext()) : null;
 1177       }
 1178   
 1179       public void setRowOnKeyDown(String rowOnKeyDown)
 1180       {
 1181           _rowOnKeyDown = rowOnKeyDown;
 1182       }
 1183   
 1184       public String getRowOnKeyPress()
 1185       {
 1186           if (_rowOnKeyPress != null)
 1187               return _rowOnKeyPress;
 1188           ValueBinding vb = getValueBinding("rowOnKeyPress");
 1189           return vb != null ? (String) vb.getValue(getFacesContext()) : null;
 1190       }
 1191   
 1192       public void setRowOnKeyPress(String rowOnKeyPress)
 1193       {
 1194           _rowOnKeyPress = rowOnKeyPress;
 1195       }
 1196   
 1197       public String getRowOnKeyUp()
 1198       {
 1199           if (_rowOnKeyUp != null)
 1200               return _rowOnKeyUp;
 1201           ValueBinding vb = getValueBinding("rowOnKeyUp");
 1202           return vb != null ? (String) vb.getValue(getFacesContext()) : null;
 1203       }
 1204   
 1205       public void setRowOnKeyUp(String rowOnKeyUp)
 1206       {
 1207           _rowOnKeyUp = rowOnKeyUp;
 1208       }
 1209   
 1210       public String getRowStyleClass()
 1211       {
 1212           if (_rowStyleClass != null)
 1213               return _rowStyleClass;
 1214           ValueBinding vb = getValueBinding(JSFAttr.ROW_STYLECLASS_ATTR);
 1215           return vb != null ? (String) vb.getValue(getFacesContext()) : null;
 1216       }
 1217   
 1218       public void setRowStyleClass(String rowStyleClass)
 1219       {
 1220           _rowStyleClass = rowStyleClass;
 1221       }
 1222   
 1223       public String getRowStyle()
 1224       {
 1225           if (_rowStyle != null)
 1226               return _rowStyle;
 1227           ValueBinding vb = getValueBinding(JSFAttr.ROW_STYLE_ATTR);
 1228           return vb != null ? (String) vb.getValue(getFacesContext()) : null;
 1229       }
 1230   
 1231       public void setRowStyle(String rowStyle)
 1232       {
 1233           _rowStyle = rowStyle;
 1234       }
 1235   
 1236       public String getRowOnMouseDown()
 1237       {
 1238           if (_rowOnMouseDown != null)
 1239               return _rowOnMouseDown;
 1240           ValueBinding vb = getValueBinding("rowOnMouseDown");
 1241           return vb != null ? (String) vb.getValue(getFacesContext()) : null;
 1242       }
 1243   
 1244       public void setRowOnMouseDown(String rowOnMouseDown)
 1245       {
 1246           _rowOnMouseDown = rowOnMouseDown;
 1247       }
 1248   
 1249       public String getRowOnMouseMove()
 1250       {
 1251           if (_rowOnMouseMove != null)
 1252               return _rowOnMouseMove;
 1253           ValueBinding vb = getValueBinding("rowOnMouseMove");
 1254           return vb != null ? (String) vb.getValue(getFacesContext()) : null;
 1255       }
 1256   
 1257       public void setRowOnMouseMove(String rowOnMouseMove)
 1258       {
 1259           _rowOnMouseMove = rowOnMouseMove;
 1260       }
 1261   
 1262       public String getRowOnMouseUp()
 1263       {
 1264           if (_rowOnMouseUp != null)
 1265               return _rowOnMouseUp;
 1266           ValueBinding vb = getValueBinding("rowOnMouseUp");
 1267           return vb != null ? (String) vb.getValue(getFacesContext()) : null;
 1268       }
 1269   
 1270       public void setRowOnMouseUp(String rowOnMouseUp)
 1271       {
 1272           _rowOnMouseUp = rowOnMouseUp;
 1273       }
 1274   
 1275       protected boolean isValidChildren()
 1276       {
 1277           return _isValidChildren;
 1278       }
 1279   
 1280       protected void setIsValidChildren(boolean isValidChildren)
 1281       {
 1282           _isValidChildren = isValidChildren;
 1283       }
 1284   
 1285       protected _SerializableDataModel getPreservedDataModel()
 1286       {
 1287           return _preservedDataModel;
 1288       }
 1289   
 1290       protected void setPreservedDataModel(_SerializableDataModel preservedDataModel)
 1291       {
 1292           _preservedDataModel = preservedDataModel;
 1293       }
 1294   
 1295   
 1296       public boolean isCurrentDetailExpanded()
 1297       {
 1298           return _expandedNodes.contains(new Integer(getRowIndex()));
 1299       }
 1300   
 1301       public void setVarDetailToggler(String varDetailToggler)
 1302       {
 1303           _varDetailToggler = varDetailToggler;
 1304       }
 1305   
 1306       public String getVarDetailToggler()
 1307       {
 1308           return _varDetailToggler;
 1309       }
 1310   
 1311       public String getRowGroupStyle()
 1312       {
 1313           if (_rowGroupStyle != null)
 1314               return _rowGroupStyle;
 1315           ValueBinding vb = getValueBinding("rowGroupStyle");
 1316           return vb != null ? (String) vb.getValue(getFacesContext()) : null;
 1317       }
 1318   
 1319       public void setRowGroupStyle(String rowGroupStyle)
 1320       {
 1321           _rowGroupStyle = rowGroupStyle;
 1322       }
 1323   
 1324       public String getRowGroupStyleClass()
 1325       {
 1326           if (_rowGroupStyleClass != null)
 1327               return _rowGroupStyleClass;
 1328           ValueBinding vb = getValueBinding("rowGroupStyleClass");
 1329           return vb != null ? (String) vb.getValue(getFacesContext()) : null;
 1330       }
 1331   
 1332       public void setRowGroupStyleClass(String rowGroupStyleClass)
 1333       {
 1334           _rowGroupStyleClass = rowGroupStyleClass;
 1335       }
 1336   
 1337       public String getBodyStyle()
 1338       {
 1339           if (_bodyStyle != null)
 1340               return _bodyStyle;
 1341           ValueBinding vb = getValueBinding("bodyStyle");
 1342           return vb != null ? (String) vb.getValue(getFacesContext()) : null;
 1343       }
 1344   
 1345       public void setBodyStyle(String bodyStyle)
 1346       {
 1347           _bodyStyle = bodyStyle;
 1348       }
 1349   
 1350       public String getBodyStyleClass()
 1351       {
 1352           if (_bodyStyleClass != null)
 1353               return _bodyStyleClass;
 1354           ValueBinding vb = getValueBinding("bodyStyleClass");
 1355           return vb != null ? (String) vb.getValue(getFacesContext()) : null;
 1356       }
 1357   
 1358       public void setBodyStyleClass(String bodyStyleClass)
 1359       {
 1360           _bodyStyleClass = bodyStyleClass;
 1361       }
 1362   
 1363       public HtmlDataTable()
 1364       {
 1365           setRendererType(DEFAULT_RENDERER_TYPE);
 1366       }
 1367   
 1368       /**
 1369        * Change the status of the current detail row from collapsed to expanded or
 1370        * viceversa.
 1371        */
 1372       public void toggleDetail()
 1373       {
 1374           Integer rowIndex = new Integer(getRowIndex());
 1375   
 1376           if (_expandedNodes.contains(rowIndex))
 1377           {
 1378               _expandedNodes.remove(rowIndex);
 1379           }
 1380           else
 1381           {
 1382               _expandedNodes.add(rowIndex);
 1383           }
 1384       }
 1385   
 1386       /**
 1387        * Return true if the current detail row is expanded.
 1388        *
 1389        * @return true if the current detail row is expanded.
 1390        */
 1391       public boolean isDetailExpanded()
 1392       {
 1393           Integer rowIndex = new Integer(getRowIndex());
 1394   
 1395           return _expandedNodes.contains(rowIndex);
 1396       }
 1397   
 1398       public int getSortColumnIndex()
 1399       {
 1400           if (_sortColumnIndex == -1)
 1401               _sortColumnIndex = columnNameToIndex(getSortColumn());
 1402   
 1403           return _sortColumnIndex;
 1404       }
 1405   
 1406       public void setSortColumnIndex(int sortColumnIndex)
 1407       {
 1408           _sortColumnIndex = sortColumnIndex;
 1409       }
 1410   
 1411       /**
 1412        * Set the number of columns the table will be divided over.
 1413        */
 1414       public int getNewspaperColumns()
 1415       {
 1416           return _newspaperColumns;
 1417       }
 1418   
 1419       public void setNewspaperColumns(int newspaperColumns)
 1420       {
 1421           this._newspaperColumns = newspaperColumns;
 1422       }
 1423   
 1424       /**
 1425        * Set the orientation of the newspaper columns.
 1426        */
 1427       public void setNewspaperOrientation(String newspaperOrientation)
 1428       {
 1429           this._newspaperOrientation = newspaperOrientation;
 1430       }
 1431   
 1432       public String getNewspaperOrientation()
 1433       {
 1434           return _newspaperOrientation;
 1435       }
 1436   
 1437       /**
 1438        * Gets the spacer facet, between each pair of newspaper columns.
 1439        */
 1440       public UIComponent getSpacer()
 1441       {
 1442           return (UIComponent) getFacets().get(SPACER_FACET_NAME);
 1443       }
 1444   
 1445       public void setSpacer(UIComponent spacer)
 1446       {
 1447           getFacets().put(SPACER_FACET_NAME, spacer);
 1448       }
 1449   
 1450       /**
 1451        * Expand all details
 1452        */
 1453       public void expandAllDetails()
 1454       {
 1455           int rowCount = getRowCount();
 1456   
 1457           _expandedNodes.clear();
 1458           for (int row = 0; row < rowCount; row++)
 1459           {
 1460               _expandedNodes.add(new Integer(row));
 1461           }
 1462       }
 1463   
 1464       /**
 1465        * Collapse all details
 1466        */
 1467       public void collapseAllDetails()
 1468       {
 1469           _expandedNodes.clear();
 1470       }
 1471   
 1472       /**
 1473        * @return true is any of the details is expanded
 1474        */
 1475       public boolean isExpandedEmpty()
 1476       {
 1477           boolean expandedEmpty = true;
 1478           if (_expandedNodes != null)
 1479           {
 1480               expandedEmpty = _expandedNodes.isEmpty();
 1481           }
 1482           return expandedEmpty;
 1483       }
 1484   
 1485       /**
 1486        * Clears expanded nodes set if expandedEmpty is true
 1487        *
 1488        * @param expandedEmpty
 1489        */
 1490       public void setExpandedEmpty(boolean expandedEmpty)
 1491       {
 1492           if (expandedEmpty)
 1493           {
 1494               if (_expandedNodes != null)
 1495               {
 1496                   _expandedNodes.clear();
 1497               }
 1498           }
 1499       }
 1500   
 1501       //------------------ GENERATED CODE BEGIN (do not modify!) --------------------
 1502   
 1503       public static final String COMPONENT_TYPE = "org.apache.myfaces.HtmlDataTable";
 1504       public static final String DEFAULT_RENDERER_TYPE = "org.apache.myfaces.Table";
 1505   
 1506       private static final boolean DEFAULT_PRESERVEDATAMODEL = false;
 1507       private static final boolean DEFAULT_PRESERVESORT = true;
 1508       private static final boolean DEFAULT_RENDEREDIFEMPTY = true;
 1509   
 1510       private Boolean _preserveDataModel = null;
 1511       private Boolean _preserveSort = null;
 1512       private String _enabledOnUserRole = null;
 1513       private String _visibleOnUserRole = null;
 1514       private Boolean _renderedIfEmpty = null;
 1515       private String _rowIndexVar = null;
 1516       private String _rowCountVar = null;
 1517       private String _sortedColumnVar = null;
 1518       private String _previousRowDataVar = null;
 1519   
 1520       public void setPreserveDataModel(boolean preserveDataModel)
 1521       {
 1522           _preserveDataModel = Boolean.valueOf(preserveDataModel);
 1523       }
 1524   
 1525       public boolean isPreserveDataModel()
 1526       {
 1527           if (_preserveDataModel != null)
 1528               return _preserveDataModel.booleanValue();
 1529           ValueBinding vb = getValueBinding("preserveDataModel");
 1530           Boolean v = vb != null ? (Boolean) vb.getValue(getFacesContext()) : null;
 1531           return v != null ? v.booleanValue() : DEFAULT_PRESERVEDATAMODEL;
 1532       }
 1533   
 1534       public void setPreserveSort(boolean preserveSort)
 1535       {
 1536           _preserveSort = Boolean.valueOf(preserveSort);
 1537       }
 1538   
 1539       public boolean isPreserveSort()
 1540       {
 1541           if (_preserveSort != null)
 1542               return _preserveSort.booleanValue();
 1543           ValueBinding vb = getValueBinding("preserveSort");
 1544           Boolean v = vb != null ? (Boolean) vb.getValue(getFacesContext()) : null;
 1545           return v != null ? v.booleanValue() : DEFAULT_PRESERVESORT;
 1546       }
 1547   
 1548       public void setEnabledOnUserRole(String enabledOnUserRole)
 1549       {
 1550           _enabledOnUserRole = enabledOnUserRole;
 1551       }
 1552   
 1553       public String getEnabledOnUserRole()
 1554       {
 1555           if (_enabledOnUserRole != null)
 1556               return _enabledOnUserRole;
 1557           ValueBinding vb = getValueBinding("enabledOnUserRole");
 1558           return vb != null ? (String) vb.getValue(getFacesContext()) : null;
 1559       }
 1560   
 1561       public void setVisibleOnUserRole(String visibleOnUserRole)
 1562       {
 1563           _visibleOnUserRole = visibleOnUserRole;
 1564       }
 1565   
 1566       public String getVisibleOnUserRole()
 1567       {
 1568           if (_visibleOnUserRole != null)
 1569               return _visibleOnUserRole;
 1570           ValueBinding vb = getValueBinding("visibleOnUserRole");
 1571           return vb != null ? (String) vb.getValue(getFacesContext()) : null;
 1572       }
 1573   
 1574       public void setRenderedIfEmpty(boolean renderedIfEmpty)
 1575       {
 1576           _renderedIfEmpty = Boolean.valueOf(renderedIfEmpty);
 1577       }
 1578   
 1579       public boolean isRenderedIfEmpty()
 1580       {
 1581           if (_renderedIfEmpty != null)
 1582               return _renderedIfEmpty.booleanValue();
 1583           ValueBinding vb = getValueBinding("renderedIfEmpty");
 1584           Boolean v = vb != null ? (Boolean) vb.getValue(getFacesContext()) : null;
 1585           return v != null ? v.booleanValue() : DEFAULT_RENDEREDIFEMPTY;
 1586       }
 1587   
 1588       public void setRowIndexVar(String rowIndexVar)
 1589       {
 1590           _rowIndexVar = rowIndexVar;
 1591       }
 1592   
 1593       public String getRowIndexVar()
 1594       {
 1595           if (_rowIndexVar != null)
 1596               return _rowIndexVar;
 1597           ValueBinding vb = getValueBinding("rowIndexVar");
 1598           return vb != null ? (String) vb.getValue(getFacesContext()) : null;
 1599       }
 1600   
 1601       public void setRowCountVar(String rowCountVar)
 1602       {
 1603           _rowCountVar = rowCountVar;
 1604       }
 1605   
 1606       public String getRowCountVar()
 1607       {
 1608           if (_rowCountVar != null)
 1609               return _rowCountVar;
 1610           ValueBinding vb = getValueBinding("rowCountVar");
 1611           return vb != null ? (String) vb.getValue(getFacesContext()) : null;
 1612       }
 1613   
 1614       public void setPreviousRowDataVar(String previousRowDataVar)
 1615       {
 1616           _previousRowDataVar = previousRowDataVar;
 1617       }
 1618   
 1619       public String getPreviousRowDataVar()
 1620       {
 1621           if (_previousRowDataVar != null)
 1622               return _previousRowDataVar;
 1623           ValueBinding vb = getValueBinding("previousRowDataVar");
 1624           return vb != null ? (String) vb.getValue(getFacesContext()) : null;
 1625       }
 1626   
 1627       public void setSortedColumnVar(String sortedColumnVar)
 1628       {
 1629           _sortedColumnVar = sortedColumnVar;
 1630       }
 1631   
 1632       public String getSortedColumnVar()
 1633       {
 1634           if (_sortedColumnVar != null) return _sortedColumnVar;
 1635           ValueBinding vb = getValueBinding("sortedColumnVar");
 1636           return vb != null ? (String) vb.getValue(getFacesContext()) : null;
 1637       }
 1638   
 1639       //------------------ GENERATED CODE END ---------------------------------------
 1640   }

Save This Page
Home » tomahawk-1.1.6-src » org.apache.myfaces.component.html » ext » [javadoc | source]