Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Tapestry Wiki" for 
change notification.

The following page has been changed by DavorHrg:
http://wiki.apache.org/tapestry/Tapestry5HowToUseTapestryHibernate

------------------------------------------------------------------------------
        
  ==== HbAction.java ====
  {{{ 
-       package org.example.hb.pages;
+ package org.example.hb.pages;
  
+ import java.util.List;
+ 
-       import org.apache.tapestry.annotations.Inject;
+ import org.apache.tapestry.annotations.Inject;
-       import org.apache.tapestry.util.TextStreamResponse;
-       import org.example.hb.entities.Hello;
+ import org.example.hb.entities.Hello;
-       import org.hibernate.Session;
+ import org.hibernate.Session;
  
-       import java.util.List;
- 
-       public class HbAction {
+ public class HbAction {
  
-           @Inject
+     @Inject
-           private Session _session;
+     private Session _session;
  
-           Object onActivate(String cmd)
-           {
-               if (cmd.equals("add")) {
+     private Hello   current;
+ 
+     public void onAction() {
-                   Hello h = new Hello();
+         Hello h = new Hello();
-                   h.setMessage("Hello World");
+         h.setMessage("Hello World");
-                   _session.save(h);
+         _session.save(h);
-                   return new TextStreamResponse("text/plain", "Added");
-               }
-               else if (cmd.equals("show")) {
-                   String ret = "";
- 
-                   List lst = _session.createCriteria(Hello.class).list();
-                   for (Object o: lst) {
-                       Hello h = (Hello) o;
-                       ret = ret + h.getMessage() + " ";
-                   }
-                 return new TextStreamResponse("text/plain", ret);
-               }
-               else {
-                   return new TextStreamResponse("text/plain", "must be either 
'add' or 'show'");
-               }       
-           }
+     }
-       }
+ 
+     public List getList() {
+         return _session.createCriteria(Hello.class).list();
+     }
+ 
+     public Hello getCurrent() {
+         return current;
+     }
+ 
+     public void setCurrent(Hello current) {
+         this.current = current;
+     }
+ 
+ }
  }}}
  
  Also add HBAction.htm in webapp/WEB-INF/
@@ -199, +196 @@

          <title>Hibernate example app</title>
      </head>
      <body>
+     <t:loop source="list" value="current">
+     ${current.message}<br/>
+     </t:loop>
+     <t:ActionLink>add</t:ActionLink>
      </body>
  </html>
  }}}     
-       Compile and deploy the application, first try this command to add a 
record:
+       Compile and deploy the application:
        
-       http://localhost:8080/HbAction/add   
+       http://localhost:8080/HbAction   
        
-       '''Note:''' depends on server setup, it might be  
http://localhost:8080/hb/HbAction/add, adjust it if needed. 
+       '''Note:''' depends on server setup, it might be  
http://localhost:8080/hb/HbAction, adjust it if needed. 
        
-       It will return: "Added" in browser, that's good, if you encounter some 
exceptions, that usually means those jar files are not properly set up, fix it 
first.
+       It will show a link "add" in browser, that's good, if you encounter 
some exceptions, that usually means those jar files are not properly set up, 
fix it first.
        
        Now, go back to IDE and look for the hibernate.cfg.xml, comment the 
line out:         
        
@@ -216, +217 @@

        
        This will avoid Hibernate to drop and re-create the tables in MySQL so 
that we can retrieve what we have just added, re-compile, re-deploy the app, 
then try this command:
        
-       http://localhost:8080/HbAction/show
+       http://localhost:8080/HbAction
        
-       you will see "Hello World" try to run the "add" command multiple times 
then run the "show" command, you will see multiple "Hello World" in the 
browser.  this ends this simple tutorial.
+       try to click "add" link multiple times, you will see multiple "Hello 
World" in the browser.  this ends this simple tutorial.
        
  === Credits: ===
        
                From a very simple 
explanation(http://tapestry.apache.org/tapestry5/tapestry-hibernate/conf.html) 
I started learning how to use Tapestry-Hibernate module, I was thinking it 
might just take a short while to learn, however it took me whole day to finally 
understand it with the helps of people in the Tapestry Forum, particularly 
Davor Hrg and Marcus Schmidke-2. After that, I came back to that simple 
explanation and wondering why it took me so long, the documentation has 
sufficiently explained the module, I believe a sample program will help in this 
learning process, with the encouragement of Davor I finally sit down and wrote 
a wiki first time in my life:) hope other newbies will find this tutorial 
informative and help them reduce the time spent, actually all informations here 
are from postings of Davor and Marcus, my job is to put them together, every 
step in this tutorial has been tested, credits go to two of them and others who 
have helped me, any mistake are mine, Than
 ks. 
        
        You can find the original discussions 
here:http://www.nabble.com/T5%3A-Hibernate-tf4409684.html#a12605784
-       
-       
+ 
+ 
+ === Few more advanced things to do ===
+ After this basic setup, we can create a very simple form (BeanEditform is 
explained at http://tapestry.apache.org/tapestry5/tutorial1/forms.html)
                                                                                
       
          
        

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to