- Revision
- 586
- Author
- paul
- Date
- 2008-02-07 00:06:52 -0600 (Thu, 07 Feb 2008)
Log Message
words and style
Modified Paths
Diff
Modified: trunk/waffle-distribution/src/site/content/accessing-java-from-ruby.html (585 => 586)
--- trunk/waffle-distribution/src/site/content/accessing-java-from-ruby.html 2008-02-07 05:47:31 UTC (rev 585) +++ trunk/waffle-distribution/src/site/content/accessing-java-from-ruby.html 2008-02-07 06:06:52 UTC (rev 586) @@ -1,24 +1,55 @@ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> -<html><head><meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type" /> -<title>Accessing Java from Ruby</title></head> +<html><head> +<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type" /><title>Accessing Java from Ruby</title> + +</head> <body> +<h2>Access your Java components from Ruby Actions.</h2> +Here we examine Ruby based controllers, and the invoking of Java +functionaility from them. Consider:<br /> +<textarea class="java:nogutter:nocontrols" name="code"> +public class MyRegistrar extends AbstractRubyAwareRegistrar { + public MyRegistrar(Registrar delegate) { + super(delegate); + } -Waffle: How to access your Java components from your Ruby Actions.<br /><br />In -my last post I gave an overview of how you can easily integrate JRuby -with Waffle. Now we will examine Ruby based controller in a bit more -depth. Lets assume we have the following Waffle Registrar for our -application:<br /><pre>public class MyRegistrar extends AbstractRubyAwareRegistrar {<br /> public MyRegistrar(Registrar delegate) {<br /> super(delegate);<br /> }</pre><pre><br /> @Override<br /> public void application() {<br /> register("the_dao", PersonDAOImpl.class);<br /> registerRubyScript("person", "PersonController");<br /> }<br />}</pre>A -DAO, PersonDAOImpl, is registered under the name "the_dao" and we have + @Override + public void application() { + register("person_dao", PersonDAOImpl.class); + registerRubyScript("person", "PersonController"); + } +}</textarea> +A +DAO, PersonDAOImpl, is registered under the name "person_dao" and we +have one Ruby based controller available. Now its probably safe to assume -that this Ruby PersonController will need access to the DAO. Gaining +that this Ruby PersonController will need access to that DAO object. +Gaining access to this DAO from the controller is easy in Waffle, just call the -locate method:<br /><pre>class PersonController<br /> def index<br /> @person_dao = locate(example.PersonDAO)<br /> @people = @person_dao.findAll<br /> render 'person.rhtml'<br /> end<br />end</pre>Notice +locate method:<br /> +<textarea class="java:nogutter:nocontrols" name="code"> +class PersonController + def index + @person_dao = locate(example.PersonDAO) + @people = @person_dao.findAll + render 'person.rhtml' + end +end</textarea> +Notice that we were able to retrieve the DAO by its interface. Additionally, since this DAO was registered with a key you can use a convention to retrieve the component. The convention is "locate_<component -key>", here is the same controller using the locate_ convention:<br /><pre>class PersonController<br /> def index<br /> @person_dao = locate_the_dao<br /> @people = @person_dao.findAll<br /> render 'person.rhtml'<br /> end<br />end</pre>As +key>", here is the same controller using the locate_ convention:<br /> +<textarea class="java:nogutter:nocontrols" name="code">class +PersonController + def index + @person_dao = locate_person_dao + @people = @person_dao.findAll + render 'person.rhtml' + end +end</textarea> +As you can see this makes writing Ruby based Controllers/Actions with Waffle really easy. In my next post I'll detail how to access request parameter and context attributes with ease. - </body></html> \ No newline at end of file
To unsubscribe from this list please visit:
