Seriously do flex + spring + blazeDS + google app JDO paging. The total number for each inquiry.

Seriously do flex + spring + blazeDS + google app JDO paging. The total number for each inquiry.

BlazeDS frustrating to die recently ..

A little bit to replace e4x xml format as to the relatively simple. But finally did not give up. Harvest is good.

First, explore inside the dynamic loading using SWFLoader do.

Depending on the menu to display different tab pages.

However, several label switch error when the problem:

*** TypeError: Error # 1034: type cast fails: can not convert Object @ b932bf1 mx.messaging.messages.IMessage.

The search is due to shared library module is loaded.

There are some things not found .. load failure.

http://www.javaeye.com/topic/297813

Refer to the following ..

Practice:

The. / / Var swfLoader: SWFLoader = new SWFLoader ();
/ / SwfLoader.source = nodeApp + ". Swf";
Replaced.
var swfLoader: ModuleLoader = new ModuleLoader ();
Load module.
swfLoader.applicationDomain = ApplicationDomain.currentDomain;
/ / Address [TypeError: Error # 1034: type cast fails:] module loading problem.
swfLoader.loadModule (nodeApp + ". swf");
And application replication.

Successfully loaded multiple modules. .. And began to load the module solved the problem of slow.

BlazeDS is also very fast to use. Seems to insist is right.

Began writing the following pages.

A reference to the previous page into a class as ..

package common.page
{
        import mx.controls.Label;
        import mx.events.ItemClickEvent;

        public class PageConf
        {
                /**  Paging class start  .*./ /**  Sort fields  . */
                public var sortField:String;
                /**  Sort Ascending and descending  .des,aesc. */
                public var sortDir:String;
                /**  Paging start  . */
                private var start:Number;
                /**  Paging end  . */
                private var end:Number;
                /**  The maximum number per page  . */
                private var limit:Number;
                /**  The total number of pages  . */
                public var total:Number;

                public function getStart():Number {
                        return this.start;
                }
                public function getEnd():Number {
                        // Recalculate every time because the End.  . Is it possible to increase the query time, data  .
                        return Math.min(this.start + this.limit, this.total);
                }

                public function getCurrPage():Number {// Get the current page  .
                        return Number(Math.floor(start / limit));
                }

                public function getTotalPage():Number {
                        /**  Get the total number of pages  . */
                        return Number(Math.ceil(total / limit));
                }

                public function getGo(page:Number):void {/*  Page jump function enter to jump to the page  . */
                        var totalPage:Number = getTotalPage();
                        var currentPage:Number = getCurrPage();
                        if (page <= 1) {/*  If less than 1. go to Home  . */
                                getFirst();
                                return;
                        } else if (page >= totalPage) {/*  If is greater than the total number of pages to jump to the last page  . */
                                getLast();
                                return;
                        } else if (page == currentPage) {/*  Returns the current page  . */
                                return;
                        } else {/*  Otherwise for page jump-that is, calculate the  start And  end. */
                                this.start = (page - 1) * limit;
                                this.end = Math.min(page * limit, total);
                        }
                }

                public function getNext():void  {
                        trace("getNextPage");
                        var currentPage:Number = getCurrPage();
                        var tempStart:Number = (currentPage + 1) * limit;
                        if (tempStart >= total)
                                return;
                        this.start = tempStart;
                        this.end = Math.min((currentPage + 2) * limit, total);
                }

                public function getFirst():void  {
                        trace("getFirst");
                        this.start = 0;
                        this.end = Math.min(limit, total);
                }

                public function getLast():void {
                        trace("getEnd");
                        var lastPage:Number = getTotalPage();
                        /**  If the total number of pages exactly divisible. to the previous page  . */
                        if ((lastPage * limit) >= total) {
                                lastPage--;
                        }
                        this.start = lastPage * limit;
                        this.end = Math.min((lastPage + 1) * limit, total);
                }

                public function getPrev():void {
                        trace("getPrevpage");
                        var currentPage:Number = getCurrPage();
                        /**  The previous page is equal to the current pages multiplied by the number of records per page  . */
                        this.start = Math.max((currentPage - 1) * limit, 0);
                        this.end = Math.max((currentPage) * limit, limit);
                }

                public function hasNext():Boolean{
                        if (this.end == this.total) {
                                return false;
                        } else if (this.getTotalPage() <= 1) {
                                return false;
                        } else {
                                return true;
                        }
                }

                public function hastPrev():Boolean {
                        if (this.start == 0) {
                                return false;
                        } else {
                                return true;
                        }
                }

                public function PageConf(start:Number, limit:Number, total:Number) {/*  The constructor sets the start.  . And pages  . */
                        this.start = start;
                        this.limit = limit;
                        this.end = this.limit;
                        this.total = total;
                }

                public function pageItemClick(itemClick:ItemClickEvent, pageInfo:Label):void {
                                if(itemClick.index == 0){
                                        getFirst();
                                }else if(itemClick.index == 1){
                                        getPrev();
                                }else if(itemClick.index == 2){
                                        getNext();
                                }else if(itemClick.index == 3){
                                        getLast();
                                }else{
                                        return;
                                }
            }

            public function showPageInfo(pageInfo:Label):void {// Universal display Info page  .
                                var tempStart:Number = 0;
                                var tempEnd:Number = 0;
                                if(total != 0){// Troubleshoot display number 0 is the first problem  .App It is a start at 0  .
                                        tempStart = (start+1);
                                }
                                if(getCurrPage() == 0){
                                        tempEnd = Math.min(getEnd(), total);
                                }else{
                                        tempEnd = getEnd();
                                }
                                pageInfo.text = "["+tempStart+"-"+tempEnd+"/"+total+"]";
            }

            public function toString():String{
                return "start["+start+"]end["+
                end+"]total["+total+"]limit["+limit;
            }
        }
}

Then in a module ..

<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%" >
<mx:HBox width="100%">
    <mx:Label textAlign="right" paddingTop="4" width="90" height="22" fontWeight="bold" fontSize="12"></mx:Label>
        <mx:LinkBar>
                <mx:dataProvider>
                <mx:Array>
                    <mx:String> Home  </mx:String>
                    <mx:String> Previous  </mx:String>
                    <mx:String> The next page  </mx:String>
                    <mx:String> End  </mx:String>
                </mx:Array>
        </mx:dataProvider>
        </mx:LinkBar>
</mx:HBox>
</mx:Canvas>

In other documents which refer to this module.

The easiest page to do a page.

But also learned to manage sub-folders for the module.

Seriously do flex + spring + blazeDS + google app JDO paging. The total number for each inquiry.

Seriously do flex + spring + blazeDS + google app JDO paging. The total number for each inquiry.

Page as shown.

One method is called.

<?xml version="1.0" encoding="utf-8"?>
<mx:Module xmlns:mx="http://www.adobe.com/2006/mxml"
  backgroundColor="#EEEEEE" width="100%" fontSize="12" initialize="initApp();" height="100%"
  xmlns:common="common.page.*">

<mx:RemoteObject destination="systemUserDAO">
        <mx:method name="list" result="listHandler(event)"/>
        <mx:method name="listSize" result="listSizeHandler(event)"/>
</mx:RemoteObject>
<mx:Script>
        <![CDATA[
                import mx.collections.ArrayCollection;
                import mx.events.ItemClickEvent;
                import mx.rpc.events.ResultEvent;
                import common.page.PageConf;
                import mx.controls.Alert;
                import mx.managers.PopUpManager;

                private var myPageConf:PageConf;
                // The initialization function  .
                private function initApp():void{
                        // Define a default load classes  .
                myPageConf = new PageConf(0,15,0);
                // The first default query data  .
                systemUserDAO.listSize();
                // To bind an event of universal paging Bar  .
                commonPageBar.pageLikBar.addEventListener(ItemClickEvent.ITEM_CLICK,
                        function(event:ItemClickEvent):void{// Anonymous functions  .
                                myPageConf.pageItemClick(event, commonPageBar.pageInfo);
                                systemUserDAO.listSize();
                });
                }
                // The list shows the data  .
                [Bindable]
        private var listData:ArrayCollection;
        // The total number of response processing query  .
                private function listSizeHandler(event:ResultEvent):void
                {
                        var pageSize:Number = event.result as Number;
                        myPageConf.total = pageSize;
                        systemUserDAO.list(myPageConf.getStart(), myPageConf.getEnd());
                        // The total number of records to display information.  .
                        myPageConf.showPageInfo(commonPageBar.pageInfo);
                }
                // Query data response processing  .
                private function listHandler(event:ResultEvent):void
                {
                         listData = event.result as ArrayCollection;
                }
        ]]>
</mx:Script>

<mx:VBox>
        <mx:DataGrid width="100%" height="386"
                editable="false" dataProvider="{listData}">
            <mx:columns>
                <mx:DataGridColumn headerText="id" width="10" />
                <mx:DataGridColumn headerText=" Sign-in name  " dataField="loginName"/>
                <mx:DataGridColumn headerText=" Name  " dataField="name"/>
                <mx:DataGridColumn headerText=" Phone  " dataField="phone"/>
                <mx:DataGridColumn headerText="email" dataField="email"/>
                <mx:DataGridColumn headerText=" Creation time  " dataField="createDate"/>
            </mx:columns>
        </mx:DataGrid>
        <mx:HBox width="100%">
                <mx:Button label=" Add new  " click="addForm();"/>
                <mx:Button label=" Delete  "/>
                <mx:Spacer width="100"/>
        <common:PageBar/>
        </mx:HBox>
</mx:VBox>

</mx:Module>

There is a problem .. I use two remote method call.

The first query of total number of pages. Which then flip. And then query

Data. Each time to check the total. Write two methods. There is no good way to think of inquiry.

Background was found with a google app generic dao support above reflective. Borrow someone else's code under.

Query DAO generic class.

package com.freewebsys.dao.impl;

import java.lang.reflect.ParameterizedType;
import java.util.List;
import java.util.Map;
import javax.jdo.PersistenceManager;
import javax.jdo.Query;
import org.springframework.orm.jdo.support.JdoDaoSupport;
import com.freewebsys.dao.IGenericDAO;
import com.freewebsys.jdo.BaseBean;
import com.freewebsys.jdo.SystemUser;

@SuppressWarnings("unchecked")
public abstract class GenericDAOImpl<T extends BaseBean> extends JdoDaoSupport
                implements IGenericDAO {

        private Class<T> entityClass;

        public GenericDAOImpl() {
                //  Classic through reflection to get class  .
                entityClass = (Class<T>) ((ParameterizedType) getClass()
                                .getGenericSuperclass()).getActualTypeArguments()[0];
        }

        @Override
        public boolean delete(BaseBean item) {
                // TODO Auto-generated method stub
                return false;
        }

        @Override
        public boolean save(BaseBean item) {
                PersistenceManager pm = getPersistenceManager();
                System.out.println(this.entityClass + " Call the Save method  .");
                try {
                        if (item.getId() == null) {
                                pm.makePersistent(item);
                        } else {
                                BaseBean itemOld = pm.getObjectById(item.getClass(), item
                                                .getId());
                                pm.makePersistent(itemOld);
                        }
                } catch (Exception e) {
                        e.printStackTrace();
                } finally {
                        pm.close();
                }
                return false;
        }

        @Override
        public T findById(long id) {
                return null;
        }

        @Override
        public List<T> findByProp(Map value) {
                return null;
        }

        @Override
        public List<T> list(long start, long end) {
                PersistenceManager pm = getPersistenceManager();
                try {
                        Query query = pm.newQuery(entityClass);
                        /**  Add the sort query .sort is sort fields  .dir Is the order or reverse order  . */
                        System.out.println("JDO pageList:[" + query.toString() + "]start:["
                                        + start + "]end:[" + end + "]");
                        query.setRange(start, end);
                        List<T> results = (List<T>) query.execute("Smith");
                        // for(int i = 0; i < results.size(); i ++){
                        // T t = results.get(i);
                        // System.out.println(t);
                        // }
                        /**  Set a start and end  . */
                        System.out.println("results size:[\t" + results.size());
                        return results;
                } catch (Exception e) {
                        e.printStackTrace();
                } finally {
                        pm.close();
                }
                return null;
        }

        @Override
        public long listSize() {
                PersistenceManager pm = getPersistenceManager();
                try {
                        long size = 0;
                        /**  Maximum number of query  . */
                        Query query = pm.newQuery("select count(id) from "
                                        + entityClass.getName());
                        /**  The total number of query  . */
                        // query = commonListQuery(query, null);

                        /**  Cast  int */
                        size = Long.parseLong(query.execute("Smith").toString());
                        //System.out.println("JDO pageSize:\t" + query.toString());
                        return size;
                } catch (Exception e) {
                        e.printStackTrace();
                } finally {
                        pm.close();
                }
                return 0;
        }
}

Also solved. In flip when inserting new data. Next page update.

Relatively satisfied with the paging.

Annex is the code.

http://myflexeye.appspot.com

Deployed to the google server. Can run.

Annex engineering. BlazeDS and app spring without the jar file.

分类:Flash 时间:2010-04-17 人气:311
分享到:
blog comments powered by Disqus

相关文章

iOS 开发

Android 开发

Python 开发

JAVA 开发

开发语言

PHP 开发

Ruby 开发

搜索

前端开发

数据库

开发工具

开放平台

Javascript 开发

.NET 开发

云计算

服务器

Copyright (C) codeweblog.com, All Rights Reserved.

CodeWeblog.com 版权所有 黔ICP备15002463号-1

processed in 0.126 (s). 12 q(s)