[Logo] Mentawai Forum - Mentawai Web Framework
  [Search] Search   [Recent Topics] Recent Topics   [Members]  Member Listing   [Groups] Back to home page 
[Register] Register / 
[Login] Login 

Forum Read-Only! Check the new site and forum here!

23) Como obter paginação em um grid usando Paginator e MentaAjax  XML
Forum Index -> F.A.Q.
Author Message
Lobo


[Avatar]

Joined: 23/01/2006 02:17:14
Messages: 840
Location: Fortaleza-CE
Offline

ApplicationManager

Code:
 import java.sql.Connection;
 
 import org.apache.commons.dbcp.BasicDataSource;
 import org.mentawai.bean.DBTypes;
 import org.mentawai.bean.jdbc.H2BeanSession;
 import org.mentawai.core.Context;
 import org.mentawai.db.ConnectionHandler;
 import org.mentawai.db.DBCPConnectionHandler;
 import org.mentawai.filter.ConnectionFilter;
 import org.mentawai.filter.DIFilter;
 import org.mentawai.filter.InjectionFilter;
 import org.mentawai.filter.IoCFilter;
 
 import examples.action.CityAction;
 import examples.bean.City;
 
 
 public class ApplicationManager extends org.mentawai.core.ApplicationManager {
 	
 	private ConnectionHandler connHandler;
     
     public void init(Context application) {
     	setDebugMode(true, true);
     	this.connHandler = new DBCPConnectionHandler("org.h2.Driver","jdbc:h2:test","sa","");
     	BasicDataSource ds = (BasicDataSource) ((DBCPConnectionHandler) connHandler)
     	.getBasicDataSource();
     	ds.setInitialSize(5);
     	ds.setMaxIdle(5);
     	ds.setMaxActive(20);
     }
     
     public void loadBeans() {
     	bean(City.class, "City")
   		.field("id","id",DBTypes.AUTOINCREMENT, true)
   		.field("name", DBTypes.STRING);
    	}
     
 	public void loadActions() {
 		filter(new IoCFilter());
 		ioc("beanSession", H2BeanSession.class);
 		filter(new InjectionFilter());
 		filter(new ConnectionFilter("connection", connHandler));
 		filter(new DIFilter());
         di("connection", Connection.class); 
         
            action(CityAction.class).fwdOk("/city.jsp");
         
           action(CityAction.class, "loadAll") .fwdOk("/city_list.jsp");
         
    }
 }
 


JSP city.jsp feature mentaAjax
Code:
 <%@ taglib uri="/WEB-INF/mentawai.tld" prefix="mtw" %>
 <html>
 <head>
     <title>GridPaging</title>
     <mtw:ajaxConfig />
 	<script type="text/javascript">
  	function find(pg) {
  	    var req = new mtw.request();
               req.setUrl("CityAction.loadAll.mtw");
             req.onSuccess(function(trans) {
                var res = new mtw.response(trans);
                   $("grid").innerHTML = res.getString();
             });
                req.addParameter("page", pg);
  	    req.send();
  	}
 	</script>
 </head>
 <body>
 <a href="#" onclick="find(1);">Show !</a>
   <div id="grid">  </div>
 </body>
 </html>
 


JSP secundário city_list.jsp feature paginator
Code:
 <%@ taglib uri="/WEB-INF/mentawai.tld" prefix="mtw" %>
 <table border="1" width="400">
 <tr>
 <td align="right" colspan="2">
 <mtw:paginator size="5" value="list">
     <mtw:isEmpty negate="true">
 	    Results <mtw:resultFrom /> - <mtw:resultTo /> of about <mtw:resultTotal /><br />
     </mtw:isEmpty>
     <mtw:hasPrevious>
 	      
          <a href="#" onclick="find(<mtw:out />);"><strong>Previous</strong></a>  
     </mtw:hasPrevious>
     <mtw:pageNumbers pagesToShow="2">
         <mtw:isCurrPage><mtw:out /></mtw:isCurrPage>
         <mtw:isCurrPage negate="true">
               
             <a href="#" onclick=find(<mtw:out />);><mtw:out /></a>  
         </mtw:isCurrPage>
     </mtw:pageNumbers>
     <mtw:hasNext>
           
        <a href="#" onclick=find(<mtw:out />);><strong>Next</strong></a>  
     </mtw:hasNext>
 </td>
 </tr>    
     <mtw:loop>
       <tr>
  	<td><mtw:out value="id" /></td>
  	<td><mtw:out value="name" /></td>
 	</tr>
     </mtw:loop>
 </mtw:paginator>
 </table>
 


Action
Code:
 public String loadAll() throws Exception {
     Collection < City > list = (Collection)beanSession.loadList(new City());
     output.setValue("list", list);
     return SUCCESS;
 }
 
[Thumb - GridPaging.png]
 Filename GridPaging.png [Disk] Download
 Description
 Filesize 13 Kbytes
 Downloaded:  845 time(s)


Atenciosamente,
Hélio Frota

Helio Frota
10+ Java Programmer
heliofrota.com

Member
Mentawai Developer
 
Forum Index -> F.A.Q.
Go to:   
Powered by JForum 2.1.6 © JForum Team