Author: alexsmirnov
Date: 2009-01-29 21:02:00 -0500 (Thu, 29 Jan 2009)
New Revision: 12502
Modified:
trunk/framework/api/src/main/java/org/ajax4jsf/context/AjaxContext.java
trunk/framework/impl/src/main/java/org/ajax4jsf/context/AjaxContextImpl.java
trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/AjaxChildrenRenderer.java
trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/AjaxRendererUtils.java
Log:
https://jira.jboss.org/jira/browse/RF-5838
Modified: trunk/framework/api/src/main/java/org/ajax4jsf/context/AjaxContext.java
===================================================================
--- trunk/framework/api/src/main/java/org/ajax4jsf/context/AjaxContext.java 2009-01-29
17:47:57 UTC (rev 12501)
+++ trunk/framework/api/src/main/java/org/ajax4jsf/context/AjaxContext.java 2009-01-30
02:02:00 UTC (rev 12502)
@@ -35,6 +35,8 @@
import org.ajax4jsf.resource.util.URLToStreamHelper;
public abstract class AjaxContext {
+
+ private boolean limitToList;
public static final String RESPONSE_DATA_KEY = "_ajax:data";
static final String SERVICE_RESOURCE = "META-INF/services/"
@@ -121,7 +123,16 @@
public abstract void setAjaxAreasToProcess(Set<String> ajaxAreasToProcess);
public abstract void setSubmittedRegionClientId(String submittedClientId);
+
+ public boolean isLimitToList() {
+ return limitToList;
+ }
+
+ public void setLimitToList(boolean limitToList) {
+ this.limitToList = limitToList;
+ }
+
/**
* Get instance of current AJAX Context. Instance get by
* variable {@link AjaxContext#AJAX_CONTEXT_KEY}
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/context/AjaxContextImpl.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/context/AjaxContextImpl.java 2009-01-29
17:47:57 UTC (rev 12501)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/context/AjaxContextImpl.java 2009-01-30
02:02:00 UTC (rev 12502)
@@ -331,6 +331,10 @@
ajaxAreasToRender.add(convertId(component, id));
}
}
+ // Is that component limit to list ?
+ if(Boolean.TRUE.equals(component.getAttributes().get("limitToList"))){
+ setLimitToList(true);
+ }
}
/**
Modified:
trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/AjaxChildrenRenderer.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/AjaxChildrenRenderer.java 2009-01-29
17:47:57 UTC (rev 12501)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/AjaxChildrenRenderer.java 2009-01-30
02:02:00 UTC (rev 12502)
@@ -33,27 +33,36 @@
import org.ajax4jsf.Messages;
import org.ajax4jsf.component.AjaxChildrenEncoder;
import org.ajax4jsf.component.AjaxOutput;
+import org.ajax4jsf.context.AjaxContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* @author shura
- *
+ *
*/
-public abstract class AjaxChildrenRenderer extends AjaxComponentRendererBase implements
AjaxRenderer {
-
+public abstract class AjaxChildrenRenderer extends AjaxComponentRendererBase
+ implements AjaxRenderer {
+
public static final Log log = LogFactory.getLog(AjaxChildrenRenderer.class);
public static final String[] SPECIAL_COMPONENTS_TYPES = {
- "org.ajax4jsf.Bundle"/*UILoadBundle.COMPONENT_TYPE*/,
"org.apache.myfaces.AliasBean",
- "org.apache.myfaces.AliasBeansScope" };
+ "org.ajax4jsf.Bundle"/* UILoadBundle.COMPONENT_TYPE */,
+ "org.apache.myfaces.AliasBean",
+ "org.apache.myfaces.AliasBeansScope" };
private static final String SPECIAL_TYPES_PARAMETER =
"org.ajax4jsf.CONTROL_COMPONENTS";
-
- /* (non-Javadoc)
- * @see
org.ajax4jsf.renderkit.AjaxRenderer#encodeAjaxChildren(javax.faces.context.FacesContext,
javax.faces.component.UIComponent, java.lang.String, java.util.Set, java.util.Set)
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.ajax4jsf.renderkit.AjaxRenderer#encodeAjaxChildren(javax.faces.context
+ * .FacesContext, javax.faces.component.UIComponent, java.lang.String,
+ * java.util.Set, java.util.Set)
*/
- public void encodeAjaxChildren(FacesContext context, UIComponent component, String path,
Set<String> ids, Set<String> renderedAreas) throws IOException {
+ public void encodeAjaxChildren(FacesContext context, UIComponent component,
+ String path, Set<String> ids, Set<String> renderedAreas)
+ throws IOException {
if (log.isDebugEnabled()) {
log.debug(Messages.getMessage(Messages.ENCODE_CHILD_AJAX_INFO,
path, component.getId()));
@@ -61,69 +70,103 @@
String currentPath = path;
if (component instanceof NamingContainer) {
currentPath += component.getId() + NamingContainer.SEPARATOR_CHAR;
+ // Do not check children if we have no id to render under naming
+ // container.
+ if (AjaxContext.getCurrentInstance(context).isLimitToList()
+ && noIdUnderPath(path, ids)) {
+ return;
+ }
}
- for (Iterator<UIComponent> it = component.getFacetsAndChildren(); it.hasNext();)
{
+ for (Iterator<UIComponent> it = component.getFacetsAndChildren(); it
+ .hasNext();) {
UIComponent element = (UIComponent) it.next();
- encodeAjaxComponent(context, element, currentPath, ids, renderedAreas);
+ encodeAjaxComponent(context, element, currentPath, ids,
+ renderedAreas);
}
}
- /* (non-Javadoc)
- * @see
org.ajax4jsf.renderkit.AjaxRenderer#encodeAjaxComponent(javax.faces.context.FacesContext,
javax.faces.component.UIComponent, java.lang.String, java.util.Set, java.util.Set)
+ private boolean noIdUnderPath(String path, Set<String> ids) {
+ // Do we have an any component for the rendering under that container ?
+ boolean noSuchId = true;
+ for (String id : ids) {
+ if (null != id && id.startsWith(path)) {
+ noSuchId = false;
+ break;
+ }
+ }
+ return noSuchId;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.ajax4jsf.renderkit.AjaxRenderer#encodeAjaxComponent(javax.faces.context
+ * .FacesContext, javax.faces.component.UIComponent, java.lang.String,
+ * java.util.Set, java.util.Set)
*/
- public void encodeAjaxComponent(FacesContext context, UIComponent component, String
currentPath, Set<String> ids, Set<String> renderedAreas) throws IOException {
- if (component.isRendered()) { // skip not-rendered components.
- boolean found = false;
- if (!ids.isEmpty()) {
- // list for rendering may contains absolute id ( best ),
- // component Id or client ID
- String elementId = component.getId();
- String absoluteId = currentPath + elementId;
- // String clientId = element.getClientId(context);
- if (ids.contains(absoluteId) || ids.contains(elementId)) {
- if (log.isDebugEnabled()) {
- log
- .debug(Messages.getMessage(
- Messages.RENDER_AJAX_AREA_INFO,
- absoluteId));
- }
- // renderChild(context, element);
- found = true;
- }
- }
- if (!found && component instanceof AjaxOutput) {
- if (((AjaxOutput) component).isAjaxRendered()) {
- // renderChild(context, element);
- found = true;
- }
-
- }
-
- if (!found) {
- if (component instanceof AjaxChildrenEncoder) {
- ((AjaxChildrenEncoder) component).encodeAjaxChild(
- context, currentPath, ids, renderedAreas);
- } else {
- // Special case - for control components, not produced
- // html code - such as message bundles loaders,
- // MyFaces aliases etc. we call encodeBegin/end methods
- // even if components not in rendered areas.
- boolean special = isSpecialElement(context, component);
- if (special) {
- component.encodeBegin(context);
- }
- encodeAjaxChildren(context, component, currentPath, ids,
- renderedAreas);
- if (special) {
- component.encodeEnd(context);
- }
-
- }
- } else {
- renderedAreas.add(component.getClientId(context));
- renderChild(context, component);
- }
- }
+ public void encodeAjaxComponent(FacesContext context,
+ UIComponent component, String currentPath, Set<String> ids,
+ Set<String> renderedAreas) throws IOException {
+ if (component.isRendered()) { // skip not-rendered components.
+ boolean found = false;
+ boolean limitToList = AjaxContext.getCurrentInstance(context).isLimitToList();
+ String elementId = component.getId();
+ String absoluteId = currentPath + elementId;
+ if (!ids.isEmpty()) {
+ // list for rendering may contains absolute id ( best ),
+ // component Id or client ID
+ // String clientId = element.getClientId(context);
+ if (ids.contains(absoluteId) || ids.contains(elementId)) {
+ if (log.isDebugEnabled()) {
+ log.debug(Messages.getMessage(
+ Messages.RENDER_AJAX_AREA_INFO, absoluteId));
+ }
+ // renderChild(context, element);
+ found = true;
+ }
+ }
+ //
+ if (!found && limitToList
+ && component instanceof NamingContainer
+ && noIdUnderPath(absoluteId
+ + NamingContainer.SEPARATOR_CHAR, ids)) {
+ return;
+ }
+ if (!found && !limitToList && component instanceof AjaxOutput) {
+ if (((AjaxOutput) component).isAjaxRendered()) {
+ // renderChild(context, element);
+ found = true;
+ }
+
+ }
+
+ if (!found) {
+ if (component instanceof AjaxChildrenEncoder
+ && (!limitToList)) {
+ ((AjaxChildrenEncoder) component).encodeAjaxChild(context,
+ currentPath, ids, renderedAreas);
+ } else {
+ // Special case - for control components, not produced
+ // html code - such as message bundles loaders,
+ // MyFaces aliases etc. we call encodeBegin/end methods
+ // even if components not in rendered areas.
+ boolean special = isSpecialElement(context, component);
+ if (special) {
+ component.encodeBegin(context);
+ }
+ encodeAjaxChildren(context, component, currentPath, ids,
+ renderedAreas);
+ if (special) {
+ component.encodeEnd(context);
+ }
+
+ }
+ } else {
+ renderedAreas.add(component.getClientId(context));
+ renderChild(context, component);
+ }
+ }
}
private Set<String> _specialComponentTypes = null;
Modified:
trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/AjaxRendererUtils.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/AjaxRendererUtils.java 2009-01-29
17:47:57 UTC (rev 12501)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/AjaxRendererUtils.java 2009-01-30
02:02:00 UTC (rev 12502)
@@ -127,8 +127,7 @@
public static final String SIMILARITY_GROUPING_ID_ATTR =
"similarityGroupingId";
/**
- * Static class - protect constructor TODO - make as subclass of chameleon
- * RendererUtils.
+ * Static class - protect constructor
*
*/
private AjaxRendererUtils() {
@@ -156,8 +155,7 @@
* @param facesContext
* @param eventName -
* name of event
- * @return <code>StringBuffer</code> with Javascript code TODO - for
- * key-based events build list of supported keys
+ * @return <code>StringBuffer</code> with Javascript code
*/
public static StringBuffer buildOnEvent(UIComponent uiComponent,
FacesContext facesContext, String eventName) {
@@ -182,8 +180,6 @@
// oncomplete - function for call after complete request.
// status - id of request status component.
// parameters - map of parameters name/value for append on request.
- // TODO
- // sync true/false - run script in sync mode.
// ..........
ajaxFunction.addParameter(buildEventOptions(facesContext, uiComponent));
@@ -288,23 +284,23 @@
options.put("parameters", parameters);
}
// parameter to render only current list of areas.
- if (isAjaxLimitToList(uiComponent)) {
- Set<? extends Object> ajaxAreas = getAjaxAreas(uiComponent);
- Set<String> areasIds = new HashSet<String>();
- if (null != ajaxAreas) {
- for (Iterator<? extends Object> iter = ajaxAreas.iterator(); iter.hasNext();)
{
- String id = (String) iter.next();
- UIComponent comp = RendererUtils.getInstance().
- findComponentFor(uiComponent, id);
- if (null != comp) {
- areasIds.add(comp.getClientId(facesContext));
- } else {
- areasIds.add(id);
- }
- }
- }
- options.put("affected", areasIds);
- }
+// if (isAjaxLimitToList(uiComponent)) {
+// Set<? extends Object> ajaxAreas = getAjaxAreas(uiComponent);
+// Set<String> areasIds = new HashSet<String>();
+// if (null != ajaxAreas) {
+// for (Iterator<? extends Object> iter = ajaxAreas.iterator(); iter.hasNext();)
{
+// String id = (String) iter.next();
+// UIComponent comp = RendererUtils.getInstance().
+// findComponentFor(uiComponent, id);
+// if (null != comp) {
+// areasIds.add(comp.getClientId(facesContext));
+// } else {
+// areasIds.add(id);
+// }
+// }
+// }
+// options.put("affected", areasIds);
+// }
String oncomplete = getAjaxOncomplete(uiComponent);
if (null != oncomplete) {
options.put(ONCOMPLETE_ATTR_NAME, buildAjaxOncomplete(oncomplete));
@@ -380,7 +376,6 @@
* @param uiComponent
* @param facesContext
* @param functionName
- * TODO
* @return
*/
public static JSFunction buildAjaxFunction(UIComponent uiComponent,
@@ -398,7 +393,6 @@
* @param uiComponent
* @param facesContext
* @param functionName
- * TODO
* @return
*/
public static JSFunction buildAjaxFunction(UIComponent uiComponent,
@@ -534,13 +528,13 @@
/**
* Convert parameter ( Collection, List, array, String, comma-separated
- * String ) to list of srings. TODO - when move to JDK 5, change to
- * List<String>
+ * String ) to list of srings.
*
* @param valueToSet -
* obect for convert to List.
* @return - list of strings.
*/
+ @SuppressWarnings("unchecked")
public static Set<String> asSet(Object valueToSet) {
if (null != valueToSet) {
@@ -894,7 +888,6 @@
ResponseWriter out = context.getResponseWriter();
// DebugUtils.traceView("ViewRoot in AJAX Page encode begin");
out.startElement("html", component);
- // TODO - html attributes. lang - from current locale ?
Locale locale = context.getViewRoot().getLocale();
out.writeAttribute(HTML.lang_ATTRIBUTE, locale.toString(), "lang");
out.startElement("body", component);