mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
- Introduction of the component generator framework
- Changed some confg attrbiute names for consistency git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2634 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
package org.alfresco.web.app.servlet;
|
||||
|
||||
import javax.faces.FactoryFinder;
|
||||
import javax.faces.component.UIComponent;
|
||||
import javax.faces.component.UIViewRoot;
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.faces.context.FacesContextFactory;
|
||||
@@ -30,11 +31,19 @@ import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.web.bean.generator.IComponentGenerator;
|
||||
import org.alfresco.web.ui.repo.RepoConstants;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
/**
|
||||
* @author Kevin Roast
|
||||
*/
|
||||
public final class FacesHelper
|
||||
{
|
||||
private static Log logger = LogFactory.getLog(FacesHelper.class);
|
||||
|
||||
/**
|
||||
* Private constructor
|
||||
*/
|
||||
@@ -118,6 +127,91 @@ public final class FacesHelper
|
||||
return vb.getValue(fc);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up the id for the given component, if the id is null a unique one
|
||||
* is generated using the standard Faces algorithm. If an id is present it
|
||||
* is checked for illegal characters.
|
||||
*
|
||||
* @param context FacesContext
|
||||
* @param component The component to set the id for
|
||||
* @param id The id to set
|
||||
*/
|
||||
public static void setupComponentId(FacesContext context, UIComponent component, String id)
|
||||
{
|
||||
if (id == null)
|
||||
{
|
||||
id = context.getViewRoot().createUniqueId();
|
||||
}
|
||||
else
|
||||
{
|
||||
// make sure we do not have illegal characters in the id
|
||||
id = id.replace(':', '_');
|
||||
|
||||
// TODO: check all other illegal characters - only allowed dash and underscore
|
||||
}
|
||||
|
||||
component.setId(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the named component generator implementation.
|
||||
* If the named generator is not found the TextFieldGenerator is looked up
|
||||
* as a default, if this is also not found an AlfrescoRuntimeException is thrown.
|
||||
*
|
||||
* @param context FacesContext
|
||||
* @param generator The name of the component generator to retrieve
|
||||
* @return The component generator instance
|
||||
*/
|
||||
public static IComponentGenerator getComponentGenerator(FacesContext context, String generatorName)
|
||||
{
|
||||
IComponentGenerator generator = lookupComponentGenerator(context, generatorName);
|
||||
|
||||
if (generator == null)
|
||||
{
|
||||
// create a text field if we can't find a component generator (a warning should have already been
|
||||
// displayed on the appserver console)
|
||||
|
||||
logger.warn("Attempting to find default component generator '" + RepoConstants.GENERATOR_TEXT_FIELD + "'");
|
||||
generator = lookupComponentGenerator(context, RepoConstants.GENERATOR_TEXT_FIELD);
|
||||
}
|
||||
|
||||
// if we still don't have a component generator we should abort as vital configuration is missing
|
||||
if (generator == null)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("Failed to find a component generator, please ensure the '" +
|
||||
RepoConstants.GENERATOR_TEXT_FIELD + "' bean is present in your configuration");
|
||||
}
|
||||
|
||||
return generator;
|
||||
}
|
||||
|
||||
private static IComponentGenerator lookupComponentGenerator(FacesContext context, String generatorName)
|
||||
{
|
||||
IComponentGenerator generator = null;
|
||||
|
||||
Object obj = FacesHelper.getManagedBean(context, generatorName);
|
||||
if (obj != null)
|
||||
{
|
||||
if (obj instanceof IComponentGenerator)
|
||||
{
|
||||
generator = (IComponentGenerator)obj;
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Found component generator for '" + generatorName + "': " + generator);
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.warn("Bean '" + generatorName + "' does not implement IComponentGenerator");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.warn("Failed to find component generator with name of '" + generatorName + "'");
|
||||
}
|
||||
|
||||
return generator;
|
||||
}
|
||||
|
||||
/**
|
||||
* We need an inner class to be able to call FacesContext.setCurrentInstance
|
||||
* since it's a protected method
|
||||
|
Reference in New Issue
Block a user