[richfaces-svn-commits] JBoss Rich Faces SVN: r4632 - in branches/3.1.x/ui/suggestionbox/src/main: java/org/richfaces/renderkit/html and 1 other directories.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Sat Dec 8 07:48:41 EST 2007


Author: akushunin
Date: 2007-12-08 07:48:41 -0500 (Sat, 08 Dec 2007)
New Revision: 4632

Added:
   branches/3.1.x/ui/suggestionbox/src/main/java/org/richfaces/component/SelectSuggestionEvent.java
Modified:
   branches/3.1.x/ui/suggestionbox/src/main/java/org/richfaces/component/UISuggestionBox.java
   branches/3.1.x/ui/suggestionbox/src/main/java/org/richfaces/renderkit/html/SuggestionBoxRenderer.java
   branches/3.1.x/ui/suggestionbox/src/main/resources/org/richfaces/renderkit/html/scripts/suggestionbox.js
Log:
RF-1363 branch merged with trunk RF-923

Added: branches/3.1.x/ui/suggestionbox/src/main/java/org/richfaces/component/SelectSuggestionEvent.java
===================================================================
--- branches/3.1.x/ui/suggestionbox/src/main/java/org/richfaces/component/SelectSuggestionEvent.java	                        (rev 0)
+++ branches/3.1.x/ui/suggestionbox/src/main/java/org/richfaces/component/SelectSuggestionEvent.java	2007-12-08 12:48:41 UTC (rev 4632)
@@ -0,0 +1,23 @@
+package org.richfaces.component;
+
+import javax.faces.component.UIComponent;
+import javax.faces.event.FacesEvent;
+import javax.faces.event.FacesListener;
+
+public class SelectSuggestionEvent extends FacesEvent {
+
+	private static final long serialVersionUID = 1L;
+
+	public SelectSuggestionEvent(UIComponent component) {
+		super(component);
+	}
+
+	public boolean isAppropriateListener(FacesListener listener) {
+		return false;
+	}
+
+	public void processListener(FacesListener listener) {
+		throw new UnsupportedOperationException();
+	}
+
+}


Property changes on: branches/3.1.x/ui/suggestionbox/src/main/java/org/richfaces/component/SelectSuggestionEvent.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:eol-style
   + native

Modified: branches/3.1.x/ui/suggestionbox/src/main/java/org/richfaces/component/UISuggestionBox.java
===================================================================
--- branches/3.1.x/ui/suggestionbox/src/main/java/org/richfaces/component/UISuggestionBox.java	2007-12-07 23:30:51 UTC (rev 4631)
+++ branches/3.1.x/ui/suggestionbox/src/main/java/org/richfaces/component/UISuggestionBox.java	2007-12-08 12:48:41 UTC (rev 4632)
@@ -21,12 +21,16 @@
 
 package org.richfaces.component;
 
+import java.util.Map;
+
+import javax.el.MethodExpression;
 import javax.faces.component.UIData;
 import javax.faces.context.FacesContext;
 import javax.faces.convert.Converter;
 import javax.faces.el.MethodBinding;
 import javax.faces.event.AbortProcessingException;
 import javax.faces.event.FacesEvent;
+import javax.faces.event.PhaseId;
 
 import org.ajax4jsf.component.AjaxComponent;
 import org.ajax4jsf.context.AjaxContext;
@@ -273,6 +277,17 @@
     /* (non-Javadoc)
      * @see javax.faces.component.UIData#broadcast(javax.faces.event.FacesEvent)
      */
+    
+    private int rowNumber = -1;
+    
+    public int getRowNumber() {
+		return rowNumber;
+	}
+
+	public void setRowNumber(int rowNumber) {
+		this.rowNumber = rowNumber;
+	}
+
     public final void broadcast(final FacesEvent event)
             throws AbortProcessingException {
         super.broadcast(event);
@@ -285,9 +300,50 @@
                 AjaxContext.getCurrentInstance(context)
                         .renderSubmittedAjaxRegion(context, true);
             }
+        } else if (event instanceof SelectSuggestionEvent) {
+        	setValue(null);
         }
     }
 
