You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by sh...@apache.org on 2006/07/15 08:10:48 UTC

svn commit: r422147 - in /myfaces/tomahawk/trunk/sandbox/core/src/main: java/org/apache/myfaces/custom/suggestajax/tablesuggestajax/TableSuggestAjaxRenderer.java resources/org/apache/myfaces/custom/suggestajax/tablesuggestajax/resource/tableSuggest.js

Author: sharathreddy
Date: Fri Jul 14 23:10:48 2006
New Revision: 422147

URL: http://svn.apache.org/viewvc?rev=422147&view=rev
Log:
When tableSuggestAjax validation fails, not only the primary field is cleared, but all the foreign-key fields must be cleared as well.

Modified:
    myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/suggestajax/tablesuggestajax/TableSuggestAjaxRenderer.java
    myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/suggestajax/tablesuggestajax/resource/tableSuggest.js

Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/suggestajax/tablesuggestajax/TableSuggestAjaxRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/suggestajax/tablesuggestajax/TableSuggestAjaxRenderer.java?rev=422147&r1=422146&r2=422147&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/suggestajax/tablesuggestajax/TableSuggestAjaxRenderer.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/suggestajax/tablesuggestajax/TableSuggestAjaxRenderer.java Fri Jul 14 23:10:48 2006
@@ -185,6 +185,8 @@
 
     private StringBuffer getEventHandlingCode(String ajaxUrl, String clientId, TableSuggestAjax tableSuggestAjax)
     {
+        FacesContext context = FacesContext.getCurrentInstance(); 
+        
         int betweenKeyUp = 0;
         int startRequest = 0;
         String charset = null;
@@ -206,10 +208,14 @@
         
         StringBuffer buf = new StringBuffer();
         String tableSuggestVar = "tableSuggest"+clientId.replace(':','_');
-
+        String fieldNames = this.getFieldNames(tableSuggestAjax, context);
+        String fieldNamesVar = tableSuggestVar + "_fieldNames";
+        
         //doing ajax request and handling the response
-        buf.append( "var " + tableSuggestVar + " = new org_apache_myfaces_TableSuggest(\""+ ajaxUrl + "\", " 
-                   + betweenKeyUp + ", " + startRequest + ", \"" + charset + "\", " + tableSuggestAjax.getAcceptValueToField().toString() + ");\n" 
+        buf.append( "var " + fieldNamesVar + " = " + fieldNames + ";\n"
+                   + "var " + tableSuggestVar + " = new org_apache_myfaces_TableSuggest(\""+ ajaxUrl + "\", " 
+                   + betweenKeyUp + ", " + startRequest + ", \"" + charset + "\", " + tableSuggestAjax.getAcceptValueToField().toString() 
+                   + ", " + fieldNamesVar + ");\n" 
                    + "dojo.event.connect(dojo.byId(\"" + clientId + "\"), \"onkeyup\", function(evt) { " 
                    + tableSuggestVar + ".decideRequest(evt); });\n"  
                    + "dojo.event.connect(dojo.byId(\"" + clientId + "\"), \"onblur\", function(evt) { " 
@@ -238,7 +244,8 @@
         UIViewRoot root = context.getViewRoot();
 
         UIComponent ajaxComp = root.findComponent(clientId);
-
+        
+        
         //checking if ajaxComp is inside a dataTable; here needed for getting the correct ids
         if (ajaxComp instanceof UIComponentPerspective)
         {
@@ -381,7 +388,7 @@
         {
             
             Object addressEntryObject = it.next();
-
+            
             context.getExternalContext().getRequestMap().put(
                     tableSuggestAjax.getVar(), addressEntryObject);
             
@@ -412,11 +419,12 @@
                     {
                         response.append("<forText>");
                         
-                        response.append(
-                                RendererUtils.getClientId(context,
-                                        tableSuggestAjax,
-                                        htmlOutputText.getFor()));
+                        String forText = RendererUtils.getClientId(context,
+                                tableSuggestAjax,
+                                htmlOutputText.getFor());
                         
+                        response.append(forText);
+                                                
                         response.append("</forText>");
                         
                         response.append("<label>");
@@ -430,11 +438,12 @@
                     {
                         response.append("<forValue>");
                         
-                        response.append(
-                                RendererUtils.getClientId(context,
-                                        tableSuggestAjax,
-                                        htmlOutputText.getForValue()));
+                        String forValue = RendererUtils.getClientId(context,
+                                tableSuggestAjax,
+                                htmlOutputText.getForValue());
                         
+                        response.append(forValue);
+                                                
                         response.append("</forValue>");
                         
                         response.append("<label>");
@@ -460,7 +469,65 @@
         context.getResponseWriter().write(response.toString());
         
     }
+    
+    //Gather the names of the the primary field as well as all
+    //the foreign-key fields in the javascript array literal format:
+    // eg. [ field1, field2, field3 ]
+    private String getFieldNames(TableSuggestAjax tableSuggestAjax,
+            FacesContext context) 
+    {
+        StringBuffer fieldNames = new StringBuffer(); 
+        fieldNames.append("[");
+        
+        if (getChildren(tableSuggestAjax) == null
+                || getChildren(tableSuggestAjax).isEmpty())
+        {
+            return null;
+        }
+            
+        Iterator columns = tableSuggestAjax.getChildren().iterator();
+        while (columns.hasNext()) 
+        {
+            UIComponent column = (UIComponent) columns.next();
+
+            Iterator columnChildren = column.getChildren().iterator(); 
+            while (columnChildren.hasNext())
+            {
+                Object component = columnChildren.next();
+                    
+                if (!(component instanceof HtmlOutputText)) 
+                {
+                    continue;
+                }
+                    
+                HtmlOutputText htmlOutputText = (HtmlOutputText) component;
+                    
+                //foreign-key field is a simple text field
+                if (htmlOutputText.getFor() != null)
+                {
 
+                    String fieldName = RendererUtils.getClientId(context,
+                            tableSuggestAjax,
+                            htmlOutputText.getFor());
+                        
+                    fieldNames.append("\"" + fieldName + "\",");                                                        
+                        
+                }
+                //foreign-key field is a combo-box field 
+                else if (htmlOutputText.getForValue() != null)
+                {
+//                    String forValue = RendererUtils.getClientId(context,
+//                            tableSuggestAjax,
+//                            htmlOutputText.getForValue());
+//                    fieldNames.add(forValue);
+                }        
+            }
+        }
+        
+        fieldNames.append("]");
+        return fieldNames.toString();
+    }   
+    
     
     
     

Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/suggestajax/tablesuggestajax/resource/tableSuggest.js
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/suggestajax/tablesuggestajax/resource/tableSuggest.js?rev=422147&r1=422146&r2=422147&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/suggestajax/tablesuggestajax/resource/tableSuggest.js (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/suggestajax/tablesuggestajax/resource/tableSuggest.js Fri Jul 14 23:10:48 2006
@@ -19,7 +19,8 @@
                                            millisBetweenKeyUps,
                                            startChars,
                                            charset,
-                                           acceptValueToField)
+                                           acceptValueToField,
+                                           fieldNames)
 {
     this.tablePagesCollection = new dojo.collections.ArrayList();
 
@@ -46,6 +47,7 @@
     this.lastKeyPressTime = new Date();
     this.millisBetweenKeyUps = millisBetweenKeyUps;
     this.scrollingRow = 0;
+    this.fieldNames = fieldNames;
 
     //puting the values from the choosen row into the fields
     org_apache_myfaces_TableSuggest.prototype.putValueToField = function(trElem)
@@ -632,8 +634,13 @@
                 if (inputValue == primaryColumn.label) return;
             }
             //clear all the fields (including foreign keys)
-            tableSuggest.inputField.value = "";
-            //tableSuggest.inputField.focus();
+            for (var i = 0; i < tableSuggest.fieldNames.length; i++)
+            {
+                var field = dojo.byId(tableSuggest.fieldNames[i]);
+                field.value = "";
+                //tableSuggest.inputField.value = "";
+                //tableSuggest.inputField.focus();
+            }
       }, 500);
 
     }