org.apache.myfaces.custom.datalist.AbstractHtmlDataList Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tomahawk21 Show documentation
Show all versions of tomahawk21 Show documentation
JSF components and utilities that can be used with any JSF implementation.
This library is based on the JSF1.1 version of Tomahawk, but with minor source code and build
changes to take advantage of JSF2.1 features. A JSF2.1 implementation is required to use this
version of the Tomahawk library.
The newest version!
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.myfaces.custom.datalist;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import javax.el.ValueExpression;
import javax.faces.FacesException;
import javax.faces.component.ContextCallback;
import javax.faces.component.UIComponent;
import javax.faces.component.UINamingContainer;
import javax.faces.component.visit.VisitCallback;
import javax.faces.component.visit.VisitContext;
import javax.faces.component.visit.VisitResult;
import javax.faces.context.FacesContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.myfaces.component.UserRoleAware;
/**
* Similar to dataTable, but does not render a table.
*
* Instead the layout attribute controls how each dataRow is rendered.
*
* Unless otherwise specified, all attributes accept static values or EL expressions.
*
* @JSFComponent
* name = "t:dataList"
* class = "org.apache.myfaces.custom.datalist.HtmlDataList"
* tagClass = "org.apache.myfaces.custom.datalist.HtmlDataListTag"
* @since 1.1.7
* @author Manfred Geiler (latest modification by $Author: lu4242 $)
* @version $Revision: 940152 $ $Date: 2010-05-01 21:03:39 -0500 (Sáb, 01 May 2010) $
*/
public abstract class AbstractHtmlDataList
extends org.apache.myfaces.component.html.ext.HtmlDataTableHack
implements UserRoleAware
{
public static final String COMPONENT_TYPE = "org.apache.myfaces.HtmlDataList";
private static final String DEFAULT_RENDERER_TYPE = "org.apache.myfaces.List";
private static Log log = LogFactory.getLog(AbstractHtmlDataList.class);
private static final int PROCESS_DECODES = 1;
private static final int PROCESS_VALIDATORS = 2; // not currently in use
private static final int PROCESS_UPDATES = 3; // not currently in use
private static final String SKIP_ITERATION_HINT = "javax.faces.visit.SKIP_ITERATION";
private transient FacesContext _facesContext;
/**
* Throws NullPointerException if context is null. Sets row index to -1,
* calls processChildren, sets row index to -1.
*/
public void processDecodes(FacesContext context)
{
if (context == null)
throw new NullPointerException("context");
if (!isRendered())
return;
setRowIndex(-1);
processChildren(context, PROCESS_DECODES);
setRowIndex(-1);
try
{
decode(context);
}
catch (RuntimeException e)
{
context.renderResponse();
throw e;
}
}
public void processUpdates(FacesContext context)
{
if (context == null)
throw new NullPointerException("context");
if (!isRendered())
return;
setRowIndex(-1);
processChildren(context, PROCESS_UPDATES);
setRowIndex(-1);
checkUpdateModelError(context);
}
public void processValidators(FacesContext context)
{
if (context == null)
throw new NullPointerException("context");
if (!isRendered())
return;
setRowIndex(-1);
processChildren(context, PROCESS_VALIDATORS);
setRowIndex(-1);
checkUpdateModelError(context);
}
/**
* Iterates over all children, processes each according to the specified
* process action if the child is rendered.
*/
public void processChildren(FacesContext context, int processAction)
{
// use this method for processing other than decode ?
int first = getFirst();
int rows = getRows();
int last = rows == 0 ? getRowCount() : first + rows;
if (log.isTraceEnabled())
{
log.trace("processing " + getChildCount()
+ " children: starting at " + first
+ ", ending at " + last);
}
for (int rowIndex = first; last == -1 || rowIndex < last; rowIndex++)
{
setRowIndex(rowIndex);
if (!isRowAvailable())
{
if (log.isTraceEnabled())
{
log.trace("scrolled past the last row, aborting");
}
break;
}
for (Iterator it = getChildren().iterator(); it.hasNext();)
{
UIComponent child = (UIComponent) it.next();
if (child.isRendered())
process(context, child, processAction);
}
}
}
/**
* Copy and pasted from UIData in order to maintain binary compatibility.
*/
private void process(FacesContext context, UIComponent component,
int processAction)
{
switch (processAction)
{
case PROCESS_DECODES:
component.processDecodes(context);
break;
case PROCESS_VALIDATORS:
component.processValidators(context);
break;
case PROCESS_UPDATES:
component.processUpdates(context);
break;
}
}
public void setRowIndex(int rowIndex)
{
super.setRowIndex(rowIndex);
String rowIndexVar = getRowIndexVar();
String rowCountVar = getRowCountVar();
if (rowIndexVar != null || rowCountVar != null)
{
Map requestMap = FacesContext.getCurrentInstance().getExternalContext().getRequestMap();
if (rowIndex >= 0)
{
//regular row index, update request scope variables
if (rowIndexVar != null)
{
requestMap.put(getRowIndexVar(), new Integer(rowIndex));
}
if (rowCountVar != null)
{
requestMap.put(getRowCountVar(), new Integer(getRowCount()));
}
}
else
{
//rowIndex == -1 means end of loop --> remove request scope variables
if (rowIndexVar != null)
{
requestMap.remove(getRowIndexVar());
}
if (rowCountVar != null)
{
requestMap.remove(getRowCountVar());
}
}
}
}
@Override
protected void restoreDescendantComponentStates(Object state)
{
restoreDescendantComponentStates(getChildren().iterator(), state, true);
}
@Override
protected Object saveDescendantComponentStates()
{
return saveDescendantComponentStates(getChildren().iterator(), true);
}
@Override
protected Map saveFullDescendantComponentStates(FacesContext facesContext)
{
return saveFullDescendantComponentStates(facesContext, null, getChildren().iterator(), true, getContainerClientId(facesContext));
}
@Override
protected void restoreFullDescendantComponentStates(FacesContext facesContext, Object initialState)
{
restoreFullDescendantComponentStates(facesContext, getChildren().iterator(), initialState, true);
}
@Override
protected void restoreFullDescendantComponentDeltaStates(FacesContext facesContext,
Map rowState, Object initialState)
{
restoreFullDescendantComponentDeltaStates(facesContext, getChildren().iterator(), rowState, initialState, true, getContainerClientId(facesContext));
}
@Override
protected Collection