0 Replies Latest reply: May 16, 2012 8:25 AM by Roshan Mutha RSS

How to migrate ExtendedTableDataModel to richfaces 4.

Roshan Mutha Newbie

I am new to richfaces.I am having one class which is as follows,

 

Here ExtendedTableDataModel and other model classes are removed in richfaces4. So which model to use to achive same functionality?

 

if given reference to an example will be helpful.

 

 

package com.ibi.widgets;

 

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

 

import org.richfaces.model.DataProvider;

import org.richfaces.model.ExtendedTableDataModel;

import org.richfaces.model.ScrollableTableDataModel.SimpleRowKey;

import org.richfaces.model.selection.SimpleSelection;

 

public class QueryManager{
    private String sortMode = "single";
    private String selectionMode = "multi";
    private SimpleSelection selection;
    private List selectedItems = new ArrayList();
    private ExtendedTableDataModel dataModel;
    private List items = new ArrayList();

 

    public SimpleSelection getSelection() {
        return selection;
    }

 

    public List getSelectedItems() {
        return selectedItems;
    }

 

    public void setSelectedItems(List selectedItems) {
        this.selectedItems = selectedItems;
    }

 

    public void setSelection(SimpleSelection selection) {
        this.selection = selection;
    }

 

    public Object getSelectedObject() {
        Iterator<Object> iterator = getSelection().getKeys();
        while (iterator.hasNext()) {
            Object key = iterator.next();
            dataModel.setRowKey(key);
            return dataModel.getRowData();
        }
        return null;
    }

 

    public String getSortMode() {
        return sortMode;
    }

 

    public void setSortMode(String sortMode) {
        this.sortMode = sortMode;
    }

 

    public String getSelectionMode() {
        return selectionMode;
    }

 

    public void setSelectionMode(String selectionMode) {
        this.selectionMode = selectionMode;
    }

 

    public ExtendedDataTableBean() {
    }

 

private ExtendedTableDataModel<AdvanceQuery> advQueryDataModel;

    private Object advQueryTableState;

    private SimpleSelection advSelection = new SimpleSelection();

    private boolean isAdvQueryRefreshRequired = false;

 

public ExtendedTableDataModel<AdvanceQuery> getAdvQueryDataModel() {

 

        if (advQueryDataModel == null || this.isAdvQueryRefreshRequired) {

            isAdvQueryRefreshRequired = false;

            //log.info("-----------init advQueryDataModel");

            advQueryDataModel = new ExtendedTableDataModel<AdvanceQuery>(new DataProvider<AdvanceQuery>(){

 

                private static final long serialVersionUID = 5054087821033164847L;

 

                public AdvanceQuery getItemByKey(Object key) {

                //    log.info("----------------getItemByKey " + key.toString());

 

                    int index = ((SimpleRowKey)key).intValue();

 

                    return getAdvancedQueries().get(index);

                    /**for(EncounterData e : getActiveEncounterData()){

                        if (key.equals(getKey(e))){

                            return e;

                        }

                    }

                    return null;**/

                }

 

                public List<AdvanceQuery> getItemsByRange(int firstRow, int endRow) {

                    return getAdvancedQueries().subList(firstRow, endRow);

                }

 

                public Object getKey(AdvanceQuery item) {                   

                    SimpleRowKey key = new SimpleRowKey(getAdvancedQueries().indexOf(item));

                    //log.info("----------------getKey " + item.getDataKey().toString() + " key " + key.intValue());

                    return key;

                }

 

                public int getRowCount() {

                    return getAdvancedQueries().size();

                }

 

            });

        }

 

        //log.info("---------------- advQueryDataModel size " + advQueryDataModel.getRowCount());

        //log.info("advQueryDataModel getAdvancedQueries() " + getAdvancedQueries().size());

        return advQueryDataModel;

    }

 

 

public String takeAdvSelection()

    {

        //log.info("---------------takeSelection size " + getSelection().size());

        //setSelectedEncounterData(null);

        Iterator<Object> iterator = getAdvSelection().getKeys();

        while(iterator.hasNext())

        {

            SimpleRowKey obj = (SimpleRowKey)iterator.next();       

            int index = obj.intValue();

            AdvanceQuery query = getAdvancedQueries().get(index);

 

            if(query instanceof GlobalQuery)

            {

                setCurrentCriteriaSelected(true);

            }

 

            setCurrentSelectedQueryIndex(index);

 

            resetCurrentQuery(query);

            }

          /**  for(AdvanceQuery query: queries)

            {               

                int index =  queries.indexOf(query);

       //         log.info("****************************************current query is " + query.toString() + " index " + index + " group id " + query.getGroupID());

 

                if(query.toString().equalsIgnoreCase(obj.toString()))

                {                   

                    //setCurrentCriteriaSelected(true);

                    //setCurrentPersonQuery((PersonQuery)query);

                    if(query instanceof GlobalQuery)

                    {

                        setCurrentCriteriaSelected(true);

                    }

 

                    setCurrentSelectedQueryIndex(index);

 

                    resetCurrentQuery(query);

                }

            }**/

 

        //    log.info("----------------takeSelection DS " + obj.toString() + " groupe id " + obj.getGroupID());

        //}

 

        return null;

    }

 

    public void clearSelection() {
        getSelectedItems().clear();   
    }
   
    public void setItems(List items) {
        this.items = items;
    }

 

}

 

 

and xhtml as follows,

 

<rich:extendedDataTable width="290px" id="advQueryList" columnClasses="col"

                                    sortMode="single" selectionMode="single" height="400px" cellpadding="1"            

                                       value="#{queryManager.advQueryDataModel}"        

                                       var="advQuery"

                                       selection="#{queryManager.advSelection}"

                                       tableState="#{queryManager.advQueryTableState}"

                                       selectedClass="selectedRow"

                                        rowKeyVar="rowNum"

                                        noDataLabel="#{messages['home.searchCriteria.noQueryFound']}">

                                        <rich:column sortable="false" width="100%">

                                            <f:facet name="header">

                                                <h:outputText value="#{messages['home.searchCriteria']}" id="ds"/>

                                            </f:facet>

                                            <h:outputText value="#{advQuery.toString()}"/>

                                           

                                        </rich:column>

                 </rich:extendedDataTable>