+    public void queueEvent(FacesEvent event) {
+    	if (event instanceof SelectSuggestionEvent) {
+    		event.setPhaseId(PhaseId.RENDER_RESPONSE);
+			super.queueEvent(event);
+    	} else if (event.getComponent() != this && rowNumber != -1) {
+			int prevIndex = getRowIndex();
+			setRowIndex(rowNumber);
+			super.queueEvent(event);
+			setRowIndex(prevIndex);
+		} else {
+			super.queueEvent(event);
+		}
+		
+	}
+
+	public void processDecodes(FacesContext context) {
+		if (!this.isRendered())
+			return;
+		Map requestParameterMap = context.getExternalContext().getRequestParameterMap();
+        String clientId = getClientId(context);
+        String rowValue = (String)requestParameterMap.get(clientId+"_selection");
+        if (rowValue != null && rowValue.length()!=0) {
+        	setRowNumber(Integer.parseInt(rowValue)+getFirst());
+            setupValue(context);
+            queueEvent(new SelectSuggestionEvent(this));
+        } else {
+        	setRowNumber(-1);
+        }
+		super.processDecodes(context);
+	}
+
+	public void setupValue(FacesContext context) {
+		Object value = getSubmitedValue();
+		MethodBinding suggestingAction = getSuggestionAction();
+		if (null != suggestingAction) {
+		    setValue(suggestingAction.invoke(context, new Object[]{value}));
+        }
+    }
+
     public void addAjaxListener(final AjaxListener listener) {
         addFacesListener(listener);
     }

Modified: branches/3.1.x/ui/suggestionbox/src/main/java/org/richfaces/renderkit/html/SuggestionBoxRenderer.java
===================================================================
--- branches/3.1.x/ui/suggestionbox/src/main/java/org/richfaces/renderkit/html/SuggestionBoxRenderer.java	2007-12-07 23:30:51 UTC (rev 4631)
+++ branches/3.1.x/ui/suggestionbox/src/main/java/org/richfaces/renderkit/html/SuggestionBoxRenderer.java	2007-12-08 12:48:41 UTC (rev 4632)
@@ -221,6 +221,15 @@
             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);
         }
@@ -243,13 +252,7 @@
             throws IOException {
         UISuggestionBox suggestionBox = (UISuggestionBox) component;
         if (suggestionBox.isSubmitted()) {
-            Object value = suggestionBox.getSubmitedValue();
-            MethodBinding suggestingAction = suggestionBox.getSuggestionAction();
-            if (null != suggestingAction) {
-                // TODO - use converter
-                suggestionBox.setValue(suggestingAction.invoke(
-                        context, new Object[]{value}));
-            }
+            suggestionBox.setupValue(context);
             body.encode(getTemplateContext(context, suggestionBox));
             // Replace rendered area ID from component to suggestion table
             suggestionBox.setRowIndex(-1);

Modified: branches/3.1.x/ui/suggestionbox/src/main/resources/org/richfaces/renderkit/html/scripts/suggestionbox.js
===================================================================
--- branches/3.1.x/ui/suggestionbox/src/main/resources/org/richfaces/renderkit/html/scripts/suggestionbox.js	2007-12-07 23:30:51 UTC (rev 4631)
+++ branches/3.1.x/ui/suggestionbox/src/main/resources/org/richfaces/renderkit/html/scripts/suggestionbox.js	2007-12-08 12:48:41 UTC (rev 4632)
@@ -16,7 +16,7 @@
         this.keyEvent = false;
         this.oldValue = this.element.value;
         this.skipHover = false;
-
+		options.selection = update + "_selection";
         var needIframe = (RichFaces.navigatorType() == "MSIE");
 
         if (needIframe) {
@@ -546,6 +546,10 @@
 
     selectEntry: function(event) {
         this.active = false;
+		
+		var input = $(this.options.selection);
+		input.value = this.index;
+        
         this.updateElement(this.getCurrentEntry());
         if (this.options.onselect) {
             this.options.onselect(this, event);
@@ -553,6 +557,7 @@
         if (this.update.onselect) {
             this.update.onselect(this, event);
         }
+		input.value = "";
     },
 
     updateElement: function(selectedElement) {
@@ -699,7 +704,7 @@
         this.actionUrl = actionUrl;
 
         if (onsubmit && onsubmit != 'null'){
-			this.onsubmitFunction = new Function(onsubmit).bind(this.element);
+			this.onsubmitFunction = new Function(onsubmit+';return true;').bind(this.element);
 		}
 
         return this;




More information about the richfaces-svn-commits mailing list