Title: [waffle-scm] [147] trunk/core/src/main/ruby: errorsContext instance now bound to each controller automatically as 'errors'.
Revision
147
Author
mward
Date
2007-06-07 17:49:47 -0500 (Thu, 07 Jun 2007)

Log Message

errorsContext instance now bound to each controller automatically as 'errors'.  Pico and Argument resolver are bound to each controller as instance variables no longer as class variables (which was wrong)

Modified Paths

Diff

Modified: trunk/core/src/main/java/org/codehaus/waffle/bind/RubyDataBinder.java (146 => 147)

--- trunk/core/src/main/java/org/codehaus/waffle/bind/RubyDataBinder.java	2007-06-07 04:32:42 UTC (rev 146)
+++ trunk/core/src/main/java/org/codehaus/waffle/bind/RubyDataBinder.java	2007-06-07 22:49:47 UTC (rev 147)
@@ -28,17 +28,20 @@
 
             JavaEmbedUtils.invokeMethod(runtime, rubyObject, "__argument_resolver=",
                     new Object[]{JavaEmbedUtils.javaToRuby(runtime, argumentResolver)},
-                    Object.class);
+                    Void.class);
 
-            JavaEmbedUtils.invokeMethod(
-                    runtime,
+            JavaEmbedUtils.invokeMethod(runtime, rubyObject, "__errors=",
+                    new Object[]{JavaEmbedUtils.javaToRuby(runtime, errorsContext)},
+                    Void.class);
+
+            JavaEmbedUtils.invokeMethod(runtime,
                     rubyObject,
                     "__set_all_contexts",
                     new Object[]{
                             JavaEmbedUtils.javaToRuby(runtime, request),
                             JavaEmbedUtils.javaToRuby(runtime, response)
                     },
-                    Object.class);
+                    Void.class);
         } else {
             // default to standard binding
             super.bind(request, response, errorsContext, controller);

Modified: trunk/core/src/main/java/org/codehaus/waffle/servlet/WaffleServlet.java (146 => 147)

--- trunk/core/src/main/java/org/codehaus/waffle/servlet/WaffleServlet.java	2007-06-07 04:32:42 UTC (rev 146)
+++ trunk/core/src/main/java/org/codehaus/waffle/servlet/WaffleServlet.java	2007-06-07 22:49:47 UTC (rev 147)
@@ -143,8 +143,6 @@
                 }
             }
 
-            // TODO ... pluggable way to register controller instance variables to the request ... no longer have to do "controller.foobar"
-            // pluggable cause we need to support ognl and ruby (get_instance_variables
             requestAttributeBinder.bind(request, controllerDefinition.getController());
             actionMethodResponseHandler.handle(request, response, actionMethodResponse);
         } catch (MethodInvocationException e) {

Modified: trunk/core/src/main/ruby/waffle.rb (146 => 147)

--- trunk/core/src/main/ruby/waffle.rb	2007-06-07 04:32:42 UTC (rev 146)
+++ trunk/core/src/main/ruby/waffle.rb	2007-06-07 22:49:47 UTC (rev 147)
@@ -72,7 +72,7 @@
   end
 
   module Controller
-    attr_reader :parameters, :request, :response, :session, :servlet_context
+    attr_reader :parameters, :request, :response, :session, :servlet_context, :errors
 
     def __set_all_contexts(request, response)
       @request = WebContext.new(request)
@@ -92,28 +92,32 @@
     end
 
     def __pico_container=(pico)
-      @@__pico_container = pico
+      @__pico_container = pico
     end
 
     def __argument_resolver=(argument_resolver)
-      @@__argument_resolver = argument_resolver
+      @__argument_resolver = argument_resolver
     end
 
+    def __errors=(errors)
+      @errors = errors
+    end
+
     def locate(type)
-      return @@__pico_container.getComponentInstanceOfType(type.java_class) if type.is_a? Module
+      return @__pico_container.getComponentInstanceOfType(type.java_class) if type.is_a? Module
 
-      return @@__pico_container.getComponentInstance(type)
+      return @__pico_container.getComponentInstance(type)
     end
 
     def method_missing(symbol, *args)
       if symbol.to_s =~ /^find_/ # todo: I don't like "find_" for this ... sounds to model-ish
         key = symbol.to_s
         key = key[5..key.length]
-        component = @@__pico_container.getComponentInstance(key)
+        component = @__pico_container.getComponentInstance(key)
 
         return component unless component.nil?
       else
-        value = @@__argument_resolver.resolve(@request.java_delegate, "{#{symbol.to_s}}")
+        value = @__argument_resolver.resolve(@request.java_delegate, "{#{symbol.to_s}}")
 
         return value unless value.nil?
       end

Modified: trunk/examples/jruby-example/src/main/ruby/ruby/foo_bar.rb (146 => 147)

--- trunk/examples/jruby-example/src/main/ruby/ruby/foo_bar.rb	2007-06-07 04:32:42 UTC (rev 146)
+++ trunk/examples/jruby-example/src/main/ruby/ruby/foo_bar.rb	2007-06-07 22:49:47 UTC (rev 147)
@@ -6,15 +6,10 @@
     render("foobar.jspx")
   end
 
-  def jake
-    session[:zoo] = "from session"
-    "go buy a mac #{zoo}"
+  def hola
+    errors # automatically resolves from params => req.attr => session.attr => application.attr
   end
 
-
-
-
-
   def ajax
     "<h1>Hello</h1>"
   end
@@ -44,7 +39,6 @@
         #{cls = Java::JavaClass.for_name('java.util.Vector')}
         #{locate(Java::JavaClass.for_name('java.util.List'))}
 
-Hello #{baz}
       }
     rescue Exception => e
       "ERROR #{e}"


To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Reply via email to