Author: akushunin
Date: 2008-03-05 11:56:15 -0500 (Wed, 05 Mar 2008)
New Revision: 6571
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/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-05 16:48:58
UTC (rev 6570)
+++ trunk/ui/suggestionbox/src/main/config/component/suggestionbox.xml 2008-03-05 16:56:15
UTC (rev 6571)
@@ -354,7 +354,7 @@
</property>
<property>
<name>selectedObjects</name>
- <classname>java.lang.Object</classname>
+ <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-05
16:48:58 UTC (rev 6570)
+++
trunk/ui/suggestionbox/src/main/java/org/richfaces/component/UISuggestionBox.java 2008-03-05
16:56:15 UTC (rev 6571)
@@ -22,10 +22,12 @@
package org.richfaces.component;
import java.util.Collection;
+import java.util.HashMap;
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;
@@ -106,9 +108,9 @@
public abstract Object getData();
- public abstract Object getSelectedObjects();
+ public abstract ValueExpression getSelectedObjects();
- public abstract void setSelectedObjects(Object so);
+ public abstract void setSelectedObjects(ValueExpression so);
@@ -310,8 +312,8 @@
public final void broadcast(final FacesEvent event)
throws AbortProcessingException {
super.broadcast(event);
- if (event instanceof AjaxEvent) {
- FacesContext context = getFacesContext();
+ FacesContext context = getFacesContext();
+ if (event instanceof AjaxEvent) {
AjaxRendererUtils.addRegionsFromComponent(this, context);
AjaxRendererUtils.addRegionByName(context, this, this.getId());
setSubmitted(true);
@@ -320,9 +322,19 @@
.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) {
@@ -349,12 +361,20 @@
setRowNumber(Integer.parseInt(rowValue)+getFirst());
setupValue(context);
queueEvent(new SelectSuggestionEvent(this));
+
} else {
setRowNumber(-1);
}
- Object selectedObject =
requestParameterMap.get(clientId+"_hiddenFetchValue");
- setSelectedObjects(selectedObject);
- super.processDecodes(context);
+
+ 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);
}
public void setupValue(FacesContext context) {
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-05
16:48:58 UTC (rev 6570)
+++
trunk/ui/suggestionbox/src/main/java/org/richfaces/renderkit/html/SuggestionBoxRenderer.java 2008-03-05
16:56:15 UTC (rev 6571)
@@ -24,6 +24,7 @@
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;
@@ -145,7 +146,8 @@
((UISuggestionBox) component).setSubmitedValue(elementValue);
component.queueEvent(new AjaxSuggestionEvent(component,
elementValue));
- }
+ }
+
}
/**
@@ -169,15 +171,7 @@
context, component);
}
- protected void writeExplicitMarkup(ResponseWriter writer,
- UISuggestionBox suggestionBox) {
- String forAttribute = suggestionBox.getFor();
- if (forAttribute != null && forAttribute.length() > 0) {
-
- }
- }
-
/**
* Encode end.
*
@@ -285,9 +279,9 @@
suggestionBox.setupValue(context);
body.encode(getTemplateContext(context, suggestionBox));
- Object[] values = ((Collection) suggestionBox.getValue()).toArray();
- // Object hiddenFetchValue = suggestionBox.getHiddenFetchValue();
+ 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++) {
String var = (String) suggestionBox.getAttributes().get("var");
@@ -295,12 +289,15 @@
.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]);
}
+
}
- suggestionBox.setData(data);
+ suggestionBox.setData(dataToStore);
// Replace rendered area ID from component to suggestion table
suggestionBox.setRowIndex(-1);
AjaxContext ajaxContext = AjaxContext.getCurrentInstance(context);
@@ -877,4 +874,5 @@
return "dr-sb-int rich-sb-int " + entryClass + " " + rowClass;
}
+
}
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-05
16:48:58 UTC (rev 6570)
+++
trunk/ui/suggestionbox/src/test/java/org/richfaces/component/SuggestionBoxComponentTest.java 2008-03-05
16:56:15 UTC (rev 6571)
@@ -118,6 +118,12 @@
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());
}
/**