Author: amarkhel
Date: 2010-08-31 08:14:40 -0400 (Tue, 31 Aug 2010)
New Revision: 19036
Modified:
branches/autocomplete/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteDivLayoutStrategy.java
branches/autocomplete/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteEncodeStrategy.java
branches/autocomplete/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteListLayoutStrategy.java
branches/autocomplete/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteRendererBase.java
branches/autocomplete/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteTableLayoutStrategy.java
Log:
Modified:
branches/autocomplete/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteDivLayoutStrategy.java
===================================================================
---
branches/autocomplete/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteDivLayoutStrategy.java 2010-08-31
12:12:43 UTC (rev 19035)
+++
branches/autocomplete/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteDivLayoutStrategy.java 2010-08-31
12:14:40 UTC (rev 19036)
@@ -29,7 +29,6 @@
import javax.faces.context.ResponseWriter;
import org.ajax4jsf.renderkit.RendererUtils.HTML;
-import org.richfaces.component.AbstractAutocomplete;
public class AutocompleteDivLayoutStrategy extends AbstractAutocompleteLayoutStrategy
implements
AutocompleteEncodeStrategy {
@@ -46,41 +45,21 @@
ResponseWriter responseWriter = facesContext.getResponseWriter();
responseWriter.startElement(HTML.DIV_ELEM, component);
responseWriter.writeAttribute(HTML.ID_ATTRIBUTE,
getContainerElementId(facesContext, component), null);
- // responseWriter.writeAttribute(HTML.CLASS_ATTRIBUTE, "cb_list_ul",
null);
}
public void encodeItemsContainerEnd(FacesContext facesContext, UIComponent component)
throws IOException {
ResponseWriter responseWriter = facesContext.getResponseWriter();
responseWriter.endElement(HTML.DIV_ELEM);
}
-
- public void encodeItem(FacesContext facesContext, AbstractAutocomplete comboBox,
Object item) throws IOException {
+
+ public void encodeItemBegin(FacesContext facesContext, UIComponent component) throws
IOException {
+ ResponseWriter writer = facesContext.getResponseWriter();
+ writer.startElement(HTML.DIV_ELEM, component);
+ }
+
+ public void encodeItemEnd(FacesContext facesContext, UIComponent component) throws
IOException {
ResponseWriter writer = facesContext.getResponseWriter();
-
- writer.startElement(HTML.DIV_ELEM, comboBox);
- writer.writeAttribute(HTML.CLASS_ATTRIBUTE, "rf-au-option rf-au-font
rf-au-input", null);
-
- if (comboBox.getChildCount() > 0) {
- for (UIComponent child : comboBox.getChildren()) {
- child.encodeAll(facesContext);
- }
- } else {
- if (item != null) {
- // TODO nick - use converter
- String value = null;
- if (comboBox.getItemConverter() != null) {
- value = comboBox.getItemConverter().getAsString(facesContext,
comboBox, item);
- }
- if (value != null) {
- writer.writeText(value, null);
- }
- writer.writeText(item, null);
- // writer.writeText(InputUtils.getConvertedValue(facesContext, comboBox,
item), null);
- }
- }
-
writer.endElement(HTML.DIV_ELEM);
-
}
}
Modified:
branches/autocomplete/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteEncodeStrategy.java
===================================================================
---
branches/autocomplete/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteEncodeStrategy.java 2010-08-31
12:12:43 UTC (rev 19035)
+++
branches/autocomplete/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteEncodeStrategy.java 2010-08-31
12:14:40 UTC (rev 19036)
@@ -5,18 +5,18 @@
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
-import org.richfaces.component.AbstractAutocomplete;
public interface AutocompleteEncodeStrategy {
void encodeItemsContainerBegin(FacesContext facesContext, UIComponent component)
throws IOException ;
void encodeItemsContainerEnd(FacesContext facesContext, UIComponent component) throws
IOException ;
+
+ void encodeItemBegin(FacesContext facesContext, UIComponent component) throws
IOException ;
+
+ void encodeItemEnd(FacesContext facesContext, UIComponent component) throws
IOException ;
void encodeFakeItem(FacesContext facesContext, UIComponent component) throws
IOException ;
- void encodeItem(FacesContext facesContext, AbstractAutocomplete comboBox,
- Object nextItem) throws IOException;
-
- public String getContainerElementId(FacesContext facesContext, UIComponent
component);
+ String getContainerElementId(FacesContext facesContext, UIComponent component);
}
Modified:
branches/autocomplete/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteListLayoutStrategy.java
===================================================================
---
branches/autocomplete/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteListLayoutStrategy.java 2010-08-31
12:12:43 UTC (rev 19035)
+++
branches/autocomplete/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteListLayoutStrategy.java 2010-08-31
12:14:40 UTC (rev 19036)
@@ -7,7 +7,6 @@
import javax.faces.context.ResponseWriter;
import org.ajax4jsf.renderkit.RendererUtils.HTML;
-import org.richfaces.component.AbstractAutocomplete;
public class AutocompleteListLayoutStrategy extends AbstractAutocompleteLayoutStrategy
implements
AutocompleteEncodeStrategy {
@@ -31,33 +30,15 @@
ResponseWriter responseWriter = facesContext.getResponseWriter();
responseWriter.endElement(HTML.UL_ELEMENT);
}
-
- public void encodeItem(FacesContext facesContext, AbstractAutocomplete comboBox,
Object item) throws IOException {
+
+ public void encodeItemBegin(FacesContext facesContext, UIComponent component) throws
IOException {
+ ResponseWriter writer = facesContext.getResponseWriter();
+ writer.startElement(HTML.LI_ELEMENT, component);
+ }
+
+ public void encodeItemEnd(FacesContext facesContext, UIComponent component) throws
IOException {
ResponseWriter writer = facesContext.getResponseWriter();
-
- writer.startElement(HTML.LI_ELEMENT, comboBox);
- writer.writeAttribute(HTML.CLASS_ATTRIBUTE, "rf-au-option rf-au-font
rf-au-input", null);
-
- if (comboBox.getChildCount() > 0) {
- for (UIComponent child : comboBox.getChildren()) {
- child.encodeAll(facesContext);
- }
- } else {
- if (item != null) {
- // TODO nick - use converter
- String value = null;
- if (comboBox.getItemConverter() != null) {
- value = comboBox.getItemConverter().getAsString(facesContext,
comboBox, item);
- }
- if (value != null) {
- writer.writeText(value, null);
- }
- writer.writeText(item, null);
- }
- }
-
writer.endElement(HTML.LI_ELEMENT);
-
}
}
Modified:
branches/autocomplete/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteRendererBase.java
===================================================================
---
branches/autocomplete/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteRendererBase.java 2010-08-31
12:12:43 UTC (rev 19035)
+++
branches/autocomplete/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteRendererBase.java 2010-08-31
12:14:40 UTC (rev 19036)
@@ -37,6 +37,7 @@
import javax.faces.context.FacesContext;
import javax.faces.context.PartialResponseWriter;
import javax.faces.context.PartialViewContext;
+import javax.faces.context.ResponseWriter;
import javax.faces.model.ArrayDataModel;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;
@@ -47,6 +48,7 @@
import org.ajax4jsf.context.AjaxContext;
import org.ajax4jsf.javascript.ScriptUtils;
import org.ajax4jsf.renderkit.RendererUtils;
+import org.ajax4jsf.renderkit.RendererUtils.HTML;
import org.ajax4jsf.util.InputUtils;
import org.richfaces.component.AbstractAutocomplete;
import org.richfaces.component.AutocompleteLayout;
@@ -88,10 +90,12 @@
utils.addToScriptHash(options, "onerror",
attributes.get("onerror"));
utils.addToScriptHash(options, "onbeforedomupdate",
attributes.get("onbeforedomupdate"));
utils.addToScriptHash(options, "onchange",
attributes.get("onchange"));
- if (attributes.get("mode").equals("ajax")){
- utils.addToScriptHash(options, "isCachedAjax", false,
"true");
- } else if (attributes.get("mode").equals("client")) {
- utils.addToScriptHash(options, "ajaxMode", false,
"true");
+ if (attributes.get("mode") != null) {
+ if (attributes.get("mode").equals("ajax")){
+ utils.addToScriptHash(options, "isCachedAjax", false,
"true");
+ } else if (attributes.get("mode").equals("client")) {
+ utils.addToScriptHash(options, "ajaxMode", false,
"true");
+ }
}
StringBuilder builder = new StringBuilder();
builder.append(ScriptUtils.toScript(options));
@@ -185,12 +189,17 @@
Object nextItem = items.next();
setVar(facesContext, comboBox.getVar(), nextItem);
- strategy.encodeItem(facesContext, comboBox, nextItem);
+ this.encodeItem(facesContext, comboBox, nextItem, strategy);
if (comboBox.getFetchValue() != null) {
fetchValues.add(comboBox.getFetchValue());
} else {
// TODO use converter
- fetchValues.add(nextItem);
+ if (comboBox.getItemConverter() != null) {
+ fetchValues.add(comboBox.getItemConverter().getAsString(facesContext,
component, nextItem));
+ } else{
+ fetchValues.add(nextItem);
+ }
+
}
}
@@ -205,25 +214,52 @@
protected void encodeItemsContainer(FacesContext facesContext, UIComponent component)
throws IOException {
AutocompleteEncodeStrategy strategy = getStrategy(component);
- strategy.encodeItemsContainerBegin(facesContext, component);
- if (component.getAttributes().get("mode").equals("client"))
{
+ Object mode = component.getAttributes().get("mode");
+ if (mode!= null && mode.equals("client")) {
List<Object> fetchValues = new ArrayList<Object>();
this.encodeItems(facesContext, component, fetchValues);
- } else {
+ } else if (mode!= null && mode.equals("lazyClient")){
+ strategy.encodeItemsContainerBegin(facesContext, component);
+ strategy.encodeItemsContainerEnd(facesContext, component);
+ } else{
+ strategy.encodeItemsContainerBegin(facesContext, component);
strategy.encodeFakeItem(facesContext, component);
+ strategy.encodeItemsContainerEnd(facesContext, component);
}
- strategy.encodeItemsContainerEnd(facesContext, component);
}
+ public void encodeItem(FacesContext facesContext, AbstractAutocomplete comboBox,
Object item, AutocompleteEncodeStrategy strategy) throws IOException {
+ strategy.encodeItemBegin(facesContext, comboBox);
+ ResponseWriter writer = facesContext.getResponseWriter();
+
+ writer.writeAttribute(HTML.CLASS_ATTRIBUTE, "rf-au-option rf-au-font
rf-au-input", null);
+
+ if (comboBox.getChildCount() > 0) {
+ for (UIComponent child : comboBox.getChildren()) {
+ child.encodeAll(facesContext);
+ }
+ } else {
+ if (item != null) {
+ // TODO nick - use converter
+ String value = null;
+ if (comboBox.getItemConverter() != null) {
+ value = comboBox.getItemConverter().getAsString(facesContext,
comboBox, item);
+ }
+ if (value != null) {
+ writer.writeText(value, null);
+ }
+ writer.writeText(item, null);
+ }
+ }
+
+ }
+
private AutocompleteEncodeStrategy getStrategy(UIComponent component) {
AbstractAutocomplete comboBox = (AbstractAutocomplete) component;
if (comboBox.getLayout() != null) {
if (comboBox.getLayout().equals(AutocompleteLayout.div.toString())) {
return new AutocompleteDivLayoutStrategy();
}
- if (comboBox.getLayout().equals(AutocompleteLayout.grid.toString())) {
- return new AutocompleteGridLayoutStrategy();
- }
if (comboBox.getLayout().equals(AutocompleteLayout.list.toString())) {
return new AutocompleteListLayoutStrategy();
}
Modified:
branches/autocomplete/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteTableLayoutStrategy.java
===================================================================
---
branches/autocomplete/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteTableLayoutStrategy.java 2010-08-31
12:12:43 UTC (rev 19035)
+++
branches/autocomplete/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteTableLayoutStrategy.java 2010-08-31
12:14:40 UTC (rev 19036)
@@ -7,16 +7,17 @@
import javax.faces.context.ResponseWriter;
import org.ajax4jsf.renderkit.RendererUtils.HTML;
-import org.richfaces.component.AbstractAutocomplete;
public class AutocompleteTableLayoutStrategy extends AbstractAutocompleteLayoutStrategy
implements
AutocompleteEncodeStrategy {
public void encodeFakeItem(FacesContext facesContext, UIComponent component) throws
IOException {
ResponseWriter responseWriter = facesContext.getResponseWriter();
+ responseWriter.startElement(HTML.TR_ELEMENT, component);
responseWriter.startElement(HTML.TD_ELEM, component);
responseWriter.writeAttribute(HTML.STYLE_ATTRIBUTE, "display:none",
null);
responseWriter.endElement(HTML.TD_ELEM);
+ responseWriter.endElement(HTML.TR_ELEMENT);
}
@@ -25,42 +26,24 @@
responseWriter.startElement(HTML.TABLE_ELEMENT, component);
responseWriter.writeAttribute(HTML.ID_ATTRIBUTE,
getContainerElementId(facesContext, component), null);
responseWriter.startElement(HTML.TBODY_ELEMENT, component);
- // responseWriter.writeAttribute(HTML.CLASS_ATTRIBUTE, "cb_list_ul",
null);
}
public void encodeItemsContainerEnd(FacesContext facesContext, UIComponent component)
throws IOException {
ResponseWriter responseWriter = facesContext.getResponseWriter();
- responseWriter.endElement(HTML.TABLE_ELEMENT);
responseWriter.endElement(HTML.TBODY_ELEMENT);
+ responseWriter.endElement(HTML.TABLE_ELEMENT);
}
-
- public void encodeItem(FacesContext facesContext, AbstractAutocomplete comboBox,
Object item) throws IOException {
+
+ public void encodeItemBegin(FacesContext facesContext, UIComponent component) throws
IOException {
+ ResponseWriter writer = facesContext.getResponseWriter();
+ writer.startElement(HTML.TR_ELEMENT, component);
+ writer.startElement(HTML.TD_ELEM, component);
+ }
+
+ public void encodeItemEnd(FacesContext facesContext, UIComponent component) throws
IOException {
ResponseWriter writer = facesContext.getResponseWriter();
-
- writer.startElement(HTML.TD_ELEM, comboBox);
- writer.writeAttribute(HTML.CLASS_ATTRIBUTE, "rf-au-option rf-au-font
rf-au-input", null);
-
- if (comboBox.getChildCount() > 0) {
- for (UIComponent child : comboBox.getChildren()) {
- child.encodeAll(facesContext);
- }
- } else {
- if (item != null) {
- // TODO nick - use converter
- String value = null;
- if (comboBox.getItemConverter() != null) {
- value = comboBox.getItemConverter().getAsString(facesContext,
comboBox, item);
- }
- if (value != null) {
- writer.writeText(value, null);
- }
- writer.writeText(item, null);
- // writer.writeText(InputUtils.getConvertedValue(facesContext, comboBox,
item), null);
- }
- }
-
writer.endElement(HTML.TD_ELEM);
-
+ writer.endElement(HTML.TR_ELEMENT);
}
}