If you can figure out how to do it in JSF, then I can probably help do it
in EGL, although I haven't tried it.
Here is how I do it with JSF. Pay particular attention to the firstResult
portion. Any idea how we could do this in EGL? BTW, I have 2hrs left on my
download of RAD_V7.
--userlist.jsp-- (note dataTable attributes value, rows, first):
<h:panelGroup>
<x:dataTable id="list1" styleClass="table" headerClass="table_header"
var="user"
value="#{UserCtl.userListDataModel}" preserveDataModel="true"
rowClasses="row1,row2"
rows="#{UserCtl.perPage}" first="#{UserCtl.firstResult}">
<h:column>
<f:facet name="header">
<h:commandLink action="#{UserCtl.orderByName}">
<h:outputText id="orderbyname" value="#{fl.user_name}" />
</h:commandLink>
</f:facet>
<h:outputText value="#{user.name}" styleClass="copy" />
</h:column>
<h:column>
<f:facet name="header">
<h:commandLink action="#{UserCtl.orderByFirstName}">
<h:outputText id="orderbyfirstname" value="First Name" />
</h:commandLink>
</f:facet>
<h:outputText value="#{user.firstname}" styleClass="copy" />
</h:column>
<h:column>
<f:facet name="header">
<h:commandLink action="#{UserCtl.orderByLastName}">
<h:outputText id="orderbylastname" value="Last Name" />
</h:commandLink>
</f:facet>
<h:outputText value="#{user.lastname}" styleClass="copy" />
</h:column>
<h:column>
<f:facet name="header">
<h:commandLink action="#{UserCtl.orderByEmail}">
<h:outputText id="orderbyemail" value="Email" />
</h:commandLink>
</f:facet>
<h:outputText value="#{user.email}" styleClass="copy" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Action" />
</f:facet>
<h:commandLink id="edit" action="#{UserCtl.updateUserPage}"
value="edit" styleClass="copy" />
<h:outputText value=" | " styleClass="copy" />
<h:commandLink id="delete" action="#{UserCtl.deleteUserPage}"
value="delete"
styleClass="copy" />
</h:column>
</x:dataTable>
<h:panelGrid columns="1" styleClass="table3">
<x:dataScroller id="ds2" for="list1" paginator="true"
paginatorMaxPages="9"
paginatorTableClass="paginator"
paginatorActiveColumnStyle="font-weight:bold;"
fastStep="10">
<f:facet name="first">
<h:graphicImage url="images/arrow-first.gif" styleClass="button" />
</f:facet>
<f:facet name="last">
<h:graphicImage url="images/arrow-last.gif" styleClass="button" />
</f:facet>
<f:facet name="previous">
<h:graphicImage url="images/arrow-previous.gif" styleClass="button"
/>
</f:facet>
<f:facet name="next">
<h:graphicImage url="images/arrow-next.gif" styleClass="button" />
</f:facet>
<f:facet name="fastforward">
<h:graphicImage url="images/arrow-ff.gif" styleClass="button" />
</f:facet>
<f:facet name="fastrewind">
<h:graphicImage url="images/arrow-fr.gif" styleClass="button" />
</f:facet>
</x:dataScroller>
<x:dataScroller for="list1" pageCountVar="pageCount"
pageIndexVar="pageIndex">
<h:outputFormat value="#{controls['dataScroller_pages']}"
styleClass="copy">
<f:param value="#{pageIndex}" />
<f:param value="#{pageCount}" />
</h:outputFormat>
</x:dataScroller>
</h:panelGrid>
</h:panelGroup>
--UserController.java--
import java.util.List;
import javax.faces.component.html.HtmlDataTable;
import javax.faces.component.html.HtmlForm;
import com.mowyourlawn.dao.DAOGeneric;
import com.mowyourlawn.dao.User;
import com.mowyourlawn.uiobjects.PagedListDataModel;
import com.mowyourlawn.util.Const;
import com.mowyourlawn.util.UIHelper;
public class UserController {
String orderBy = "created";
String orderDirection = Const.DESC;
int firstResult = 0;
int perPage = 0;
public UserController() {
}
public PagedListDataModel getUserListDataModel() {
HtmlDataTable list1 = (HtmlDataTable)
UIHelper.findComponent("form1:list1");
HtmlForm form1 = (HtmlForm) UIHelper.findComponent("form1");
if (form1.isSubmitted())
firstResult = list1.getFirst();
int rowCount = DAOGeneric.getDataCount("User", "");
List records = DAOGeneric.getPagedData("User", "", orderBy,
orderDirection, firstResult, perPage);
PagedListDataModel dataModel = new PagedListDataModel();
dataModel.setWrappedData(records);
dataModel.setTotalNumRows(rowCount);
dataModel.setPageSize(perPage);
return dataModel;
}
public int getFirstResult() {
return firstResult;
}
public void setFirstResult(int firstResult) {
this.firstResult = firstResult;
}
public int getPerPage() {
return perPage;
}
public void setPerPage(int perPage) {
this.perPage = perPage;
}
}
--PagedListDataModel.java--
import java.util.List;
import javax.faces.model.DataModel;
public class PagedListDataModel extends DataModel {
private int rowIndex = -1;
private int totalNumRows;
private int pageSize;
private List list;
public PagedListDataModel() {
super();
}
public PagedListDataModel(List list, int totalNumRows, int pageSize) {
super();
setWrappedData(list);
this.totalNumRows = totalNumRows;
this.pageSize = pageSize;
}
public boolean isRowAvailable() {
if (list == null)
return false;
int rowIndex = getRowIndex();
if (rowIndex >= 0 && rowIndex < list.size())
return true;
else
return false;
}
public int getRowCount() {
return totalNumRows;
}
public Object getRowData() {
if (list == null)
return null;
else if (!isRowAvailable())
throw new IllegalArgumentException();
else {
int dataIndex = getRowIndex();
return list.get(dataIndex);
}
}
public int getRowIndex() {
return (rowIndex % pageSize);
}
public void setRowIndex(int rowIndex) {
this.rowIndex = rowIndex;
}
public Object getWrappedData() {
return list;
}
public void setWrappedData(Object list) {
this.list = (List) list;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public int getTotalNumRows() {
return totalNumRows;
}
public void setTotalNumRows(int totalNumRows) {
this.totalNumRows = totalNumRows;
}
}
Aaron Bartell
http://mowyourlawn.com
As an Amazon Associate we earn from qualifying purchases.