Author: nbelaevski
Date: 2008-03-13 21:30:03 -0400 (Thu, 13 Mar 2008)
New Revision: 6799
Modified:
trunk/ui/suggestionbox/src/main/config/component/suggestionbox.xml
trunk/ui/suggestionbox/src/main/java/org/richfaces/component/UISuggestionBox.java
trunk/ui/suggestionbox/src/main/java/org/richfaces/renderkit/html/SuggestionBoxRenderer.java
trunk/ui/suggestionbox/src/main/resources/org/richfaces/renderkit/html/scripts/suggestionbox.js
trunk/ui/suggestionbox/src/test/java/org/richfaces/component/SuggestionBoxComponentTest.java
Log:
http://jira.jboss.com/jira/browse/RF-1774
Modified: trunk/ui/suggestionbox/src/main/config/component/suggestionbox.xml
===================================================================
--- trunk/ui/suggestionbox/src/main/config/component/suggestionbox.xml 2008-03-14 01:29:52
UTC (rev 6798)
+++ trunk/ui/suggestionbox/src/main/config/component/suggestionbox.xml 2008-03-14 01:30:03
UTC (rev 6799)
@@ -266,10 +266,6 @@
is set as a value
</description>
</property>
- <property>
- <name>hiddenFetchValue</name>
- <classname>java.lang.Object</classname>
- </property>
<property hidden="true">
<name>value</name>
<classname>java.lang.Object</classname>
@@ -353,9 +349,6 @@
It isn't selectable and list is closed as always after click on it and nothing is
put to input.
</description>
</property>
- <property>
- <name>selectedObjects</name>
- <classname>javax.el.ValueExpression</classname>
- </property>
+
</component>
</components>
Modified:
trunk/ui/suggestionbox/src/main/java/org/richfaces/component/UISuggestionBox.java
===================================================================
---
trunk/ui/suggestionbox/src/main/java/org/richfaces/component/UISuggestionBox.java 2008-03-14
01:29:52 UTC (rev 6798)
+++
trunk/ui/suggestionbox/src/main/java/org/richfaces/component/UISuggestionBox.java 2008-03-14
01:30:03 UTC (rev 6799)
@@ -21,13 +21,12 @@
package org.richfaces.component;
-import java.util.Collection;
-import java.util.HashMap;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Map;
import javax.el.MethodExpression;
-import javax.el.ValueExpression;
-import javax.faces.component.UIComponent;
import javax.faces.component.UIData;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
@@ -53,15 +52,43 @@
implements AjaxComponent, AjaxSource {
+ private static final class SubmittedValue implements Serializable {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 2032953038329023808L;
+
+ private Object suggestionValue;
+ private String[] requestedValues;
+
+ public SubmittedValue() {
+
+ }
+
+ public SubmittedValue(Object suggestionValue, String[] requestedValues) {
+ super();
+ this.suggestionValue = suggestionValue;
+ this.requestedValues = requestedValues;
+ }
+
+ public Object getSuggestionValue() {
+ return suggestionValue;
+ }
+
+ public String[] getRequestedValues() {
+ return requestedValues;
+ }
+ }
+
/**
* Component type.
*/
- private static final String COMPONENT_TYPE =
"org.richfaces.SuggestionBox";
+ public static final String COMPONENT_TYPE = "org.richfaces.SuggestionBox";
/**
* Component family.
*/
- private static final String COMPONENT_FAMILY =
+ public static final String COMPONENT_FAMILY =
"org.richfaces.SuggestionBox";
/**
@@ -87,6 +114,10 @@
public abstract void setSubmitedValue(Object v);
+ public void setSubmitedValue(Object suggestionValue, String[] requestedValues) {
+ setSubmitedValue(new SubmittedValue(suggestionValue, requestedValues));
+ }
+
public abstract String getFor();
/**
@@ -95,25 +126,7 @@
* @param f identifier
*/
public abstract void setFor(String f);
-
- public abstract Object getHiddenFetchValue();
- public abstract void setHiddenFetchValue(Object hfv);
-
- public abstract Object getFetchValue();
-
- public abstract void setFetchValue(Object fv);
-
- public abstract void setData(Object data);
-
- public abstract Object getData();
-
- public abstract ValueExpression getSelectedObjects();
-
- public abstract void setSelectedObjects(ValueExpression so);
-
-
-
/**
* Getter for suggestionAction.
*
@@ -295,12 +308,75 @@
public abstract void setNothingLabel(String nothingLabel);
+ public abstract Object getFetchValue();
+
+ public abstract void setFetchValue(Object value);
+
/* (non-Javadoc)
* @see javax.faces.component.UIData#broadcast(javax.faces.event.FacesEvent)
*/
private int rowNumber = -1;
+ private Object getRequestedValuesData() {
+ MethodExpression suggestingAction = getSuggestionAction();
+ SubmittedValue valueHolder = (SubmittedValue) getSubmitedValue();
+ FacesContext context = getFacesContext();
+
+ if (null != suggestingAction && valueHolder != null) {
+ String[] requestedValues = valueHolder.getRequestedValues();
+ if (requestedValues != null) {
+ int first = getFirst();
+ int rows = getRows();
+ int rowIndex = getRowIndex();
+ setFirst(0);
+ setRows(0);
+
+ List results = new ArrayList();
+ for (int i = 0; i < requestedValues.length; i++) {
+ String requestedValue = requestedValues[i];
+ if (requestedValue != null) {
+ setValue(suggestingAction.invoke(
+ context.getELContext(), new Object[]{requestedValue}));
+
+ setRowIndex(-1);
+
+ int j = 0;
+ boolean stop = false;
+
+ while (!stop) {
+ setRowIndex(j++);
+ if (isRowAvailable()) {
+ Object fetchValue = getFetchValue();
+ if (fetchValue != null) {
+ if (requestedValue.equalsIgnoreCase(fetchValue.toString())) {
+ results.add(getRowData());
+ stop = true;
+ }
+ }
+ } else {
+ results.add(null);
+ stop = true;
+ }
+ }
+ } else {
+ results.add(null);
+ }
+ }
+
+ setData(results);
+
+ setFirst(first);
+ setRows(rows);
+ setRowIndex(rowIndex);
+
+ return results;
+ }
+ }
+
+ return null;
+ }
+
public int getRowNumber() {
return rowNumber;
}
@@ -312,29 +388,23 @@
public final void broadcast(final FacesEvent event)
throws AbortProcessingException {
super.broadcast(event);
- FacesContext context = getFacesContext();
- if (event instanceof AjaxEvent) {
+ if (event instanceof AjaxEvent) {
+ FacesContext context = getFacesContext();
+ Object data = getRequestedValuesData();
+ AjaxContext ajaxContext = AjaxContext.getCurrentInstance(context);
+ if (null != data) {
+ ajaxContext.setResponseData(data);
+ }
AjaxRendererUtils.addRegionsFromComponent(this, context);
AjaxRendererUtils.addRegionByName(context, this, this.getId());
setSubmitted(true);
if (isSelfRendered()) {
- AjaxContext.getCurrentInstance(context)
- .renderSubmittedAjaxRegion(context, true);
+ ajaxContext.renderSubmittedAjaxRegion(context, true);
}
} else if (event instanceof SelectSuggestionEvent) {
- setValue(null);
+ setValue(null);
}
-
}
- private Object getElementFromMap(Object selection){
- //TODO Add more than one Object support.
- HashMap<Object, Object> data = (HashMap<Object, Object>) getData();
- if(data!=null){
- return data.get(selection);
- }else{
- return null;
- }
- }
public void queueEvent(FacesEvent event) {
if (event instanceof SelectSuggestionEvent) {
@@ -361,29 +431,20 @@
setRowNumber(Integer.parseInt(rowValue)+getFirst());
setupValue(context);
queueEvent(new SelectSuggestionEvent(this));
-
} else {
setRowNumber(-1);
}
-
- Object selectedObject =
context.getExternalContext().getRequestParameterMap().get(getClientId(context)+"_hiddenFetchValue");
- /*TODO set selected from Map to bean property or put it ot Listener.
- ValueExpression ve = getSelectedObjects();
- if(ve!=null){
- ve.setValue(context.getELContext(), getElementFromMap(selectedObject));
- setSelectedObjects(ve);
- }
- */
- super.processDecodes(context);
+ super.processDecodes(context);
}
public void setupValue(FacesContext context) {
- Object value = getSubmitedValue();
+ SubmittedValue valueHolder = (SubmittedValue) getSubmitedValue();
+ Object submittedValue = valueHolder != null ? valueHolder.getSuggestionValue() :
null;
+
MethodExpression suggestingAction = getSuggestionAction();
if (null != suggestingAction) {
setValue(suggestingAction.invoke(
- context.getELContext(), new Object[]{value}));
-
+ context.getELContext(), new Object[]{submittedValue}));
}
}
Modified:
trunk/ui/suggestionbox/src/main/java/org/richfaces/renderkit/html/SuggestionBoxRenderer.java
===================================================================
---
trunk/ui/suggestionbox/src/main/java/org/richfaces/renderkit/html/SuggestionBoxRenderer.java 2008-03-14
01:29:52 UTC (rev 6798)
+++
trunk/ui/suggestionbox/src/main/java/org/richfaces/renderkit/html/SuggestionBoxRenderer.java 2008-03-14
01:30:03 UTC (rev 6799)
@@ -23,14 +23,11 @@
import java.io.IOException;
import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
-import javax.el.ValueExpression;
import javax.faces.FacesException;
import javax.faces.component.NamingContainer;
import javax.faces.component.UIColumn;
@@ -38,7 +35,6 @@
import javax.faces.component.UIData;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
-import javax.servlet.http.HttpServlet;
import org.ajax4jsf.context.AjaxContext;
import org.ajax4jsf.javascript.JSFunction;
@@ -62,817 +58,778 @@
* Renderer for SuggestionBox component.
*/
public class SuggestionBoxRenderer extends AjaxComponentRendererBase {
- /**
- * Component options.
- */
- private static final String[] OPTIONS = { "popupClass",
"popupStyle",
- "width", "height", "entryClass",
"selectedClass", "param",
- "frequency", "minChars", "tokens", "rows",
"selectValueClass" };
+ /**
+ * Component options.
+ */
+ private static final String[] OPTIONS = {"popupClass",
"popupStyle",
+ "width", "height", "entryClass",
"selectedClass", "param",
+ "frequency", "minChars", "tokens",
"rows", "selectValueClass" };
- /**
- * Shadow depth.
- */
- public static final int SHADOW_DEPTH = 4;
+ /**
+ * Shadow depth.
+ */
+ public static final int SHADOW_DEPTH = 4;
- /**
- * Styles.
- */
- private InternetResource[] styles = { new TemplateCSSResource(
- "org/richfaces/renderkit/html/css/suggestionbox.xcss") };
+ /**
+ * Styles.
+ */
+ private InternetResource[] styles = {new TemplateCSSResource(
+ "org/richfaces/renderkit/html/css/suggestionbox.xcss")};
- /**
- * Additional scripts.
- */
- private final InternetResource[] additionalScripts = {
- new org.ajax4jsf.javascript.PrototypeScript(),
- new org.ajax4jsf.javascript.SmartPositionScript(),
- getResource("/org/richfaces/renderkit/html/scripts/browser_info.js"),
- getResource("scripts/scriptaculo.js"),
- getResource("scripts/suggestionbox.js") };
+ /**
+ * Additional scripts.
+ */
+ private final InternetResource[] additionalScripts = {
+ new org.ajax4jsf.javascript.PrototypeScript(),
+ new org.ajax4jsf.javascript.SmartPositionScript(),
+ getResource("/org/richfaces/renderkit/html/scripts/browser_info.js"),
+ getResource("scripts/scriptaculo.js"),
+ getResource("scripts/suggestionbox.js")};
- /**
- * Template for table.
- */
- private PreparedTemplate body = HtmlCompiler
- .compileResource("org/richfaces/renderkit/html/templates/table.jspx");
+ /**
+ * Template for table.
+ */
+ private PreparedTemplate body = HtmlCompiler
+ .compileResource("org/richfaces/renderkit/html/templates/table.jspx");
- /**
- * Template for popup.
- */
- private PreparedTemplate popup = HtmlCompiler
- .compileResource("org/richfaces/renderkit/html/templates/popup.jspx");
+ /**
+ * Template for popup.
+ */
+ private PreparedTemplate popup = HtmlCompiler
+ .compileResource("org/richfaces/renderkit/html/templates/popup.jspx");
- /**
- * Gets component class.
- *
- * @return component class
- */
- protected final Class getComponentClass() {
- return UISuggestionBox.class;
- }
+ /**
+ * Gets component class.
+ *
+ * @return component class
+ */
+ protected final Class getComponentClass() {
+ return UISuggestionBox.class;
+ }
- /**
- * Is render children.
- *
- * @return boolean
- */
- public final boolean getRendersChildren() {
- return true;
- }
+ /**
+ * Is render children.
+ *
+ * @return boolean
+ */
+ public final boolean getRendersChildren() {
+ return true;
+ }
- /**
- * Decode.
- *
- * @param context
- * {@link javax.faces.context.FacesContext}
- * @param component
- * {@link javax.faces.component.UIComponent}
- *
- * @see org.ajax4jsf.framework.renderer.RendererBase#doDecode(
- * javax.faces.context.FacesContext, javax.faces.component.UIComponent)
- */
- protected final void doDecode(final FacesContext context,
- final UIComponent component) {
- String clientId = component.getClientId(context);
- Map requestParameterMap = context.getExternalContext()
- .getRequestParameterMap();
- String reqValue = (String) requestParameterMap.get(clientId);
- if (reqValue != null && reqValue.equals(clientId)) {
- String paramName = (String) component.getAttributes().get("param");
- if (null == paramName) {
- paramName = "inputvalue";
- }
- Object elementValue = requestParameterMap.get(paramName);
- ((UISuggestionBox) component).setSubmitedValue(elementValue);
- component.queueEvent(new AjaxSuggestionEvent(component,
- elementValue));
- }
-
- }
+ private Pattern getTokensPattern(UIComponent component) {
+ //TODO nick - cache ?
+ String tokens = (String) component.getAttributes().get("tokens");
+ if (tokens != null && tokens.length() != 0) {
+ StringBuilder patternSource = new StringBuilder();
+ char[] array = tokens.toCharArray();
+ int l = array.length;
+ for (int i = 0; i < l; i++) {
+ if (i != 0) {
+ patternSource.append('|');
+ }
+ patternSource.append(Pattern.quote(String.valueOf(array[i])));
+ }
+
+ return Pattern.compile(patternSource.toString());
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Decode.
+ *
+ * @param context {@link javax.faces.context.FacesContext}
+ * @param component {@link javax.faces.component.UIComponent}
+ *
+ * @see org.ajax4jsf.framework.renderer.RendererBase#doDecode(
+ * javax.faces.context.FacesContext,
+ * javax.faces.component.UIComponent)
+ */
+ protected final void doDecode(final FacesContext context,
+ final UIComponent component) {
+ String clientId = component.getClientId(context);
+ Map requestParameterMap = context.getExternalContext()
+ .getRequestParameterMap();
+ String reqValue = (String) requestParameterMap.get(clientId);
+ if (reqValue != null && reqValue.equals(clientId)) {
+ String paramName = (String)
component.getAttributes().get("param");
+ if (null == paramName) {
+ paramName = "inputvalue";
+ }
+ Object elementValue = requestParameterMap.get(paramName);
+ component.queueEvent(
+ new AjaxSuggestionEvent(component, elementValue));
- /**
- * Encode begin.
- *
- * @param writer
- * {@link javax.faces.context.ResponseWriter}
- * @param context
- * {@link javax.faces.context.FacesContext}
- * @param component
- * {@link javax.faces.component.UIComponent}
- * @throws IOException
- *
- * @see {@link org.ajax4jsf.framework.renderer.RendererBase#doEncodeBegin}
- */
- protected final void doEncodeBegin(final ResponseWriter writer,
- final FacesContext context, final UIComponent component)
- throws IOException {
- super.doEncodeBegin(writer, context, component);
- org.richfaces.component.util.FormUtil.throwEnclFormReqExceptionIfNeed(
- context, component);
- }
+
+ String requestedParamName = paramName + "request";
+ String[] requestedValues = null;
+ Object requestedValuesParam = requestParameterMap.get(requestedParamName);
+
+ if (requestedValuesParam != null) {
+ String requestedString = requestedValuesParam.toString();
+ Pattern pattern = getTokensPattern(component);
+
+ if (pattern != null) {
+ requestedValues = pattern.split(requestedString);
+ } else {
+ requestedValues = new String[] {requestedString};
+ }
+ } else {
+ //TODO nick - review together with pasha
+ }
+ ((UISuggestionBox) component).setSubmitedValue(elementValue,
+ requestedValues);
+
+ }
+ }
- /**
- * Encode end.
- *
- * @param writer
- * {@link javax.faces.context.ResponseWriter}
- * @param context
- * {@link javax.faces.context.FacesContext}
- * @param component
- * {@link javax.faces.component.UIComponent}
- * @throws IOException
- *
- * @see {@link org.ajax4jsf.framework.renderer.RendererBase#doEncodeEnd}
- */
- protected void doEncodeEnd(final ResponseWriter writer,
- final FacesContext context, final UIComponent component)
- throws IOException {
- UISuggestionBox suggestionBox = (UISuggestionBox) component;
+ /**
+ * Encode begin.
+ *
+ * @param writer {@link javax.faces.context.ResponseWriter}
+ * @param context {@link javax.faces.context.FacesContext}
+ * @param component {@link javax.faces.component.UIComponent}
+ * @throws IOException
+ *
+ * @see {@link org.ajax4jsf.framework.renderer.RendererBase#doEncodeBegin}
+ */
+ protected final void doEncodeBegin(final ResponseWriter writer,
+ final FacesContext context,
+ final UIComponent component)
+ throws IOException {
+ super.doEncodeBegin(writer, context, component);
+ org.richfaces.component.util.FormUtil.throwEnclFormReqExceptionIfNeed(
+ context, component);
+ }
- if (!suggestionBox.isSubmitted()) {
- suggestionBox.setRowIndex(-1);
+ /**
+ * Encode end.
+ *
+ * @param writer {@link javax.faces.context.ResponseWriter}
+ * @param context {@link javax.faces.context.FacesContext}
+ * @param component {@link javax.faces.component.UIComponent}
+ * @throws IOException
+ *
+ * @see {@link org.ajax4jsf.framework.renderer.RendererBase#doEncodeEnd}
+ */
+ protected void doEncodeEnd(final ResponseWriter writer,
+ final FacesContext context,
+ final UIComponent component) throws IOException {
+ UISuggestionBox suggestionBox = (UISuggestionBox) component;
+ if (!suggestionBox.isSubmitted()) {
+ suggestionBox.setRowIndex(-1);
+ writer.startElement(HTML.DIV_ELEM, component);
+ getUtils().encodeId(context, component);
- writer.startElement(HTML.DIV_ELEM, component);
- getUtils().encodeId(context, component);
+ StringBuffer clazz = new StringBuffer(
+ "dr-sb-common-container rich-sb-common-container ");
+ clazz.append(suggestionBox.getPopupClass() + " ").
+ append(suggestionBox.getStyleClass());
+ writer.writeAttribute("class", clazz, "popupClass");
- StringBuffer clazz = new StringBuffer(
- "dr-sb-common-container rich-sb-common-container ");
- clazz.append(suggestionBox.getPopupClass() + " ").append(
- suggestionBox.getStyleClass());
- writer.writeAttribute("class", clazz, "popupClass");
+ int zIndex = suggestionBox.getZindex();
- int zIndex = suggestionBox.getZindex();
+ StringBuffer style = new StringBuffer("display:none; z-index: " +
(zIndex + 1) + ";");
- StringBuffer style = new StringBuffer("display:none; z-index: "
- + (zIndex + 1) + ";");
+ style.append(getSizeForStyle(component, "width", null, false));
+ style.append(getSizeForStyle(component, "height", null, false));
- style.append(getSizeForStyle(component, "width", null, false));
- style.append(getSizeForStyle(component, "height", null, false));
+ style.append(suggestionBox.getPopupStyle() + ";").
+ append(suggestionBox.getStyle() + ";");
+ writer.writeAttribute("style", style, "popupStyle");
- style.append(suggestionBox.getPopupStyle() + ";").append(
- suggestionBox.getStyle() + ";");
- writer.writeAttribute("style", style, "popupStyle");
+ UIComponent popupFacet = component.getFacet("popup");
+ if (null == popupFacet) {
+ popup.encode(this, context, component);
+ } else {
+ // Use facet as content of popup window
+ // suggestionBox.setPopup(popupFacet.getClientId(context));
+ renderChild(context, popupFacet);
+ }
+ writer.startElement(HTML.SCRIPT_ELEM, component);
+ writer.writeText(getScript(context, component), "script");
+ writer.endElement(HTML.SCRIPT_ELEM);
+ writer.endElement(HTML.DIV_ELEM);
+ writer.startElement("iframe", component);
+ writer.writeAttribute("src",
+ getResource("/org/richfaces/renderkit/html/images/spacer.gif")
+ .getUri(context, null), null);
+ writer.writeAttribute("id", component.getClientId(context)
+ + "_iframe", null);
+ writer.writeAttribute(
+ "style",
"position:absolute;display:none;z-index:" + zIndex + ";", null);
+ writer.endElement("iframe");
- UIComponent popupFacet = component.getFacet("popup");
- if (null == popupFacet) {
- popup.encode(this, context, component);
- } else {
- // Use facet as content of popup window
- // suggestionBox.setPopup(popupFacet.getClientId(context));
- renderChild(context, popupFacet);
- }
- writer.startElement(HTML.SCRIPT_ELEM, component);
- writer.writeText(getScript(context, component), "script");
- writer.endElement(HTML.SCRIPT_ELEM);
- writer.endElement(HTML.DIV_ELEM);
- writer.startElement("iframe", component);
- writer.writeAttribute("src", getResource(
- "/org/richfaces/renderkit/html/images/spacer.gif").getUri(
- context, null), null);
- writer.writeAttribute("id", component.getClientId(context)
- + "_iframe", null);
- writer.writeAttribute("style",
- "position:absolute;display:none;z-index:" + zIndex + ";",
- null);
- writer.endElement("iframe");
+ writer.startElement("input", component);
+ writer.writeAttribute("type", "hidden", null);
+ writer.writeAttribute("id", component.getClientId(context)
+ + "_selection", null);
+ writer.writeAttribute("name", component.getClientId(context)
+ + "_selection", null);
+ writer.endElement("input");
+
+ } else {
+ suggestionBox.setSubmitted(false);
+ }
- writer.startElement("input", component);
- writer.writeAttribute("type", "hidden", null);
- writer.writeAttribute("id", component.getClientId(context)
- + "_hiddenFetchValue", null);
- writer.writeAttribute("name", component.getClientId(context)
- + "_hiddenFetchValue", null);
- writer.endElement("input");
+ // Fix for bug CH-1323.
+ ((UISuggestionBox) component).setValue(null);
+ }
- writer.startElement("input", component);
- writer.writeAttribute("type", "hidden", null);
- writer.writeAttribute("id", component.getClientId(context)
- + "_selection", null);
- writer.writeAttribute("name", component.getClientId(context)
- + "_selection", null);
- writer.endElement("input");
+ /**
+ * Encode children.
+ *
+ * @param context {@link javax.faces.context.FacesContext}
+ * @param component {@link javax.faces.component.UIComponent}
+ * @throws IOException
+ *
+ * @see javax.faces.render.Renderer#encodeChildren
+ */
+ public void encodeChildren(final FacesContext context,
+ final UIComponent component)
+ throws IOException {
+ UISuggestionBox suggestionBox = (UISuggestionBox) component;
+ if (suggestionBox.isSubmitted()) {
+ suggestionBox.setupValue(context);
+ body.encode(getTemplateContext(context, suggestionBox));
+ // Replace rendered area ID from component to suggestion table
+ suggestionBox.setRowIndex(-1);
+ AjaxContext ajaxContext = AjaxContext.getCurrentInstance(context);
+ ajaxContext.removeRenderedArea(component.getClientId(context));
+ ajaxContext.addRenderedArea(getContentId(context, component));
+ }
+ }
- } else {
- suggestionBox.setSubmitted(false);
- }
+ /**
+ * Gets component.
+ *
+ * @param component {@link javax.faces.component.UIComponent}
+ * @return component
+ */
+ private UIComponent getTarget(final UIComponent component) {
+ String target = ((UISuggestionBox) component).getFor();
+ if (null != target) {
+ target = RendererUtils.getInstance().correctForIdReference(target,component);
+ // Use parent since UIData - naming container
+ UIComponent targetComponent = RendererUtils.getInstance().
+ findComponentFor(component, target);
+ if (null != targetComponent) {
+ return targetComponent;
+ } else {
+ throw new FacesException("Component for target " + target
+ + " not found in SuggestionBox " + component.getId());
+ }
+ } else {
+ throw new FacesException("Component SuggestionBox "
+ + component.getId() + " don't have property 'for'
");
+ }
+ }
- // Fix for bug CH-1323.
- ((UISuggestionBox) component).setValue(null);
- }
+ /**
+ * Gets script.
+ *
+ * @param context {@link javax.faces.context.FacesContext}
+ * @param component {@link javax.faces.component.UIComponent}
+ * @return script
+ */
+ private String getScript(final FacesContext context,
+ final UIComponent component) {
+ Map attributes = component.getAttributes();
+ StringBuffer script = new StringBuffer(" new ");
+ // Build ajax function call
+ JSFunction submitSuggest = AjaxRendererUtils.buildAjaxFunction(
+ component, context, "RichFaces.Suggestion");
+ UIComponent targetComponent = getTarget(component);
+ submitSuggest.addParameter(targetComponent.getClientId(context));
+ submitSuggest.addParameter(component.getClientId(context));
+ submitSuggest.addParameter(component.getAttributes().get("onsubmit"));
+ Map options = AjaxRendererUtils.buildEventOptions(context, component);
+ options.put("popup", component.getClientId(context));
+ for (int i = 0; i < OPTIONS.length; i++) {
+ String option = OPTIONS[i];
+ Object value = attributes.get(option);
+ if (null != value) {
+ options.put(option, value);
+ }
+ }
+ // If ajax queue name not set, put clientId
+ String eventsQueue = (String) options.get("eventsQueue");
+ if (null == eventsQueue) {
+ options.put("eventsQueue", component.getClientId(context));
+ }
+ String onselect = (String) attributes.get("onselect");
+ if (null != onselect) {
+ JSFunctionDefinition function = new JSFunctionDefinition(
+ "suggestion");
+ function.addParameter("event");
+ function.addToBody(onselect);
- /**
- * Encode children.
- *
- * @param context
- * {@link javax.faces.context.FacesContext}
- * @param component
- * {@link javax.faces.component.UIComponent}
- * @throws IOException
- *
- * @see javax.faces.render.Renderer#encodeChildren
- */
- public void encodeChildren(final FacesContext context,
- final UIComponent component) throws IOException {
- UISuggestionBox suggestionBox = (UISuggestionBox) component;
- if (suggestionBox.isSubmitted()) {
- suggestionBox.setupValue(context);
- body.encode(getTemplateContext(context, suggestionBox));
+ options.put("onselect", function);
- Object[] values = ((Collection) suggestionBox.getValue()).toArray();
- Collection data = new ArrayList();
- HashMap<Object,Object> dataToStore = new HashMap<Object,Object>();
- for (int i = 0; i < values.length; i++) {
+ }
+ if (component.getValueBinding("fetchValue") != null
+ || attributes.get("fetchValue") != null) {
+ options.put("select",
attributes.get("selectValueClass"));
+ }
- String var = (String) suggestionBox.getAttributes().get("var");
- context.getExternalContext().getRequestMap()
- .put(var, values[i]);
- if (suggestionBox.getHiddenFetchValue() != null) {
- data.add(suggestionBox.getHiddenFetchValue());
- dataToStore.put(suggestionBox.getHiddenFetchValue(), values[i]);
- } else {
- data.add(suggestionBox.getFetchValue());
- dataToStore.put(suggestionBox.getFetchValue(), values[i]);
- }
-
+ submitSuggest.addParameter(options);
+ script.append(submitSuggest.toScript()).append(";\n");
+ return script.toString();
+ }
- }
- suggestionBox.setData(dataToStore);
- // Replace rendered area ID from component to suggestion table
- suggestionBox.setRowIndex(-1);
- AjaxContext ajaxContext = AjaxContext.getCurrentInstance(context);
- ajaxContext.removeRenderedArea(component.getClientId(context));
- ajaxContext.addRenderedArea(getContentId(context, component));
- ajaxContext.getResponseDataMap().put("_ajax:data",data);
-
- }
- }
+ /**
+ * Gets template.
+ *
+ * @param context {@link javax.faces.context.FacesContext}
+ * @param data
+ * @return {@link org.ajax4jsf.framework.renderer.compiler.TemplateContext}
+ */
+ private TemplateContext getTemplateContext(final FacesContext context,
+ final UIData data) {
+ data.setRowIndex(-1);
+ return new DataTemplateContext(this, context, data);
+ }
- /**
- * Gets component.
- *
- * @param component
- * {@link javax.faces.component.UIComponent}
- * @return component
- */
- private UIComponent getTarget(final UIComponent component) {
- String target = ((UISuggestionBox) component).getFor();
- if (null != target) {
- target = RendererUtils.getInstance().correctForIdReference(target,
- component);
- // Use parent since UIData - naming container
- UIComponent targetComponent = RendererUtils.getInstance()
- .findComponentFor(component, target);
- if (null != targetComponent) {
- return targetComponent;
- } else {
- throw new FacesException("Component for target " + target
- + " not found in SuggestionBox " + component.getId());
- }
- } else {
- return component;
- }
- }
+ /**
+ * Special html templates context class with pre-defined properties for
+ * iterations over rows and columns.
+ *
+ * @author shura (latest modification by $Author: alexsmirnov $)
+ * @version $Revision: 1.20 $ $Date: 2007/03/01 22:37:49 $
+ */
+ private static class DataTemplateContext extends TemplateContext {
- /**
- * Gets script.
- *
- * @param context
- * {@link javax.faces.context.FacesContext}
- * @param component
- * {@link javax.faces.component.UIComponent}
- * @return script
- */
- private String getScript(final FacesContext context,
- final UIComponent component) {
- Map attributes = component.getAttributes();
- StringBuffer script = new StringBuffer(" new ");
- // Build ajax function call
- JSFunction submitSuggest = AjaxRendererUtils.buildAjaxFunction(
- component, context, "RichFaces.Suggestion");
- UIComponent targetComponent = getTarget(component);
- if (targetComponent.equals(component)) {
- submitSuggest.addParameter(targetComponent.getClientId(context)
- + "_input");
- } else {
- submitSuggest.addParameter(targetComponent.getClientId(context));
- }
- submitSuggest.addParameter(component.getClientId(context));
- submitSuggest.addParameter(component.getAttributes().get("onsubmit"));
- Map options = AjaxRendererUtils.buildEventOptions(context, component);
- options.put("popup", component.getClientId(context));
- for (int i = 0; i < OPTIONS.length; i++) {
- String option = OPTIONS[i];
- Object value = attributes.get(option);
- if (null != value) {
- options.put(option, value);
- }
- }
- // If ajax queue name not set, put clientId
- String eventsQueue = (String) options.get("eventsQueue");
- if (null == eventsQueue) {
- options.put("eventsQueue", component.getClientId(context));
- }
- String onselect = (String) attributes.get("onselect");
- if (null != onselect) {
- JSFunctionDefinition function = new JSFunctionDefinition(
- "suggestion");
- function.addParameter("event");
- function.addToBody(onselect);
+ private List columns;
- options.put("onselect", function);
+ private int first;
- }
- if (component.getValueBinding("fetchValue") != null
- || attributes.get("fetchValue") != null) {
- options.put("select", attributes.get("selectValueClass"));
- }
+ private int last;
- submitSuggest.addParameter(options);
- script.append(submitSuggest.toScript()).append(";\n");
- return script.toString();
- }
+ private int rows;
- /**
- * Gets template.
- *
- * @param context
- * {@link javax.faces.context.FacesContext}
- * @param data
- * @return {@link org.ajax4jsf.framework.renderer.compiler.TemplateContext}
- */
- private TemplateContext getTemplateContext(final FacesContext context,
- final UIData data) {
- data.setRowIndex(-1);
- return new DataTemplateContext(this, context, data);
- }
+ private int rowCount;
- /**
- * Special html templates context class with pre-defined properties for
- * iterations over rows and columns.
- *
- * @author shura (latest modification by $Author: alexsmirnov $)
- * @version $Revision: 1.20 $ $Date: 2007/03/01 22:37:49 $
- */
- private static class DataTemplateContext extends TemplateContext {
+ private int current;
- private List columns;
+ private String[] rowClasses = new String[0];
- private int first;
+ private String entryClass;
- private int last;
+ /**
+ * Constructor.
+ *
+ * @param renderer {@link org.ajax4jsf.framework.renderer.RendererBase}
+ * @param facesContext {@link javax.faces.context.FacesContext}
+ * @param component {@link javax.faces.component.UIComponent}
+ */
+ public DataTemplateContext(final RendererBase renderer,
+ final FacesContext facesContext,
+ final UIComponent component) {
+ super(renderer, facesContext, component);
+ if (component.getFacet("head") != null) {
+ this.putParameter("hasHead", Boolean.TRUE);
+ }
+ if (component.getFacet("head") != null) {
+ this.putParameter("hasHead", Boolean.TRUE);
+ }
+ // Fill child columns components
+ columns = new ArrayList(component.getChildCount());
+ for (Iterator iter = component.getChildren().iterator(); iter
+ .hasNext();) {
+ UIComponent column = (UIComponent) iter.next();
+ if (column instanceof UIColumn) {
+ columns.add(column);
+ if (column.getFacet("head") != null) {
+ this.putParameter("hasHead", Boolean.TRUE);
+ this.putParameter("hasColumnHead", Boolean.TRUE);
+ }
+ if (column.getFacet("footer") != null) {
+ this.putParameter("hasFooter", Boolean.TRUE);
+ this.putParameter("hasColumnFooter", Boolean.TRUE);
+ }
+ }
+ }
+ // fill rows counters
+ UISuggestionBox box = (UISuggestionBox) component;
+ this.first = box.getFirst();
+ this.rows = box.getRows();
+ this.rowCount = box.getRowCount();
+ // return all records; CH-1330
+ if (rows <= 0 || true) {
+ rows = rowCount - first;
+ }
+ last = first + rows;
+ if (last > rowCount) {
+ last = rowCount;
+ }
+ current = first;
+ // rows classes
+ entryClass = box.getEntryClass();
+ String rowClasses = box.getRowClasses();
+ if (null != rowClasses && rowClasses.length() > 0) {
+ this.rowClasses = rowClasses.split("\\s+");
+ }
- private int rows;
+ }
- private int rowCount;
+ /**
+ * Gets parameter.
+ *
+ * @param key parameter key
+ * @return parameter
+ */
+ public Object getParameter(Object key) {
+ if ("rows".equals(key)) {
+ // Iterate over rows in datatable
+ return new Iterator() {
- private int current;
+ public boolean hasNext() {
+ if (current >= last) {
+ return false;
+ }
+ UIData data = ((UIData) getComponent());
+ data.setRowIndex(current);
+ return data.isRowAvailable();
+ }
- private String[] rowClasses = new String[0];
+ public Object next() {
+ // TODO reset rows and columns classes counters
+ current++;
+ return getComponent();
+ }
- private String entryClass;
+ public void remove() {
+ throw new UnsupportedOperationException(
+ "remove row from UIData not supported");
+ }
- /**
- * Constructor.
- *
- * @param renderer
- * {@link org.ajax4jsf.framework.renderer.RendererBase}
- * @param facesContext
- * {@link javax.faces.context.FacesContext}
- * @param component
- * {@link javax.faces.component.UIComponent}
- */
- public DataTemplateContext(final RendererBase renderer,
- final FacesContext facesContext, final UIComponent component) {
- super(renderer, facesContext, component);
- if (component.getFacet("head") != null) {
- this.putParameter("hasHead", Boolean.TRUE);
- }
- if (component.getFacet("head") != null) {
- this.putParameter("hasHead", Boolean.TRUE);
- }
- // Fill child columns components
- columns = new ArrayList(component.getChildCount());
- for (Iterator iter = component.getChildren().iterator(); iter
- .hasNext();) {
- UIComponent column = (UIComponent) iter.next();
- if (column instanceof UIColumn) {
- columns.add(column);
- if (column.getFacet("head") != null) {
- this.putParameter("hasHead", Boolean.TRUE);
- this.putParameter("hasColumnHead", Boolean.TRUE);
- }
- if (column.getFacet("footer") != null) {
- this.putParameter("hasFooter", Boolean.TRUE);
- this.putParameter("hasColumnFooter", Boolean.TRUE);
- }
- }
- }
- // fill rows counters
- UISuggestionBox box = (UISuggestionBox) component;
- this.first = box.getFirst();
- this.rows = box.getRows();
- this.rowCount = box.getRowCount();
- // return all records; CH-1330
- if (rows <= 0 || true) {
- rows = rowCount - first;
- }
- last = first + rows;
- if (last > rowCount) {
- last = rowCount;
- }
- current = first;
- // rows classes
- entryClass = box.getEntryClass();
- String rowClasses = box.getRowClasses();
- if (null != rowClasses && rowClasses.length() > 0) {
- this.rowClasses = rowClasses.split("\\s+");
- }
+ };
+ } else if ("rowClass".equals(key)) {
+ // Build row class string from entryClass and row classes
+ StringBuffer rowClass = new StringBuffer();
+ if (null != entryClass) {
+ rowClass.append(entryClass);
+ if (rowClasses.length > 0) {
+ rowClass.append(" ");
+ }
+ }
+ if (rowClasses.length > 0) {
+ int currentClass = (current - first - 1)
+ % rowClasses.length;
+ if (currentClass < 0) {
+ currentClass = 0;
+ }
+ rowClass.append(rowClasses[currentClass]);
+ }
+ // for iterate over columns
+ return rowClass.toString();
+ } else if ("columns".equals(key)) {
+ // for iterate over columns
+ return columns;
+ } else if ("columnsCount".equals(key)) {
+ return new Integer(columns.size());
+ } else {
+ return super.getParameter(key);
+ }
+ }
+ }
- }
+ /**
+ * Gets opacity style.
+ *
+ * @param context {@link javax.faces.context.FacesContext}
+ * @param component {@link javax.faces.component.UIComponent}
+ * @return style
+ */
+ public final String opacityStyle(final FacesContext context,
+ final UIComponent component) {
+ String opacity = (String)
component.getAttributes().get("shadowOpacity");
+ String filterOpacity;
- /**
- * Gets parameter.
- *
- * @param key
- * parameter key
- * @return parameter
- */
- public Object getParameter(Object key) {
- if ("rows".equals(key)) {
- // Iterate over rows in datatable
- return new Iterator() {
+ if (null == opacity) {
+ Skin skin = SkinFactory.getInstance().getSkin(context);
+ opacity = (String) skin.getParameter(context, "shadowOpacity");
+ }
+ try {
+ Double op = Double.valueOf(opacity);
+ filterOpacity = Integer.toString(op.intValue() * 10);
+ opacity = Double.toString(op.doubleValue() / 10);
+ } catch (Exception e) {
+ // illegal opacity
+ return ";";
+ }
+ return "opacity:" + opacity
+ + "; filter:alpha(opacity=" + filterOpacity + ");";
+ }
- public boolean hasNext() {
- if (current >= last) {
- return false;
- }
- UIData data = ((UIData) getComponent());
- data.setRowIndex(current);
- return data.isRowAvailable();
- }
+ /**
+ * Gets border style.
+ *
+ * @param context {@link javax.faces.context.FacesContext}
+ * @param component {@link javax.faces.component.UIComponent}
+ * @return style
+ */
+ public final String border(final FacesContext context,
+ final UIComponent component) {
- public Object next() {
- // TODO reset rows and columns classes counters
- current++;
- return getComponent();
- }
+ String border = (String) component.getAttributes().get("border");
- public void remove() {
- throw new UnsupportedOperationException(
- "remove row from UIData not supported");
- }
+ String frame = (String) component.getAttributes().get("frame");
+ if (null == frame) {
+ frame = "box";
+ }
+ StringBuffer stringBuffer = new StringBuffer();
- };
- } else if ("rowClass".equals(key)) {
- // Build row class string from entryClass and row classes
- StringBuffer rowClass = new StringBuffer();
- if (null != entryClass) {
- rowClass.append(entryClass);
- if (rowClasses.length > 0) {
- rowClass.append(" ");
- }
- }
- if (rowClasses.length > 0) {
- int currentClass = (current - first - 1)
- % rowClasses.length;
- if (currentClass < 0) {
- currentClass = 0;
- }
- rowClass.append(rowClasses[currentClass]);
- }
- // for iterate over columns
- return rowClass.toString();
- } else if ("columns".equals(key)) {
- // for iterate over columns
- return columns;
- } else if ("columnsCount".equals(key)) {
- return new Integer(columns.size());
- } else {
- return super.getParameter(key);
- }
- }
- }
+ if (null != border && Pattern.matches("\\d*", border)) {
+ border += "px";
+ }
- /**
- * Gets opacity style.
- *
- * @param context
- * {@link javax.faces.context.FacesContext}
- * @param component
- * {@link javax.faces.component.UIComponent}
- * @return style
- */
- public final String opacityStyle(final FacesContext context,
- final UIComponent component) {
- String opacity = (String) component.getAttributes()
- .get("shadowOpacity");
- String filterOpacity;
+ boolean top = false, right = false, bottom = false, left = false;
+ if (frame.equalsIgnoreCase("above")) {
+ top = true;
+ // else if (frame.equalsIgnoreCase("border") |
+ // frame.equalsIgnoreCase("box")) top=right=bottom=left=true;
+ } else if (frame.equalsIgnoreCase("below")) {
+ bottom = true;
+ } else if (frame.equalsIgnoreCase("hsides")) {
+ top = true;
+ bottom = true;
+ } else if (frame.equalsIgnoreCase("lhs")) {
+ left = true;
+ } else if (frame.equalsIgnoreCase("rhs")) {
+ right = true;
+ } else if (frame.equalsIgnoreCase("vsides")) {
+ right = true;
+ left = true;
+ } else {
+ top = true;
+ right = true;
+ bottom = true;
+ left = true;
+ }
+ stringBuffer.append("; border-width:");
+ if (top) {
+ stringBuffer.append(" ").append(border).append(" ");
+ } else {
+ stringBuffer.append(" 0px ");
+ }
+ if (right) {
+ stringBuffer.append(" ").append(border).append(" ");
+ } else {
+ stringBuffer.append(" 0px ");
+ }
+ if (bottom) {
+ stringBuffer.append(" ").append(border).append(" ");
+ } else {
+ stringBuffer.append(" 0px ");
+ }
+ if (left) {
+ stringBuffer.append(" ").append(border).append(" ");
+ } else {
+ stringBuffer.append(" 0px ");
+ }
+ stringBuffer.append(";");
+ return stringBuffer.toString();
+ }
- if (null == opacity) {
- Skin skin = SkinFactory.getInstance().getSkin(context);
- opacity = (String) skin.getParameter(context, "shadowOpacity");
- }
- try {
- Double op = Double.valueOf(opacity);
- filterOpacity = Integer.toString(op.intValue() * 10);
- opacity = Double.toString(op.doubleValue() / 10);
- } catch (Exception e) {
- // illegal opacity
- return ";";
- }
- return "opacity:" + opacity + "; filter:alpha(opacity=" +
filterOpacity
- + ");";
- }
+ /**
+ * Gets background-color style.
+ *
+ * @param context {@link javax.faces.context.FacesContext}
+ * @param component {@link javax.faces.component.UIComponent}
+ * @return background-color style
+ */
+ public final String bgcolor(final FacesContext context,
+ final UIComponent component) {
+ String bgcolor = (String) component.getAttributes().get("bgcolor");
+ if (bgcolor != null) {
+ return "background-color: " + bgcolor + ";";
+ }
+ return ";";
+ }
- /**
- * Gets border style.
- *
- * @param context
- * {@link javax.faces.context.FacesContext}
- * @param component
- * {@link javax.faces.component.UIComponent}
- * @return style
- */
- public final String border(final FacesContext context,
- final UIComponent component) {
+ /**
+ * Gets cellpadding style.
+ *
+ * @param context {@link javax.faces.context.FacesContext}
+ * @param component {@link javax.faces.component.UIComponent}
+ * @return cellpadding style
+ */
+ public final String cellPadding(final FacesContext context,
+ final UIComponent component) {
+ UISuggestionBox box = (UISuggestionBox) component;
+ String cp = box.getCellpadding();
+ if (cp != null) {
+ return "padding: " + getUtils().encodePctOrPx(cp) + ";";
+ }
+ return ";";
+ }
- String border = (String) component.getAttributes().get("border");
+ /**
+ * Gets border size
+ *
+ * @param context {@link javax.faces.context.FacesContext}
+ * @param component {@link javax.faces.component.UIComponent}
+ * @return border size if set, 0 if none
+ */
+ public final String getBorder(final FacesContext context,
+ final UIComponent component) {
- String frame = (String) component.getAttributes().get("frame");
- if (null == frame) {
- frame = "box";
- }
- StringBuffer stringBuffer = new StringBuffer();
+ String border = (String) component.getAttributes().get("border");
+ if (border == null || border.length() == 0) {
+ return "0";
+ }
+
+ return border;
+ }
- if (null != border && Pattern.matches("\\d*", border)) {
- border += "px";
- }
+
+ /**
+ * Gets context identifier.
+ *
+ * @param context {@link javax.faces.context.FacesContext}
+ * @param component {@link javax.faces.component.UIComponent}
+ * @return context identifier
+ */
+ public final String getContentId(final FacesContext context,
+ final UIComponent component) {
+ return component.getClientId(context)
+ + NamingContainer.SEPARATOR_CHAR + "suggest";
+ }
- boolean top = false, right = false, bottom = false, left = false;
- if (frame.equalsIgnoreCase("above")) {
- top = true;
- // else if (frame.equalsIgnoreCase("border") |
- // frame.equalsIgnoreCase("box")) top=right=bottom=left=true;
- } else if (frame.equalsIgnoreCase("below")) {
- bottom = true;
- } else if (frame.equalsIgnoreCase("hsides")) {
- top = true;
- bottom = true;
- } else if (frame.equalsIgnoreCase("lhs")) {
- left = true;
- } else if (frame.equalsIgnoreCase("rhs")) {
- right = true;
- } else if (frame.equalsIgnoreCase("vsides")) {
- right = true;
- left = true;
- } else {
- top = true;
- right = true;
- bottom = true;
- left = true;
- }
- stringBuffer.append("; border-width:");
- if (top) {
- stringBuffer.append(" ").append(border).append(" ");
- } else {
- stringBuffer.append(" 0px ");
- }
- if (right) {
- stringBuffer.append(" ").append(border).append(" ");
- } else {
- stringBuffer.append(" 0px ");
- }
- if (bottom) {
- stringBuffer.append(" ").append(border).append(" ");
- } else {
- stringBuffer.append(" 0px ");
- }
- if (left) {
- stringBuffer.append(" ").append(border).append(" ");
- } else {
- stringBuffer.append(" 0px ");
- }
- stringBuffer.append(";");
- return stringBuffer.toString();
- }
+ /**
+ * Gets overflow sizes.
+ *
+ * @param context {@link javax.faces.context.FacesContext}
+ * @param component {@link javax.faces.component.UIComponent}
+ * @return overflow style
+ */
+ public final String overflowSize(final FacesContext context,
+ final UIComponent component) {
+ StringBuffer style = new StringBuffer();
- /**
- * Gets background-color style.
- *
- * @param context
- * {@link javax.faces.context.FacesContext}
- * @param component
- * {@link javax.faces.component.UIComponent}
- * @return background-color style
- */
- public final String bgcolor(final FacesContext context,
- final UIComponent component) {
- String bgcolor = (String) component.getAttributes().get("bgcolor");
- if (bgcolor != null) {
- return "background-color: " + bgcolor + ";";
- }
- return ";";
- }
+ style.append(getSizeForStyle(component, "width", null, true));
+ style.append(getSizeForStyle(component, "height", null, true));
- /**
- * Gets cellpadding style.
- *
- * @param context
- * {@link javax.faces.context.FacesContext}
- * @param component
- * {@link javax.faces.component.UIComponent}
- * @return cellpadding style
- */
- public final String cellPadding(final FacesContext context,
- final UIComponent component) {
- UISuggestionBox box = (UISuggestionBox) component;
- String cp = box.getCellpadding();
- if (cp != null) {
- return "padding: " + getUtils().encodePctOrPx(cp) + ";";
- }
- return ";";
- }
+ return style.toString();
+ }
- /**
- * Gets border size
- *
- * @param context
- * {@link javax.faces.context.FacesContext}
- * @param component
- * {@link javax.faces.component.UIComponent}
- * @return border size if set, 0 if none
- */
- public final String getBorder(final FacesContext context,
- final UIComponent component) {
+ /**
+ * Gets shadow style.
+ *
+ * @param context {@link javax.faces.context.FacesContext}
+ * @param component {@link javax.faces.component.UIComponent}
+ * @return shadow style
+ */
+ public final String shadowDepth(final FacesContext context,
+ final UIComponent component) {
+ String shadow = (String) component.getAttributes().get("shadowDepth");
+ if (shadow == null) {
+ shadow = Integer.toString(SHADOW_DEPTH);
+ }
- String border = (String) component.getAttributes().get("border");
- if (border == null || border.length() == 0) {
- return "0";
- }
+ return "top: " + shadow + "px; left: " + shadow +"px;
";
+ }
- return border;
- }
+ /**
+ * Gets additional scripts.
+ *
+ * @return array of resources
+ * {@link org.ajax4jsf.framework.resource.InternetResource}
+ */
+ protected final InternetResource[] getAdditionalScripts() {
+ return additionalScripts;
+ }
- /**
- * Gets context identifier.
- *
- * @param context
- * {@link javax.faces.context.FacesContext}
- * @param component
- * {@link javax.faces.component.UIComponent}
- * @return context identifier
- */
- public final String getContentId(final FacesContext context,
- final UIComponent component) {
- return component.getClientId(context) + NamingContainer.SEPARATOR_CHAR
- + "suggest";
- }
+ /**
+ * Gets styles.
+ *
+ * @return array of styles
+ * {@link org.ajax4jsf.framework.resource.InternetResource}
+ */
+ protected final InternetResource[] getStyles() {
+ return styles;
+ }
- /**
- * Gets overflow sizes.
- *
- * @param context
- * {@link javax.faces.context.FacesContext}
- * @param component
- * {@link javax.faces.component.UIComponent}
- * @return overflow style
- */
- public final String overflowSize(final FacesContext context,
- final UIComponent component) {
- StringBuffer style = new StringBuffer();
+ /**
+ * Gets style for width & height.
+ * @param component {@link javax.faces.component.UIComponent}
+ * @param attr attribute
+ * @param def default value
+ * @param isShadow TRUE if shadow exists
+ * @return style
+ */
+ private String getSizeForStyle(final UIComponent component,
+ final String attr,
+ final String def,
+ final boolean isShadow) {
+ Map attributes = component.getAttributes();
+ StringBuffer style = new StringBuffer();
- style.append(getSizeForStyle(component, "width", null, true));
- style.append(getSizeForStyle(component, "height", null, true));
+ String attribute = (String) attributes.get(attr);
+ if (attribute == null && def != null) {
+ attribute = def;
+ }
- return style.toString();
- }
+ if (attribute != null && (!attribute.equals(""))) {
+ if (isShadow) {
+ attribute = String.valueOf(Integer.parseInt(attribute)
+ - SHADOW_DEPTH);
+ }
- /**
- * Gets shadow style.
- *
- * @param context
- * {@link javax.faces.context.FacesContext}
- * @param component
- * {@link javax.faces.component.UIComponent}
- * @return shadow style
- */
- public final String shadowDepth(final FacesContext context,
- final UIComponent component) {
- String shadow = (String) component.getAttributes().get("shadowDepth");
- if (shadow == null) {
- shadow = Integer.toString(SHADOW_DEPTH);
- }
+ style.append(attr).append(":").append(attribute);
+ if (Pattern.matches("\\d*", attribute)) {
+ style.append("px");
+ }
+ style.append(";");
+ }
- return "top: " + shadow + "px; left: " + shadow + "px;
";
- }
-
- /**
- * Gets additional scripts.
- *
- * @return array of resources
- * {@link org.ajax4jsf.framework.resource.InternetResource}
- */
- protected final InternetResource[] getAdditionalScripts() {
- return additionalScripts;
- }
-
- /**
- * Gets styles.
- *
- * @return array of styles
- * {@link org.ajax4jsf.framework.resource.InternetResource}
- */
- protected final InternetResource[] getStyles() {
- return styles;
- }
-
- /**
- * Gets style for width & height.
- *
- * @param component
- * {@link javax.faces.component.UIComponent}
- * @param attr
- * attribute
- * @param def
- * default value
- * @param isShadow
- * TRUE if shadow exists
- * @return style
- */
- private String getSizeForStyle(final UIComponent component,
- final String attr, final String def, final boolean isShadow) {
- Map attributes = component.getAttributes();
- StringBuffer style = new StringBuffer();
-
- String attribute = (String) attributes.get(attr);
- if (attribute == null && def != null) {
- attribute = def;
- }
-
- if (attribute != null && (!attribute.equals(""))) {
- if (isShadow) {
- attribute = String.valueOf(Integer.parseInt(attribute)
- - SHADOW_DEPTH);
- }
-
- style.append(attr).append(":").append(attribute);
- if (Pattern.matches("\\d*", attribute)) {
- style.append("px");
- }
- style.append(";");
- }
-
- return style.toString();
- }
-
- public void insertNothingLabel(final FacesContext context,
- final UIComponent component) throws IOException {
- ResponseWriter writer = context.getResponseWriter();
- UISuggestionBox suggestionBox = (UISuggestionBox) component;
- final String startHtml = "<tr id=\""
- + suggestionBox.getClientId(context)
- + "NothingLabel\" class=\"dr-sb-int rich-sb-int "
- + suggestionBox.getRowClasses()
- + "\" style=\"display: none;\">"
- + "<td nowrap=\"nowrap\" class=\"dr-sb-cell-padding
rich-sb-cell-padding\" style=\""
- + this.cellPadding(context, component) + "\">";
- final String endHtml = "</td></tr>";
-
- UIComponent nothingLabelFacet = component.getFacet("nothingLabel");
- if (null != nothingLabelFacet && nothingLabelFacet.isRendered()) {
- writer.write(startHtml);
- renderChild(context, nothingLabelFacet);
- writer.write(endHtml);
- } else if (null != suggestionBox.getNothingLabel()
- && !"".equals(suggestionBox.getNothingLabel())) {
- writer.write(startHtml);
- writer.write(suggestionBox.getNothingLabel());
- writer.write(endHtml);
- }
-
- }
-
- /**
- * Gets 'class' attribute for suggestion entry.
- *
- * @param context
- * {@link javax.faces.context.FacesContext}
- * @param component
- * {@link javax.faces.component.UIComponent}
- * @return 'class' attribute for 'tr' element of suggestion entry.
- */
- public final String getEntryClass(final FacesContext context,
- final UIComponent component) {
- String entryClass = (String) component.getAttributes()
- .get("entryClass");
- if (null == entryClass)
- entryClass = "";
- String rowClass = (String) component.getAttributes().get("rowClasses");
- if (null == rowClass)
- rowClass = "";
-
- return "dr-sb-int rich-sb-int " + entryClass + " " + rowClass;
- }
-
+ return style.toString();
+ }
+
+ public void insertNothingLabel(final FacesContext context,
+ final UIComponent component) throws IOException {
+ ResponseWriter writer = context.getResponseWriter();
+ UISuggestionBox suggestionBox = (UISuggestionBox)component;
+ final String startHtml =
+ "<tr id=\"" + suggestionBox.getClientId(context) +
"NothingLabel\" class=\"dr-sb-int rich-sb-int " +
suggestionBox.getRowClasses() +
+ "\" style=\"display: none;\">" +
+ "<td nowrap=\"nowrap\" class=\"dr-sb-cell-padding
rich-sb-cell-padding\" style=\"" + this.cellPadding(context, component) +
"\">";
+ final String endHtml = "</td></tr>";
+
+ UIComponent nothingLabelFacet = component.getFacet("nothingLabel");
+ if(null != nothingLabelFacet && nothingLabelFacet.isRendered()) {
+ writer.write(startHtml);
+ renderChild(context, nothingLabelFacet);
+ writer.write(endHtml);
+ }
+ else if (null != suggestionBox.getNothingLabel() &&
+ !"".equals(suggestionBox.getNothingLabel())) {
+ writer.write(startHtml);
+ writer.write(suggestionBox.getNothingLabel());
+ writer.write(endHtml);
+ }
+
+ }
+
+ /**
+ * Gets 'class' attribute for suggestion entry.
+ *
+ * @param context {@link javax.faces.context.FacesContext}
+ * @param component {@link javax.faces.component.UIComponent}
+ * @return 'class' attribute for 'tr' element of suggestion entry.
+ */
+ public final String getEntryClass(final FacesContext context,
+ final UIComponent component) {
+ String entryClass = (String) component.getAttributes().get("entryClass");
+ if (null == entryClass)
+ entryClass = "";
+ String rowClass = (String) component.getAttributes().get("rowClasses");
+ if (null == rowClass)
+ rowClass = "";
+
+ return "dr-sb-int rich-sb-int " + entryClass + " " +
rowClass;
+ }
}
Modified:
trunk/ui/suggestionbox/src/main/resources/org/richfaces/renderkit/html/scripts/suggestionbox.js
===================================================================
---
trunk/ui/suggestionbox/src/main/resources/org/richfaces/renderkit/html/scripts/suggestionbox.js 2008-03-14
01:29:52 UTC (rev 6798)
+++
trunk/ui/suggestionbox/src/main/resources/org/richfaces/renderkit/html/scripts/suggestionbox.js 2008-03-14
01:30:03 UTC (rev 6799)
@@ -753,11 +753,11 @@
{
for (var i=0;i<this.selectedItems.length; i++)
{
- if (!this.selectedItems.object) list.push(this.selectedItems.text);
+ if (!this.selectedItems[i].object) list.push(this.selectedItems[i].text);
}
result = list.join(this.options.tokens[0]);
}
- else if (this.selectedItems.length!=0 && !this.selectedItems[0].object)
result = this.selectedItems.object;
+ else if (this.selectedItems.length!=0 && !this.selectedItems[0].object)
result = this.selectedItems[0].object;
return result;
},
Modified:
trunk/ui/suggestionbox/src/test/java/org/richfaces/component/SuggestionBoxComponentTest.java
===================================================================
---
trunk/ui/suggestionbox/src/test/java/org/richfaces/component/SuggestionBoxComponentTest.java 2008-03-14
01:29:52 UTC (rev 6798)
+++
trunk/ui/suggestionbox/src/test/java/org/richfaces/component/SuggestionBoxComponentTest.java 2008-03-14
01:30:03 UTC (rev 6799)
@@ -118,12 +118,6 @@
HtmlElement iframe = page.getHtmlElementById(sb.getClientId(facesContext) +
"_iframe");
assertNotNull(iframe);
assertEquals("iframe", iframe.getNodeName());
- HtmlElement input_select =
page.getHtmlElementById(sb.getClientId(facesContext)+"_selection");
- assertNotNull(input_select);
- assertSame("input", input_select.getNodeName());
- HtmlElement input_fetchValue =
page.getHtmlElementById(sb.getClientId(facesContext)+"_hiddenFetchValue");
- assertNotNull(input_fetchValue);
- assertSame("input", input_fetchValue.getNodeName());
}
/**