Author: ishabalov
Date: 2007-09-05 14:11:56 -0400 (Wed, 05 Sep 2007)
New Revision: 2786
Modified:
trunk/samples/richfaces-demo/src/main/java/org/richfaces/demo/extendeddatamodel/AuctionDataModel.java
trunk/samples/richfaces-demo/src/main/java/org/richfaces/demo/extendeddatamodel/AuctionItem.java
trunk/samples/richfaces-demo/src/main/webapp/richfaces/dataTable/examples/extendedDataModel.xhtml
trunk/samples/richfaces-demo/src/main/webapp/richfaces/dataTable/extended-data-model.xhtml
Log:
More extended data model sample
Modified:
trunk/samples/richfaces-demo/src/main/java/org/richfaces/demo/extendeddatamodel/AuctionDataModel.java
===================================================================
---
trunk/samples/richfaces-demo/src/main/java/org/richfaces/demo/extendeddatamodel/AuctionDataModel.java 2007-09-05
17:46:02 UTC (rev 2785)
+++
trunk/samples/richfaces-demo/src/main/java/org/richfaces/demo/extendeddatamodel/AuctionDataModel.java 2007-09-05
18:11:56 UTC (rev 2786)
@@ -17,10 +17,10 @@
* @author ias
* This is example class that intended to demonstrate use of ExtendedDataModel and
SerializableDataModel.
* This implementation intended to be used as a request scope bean. However, it actually
provides serialized
- * state, so on a post-back we do not load data from the data provider. Instead we use
whatever data was used
+ * state, so on a post-back we do not load data from the data provider. Instead we use
data that was used
* during rendering.
- * This data model intended to be used together with Data Provider, which is responsible
for actual data load
- * from the database using specific filtering and sorting. Normally it suppose to be in
either session, or conversation
+ * This data model must be used together with Data Provider, which is responsible for
actual data load
+ * from the database using specific filtering and sorting. Normally Data Provider must be
in either session, or conversation
* scope.
*/
public class AuctionDataModel extends SerializableDataModel {
Modified:
trunk/samples/richfaces-demo/src/main/java/org/richfaces/demo/extendeddatamodel/AuctionItem.java
===================================================================
---
trunk/samples/richfaces-demo/src/main/java/org/richfaces/demo/extendeddatamodel/AuctionItem.java 2007-09-05
17:46:02 UTC (rev 2785)
+++
trunk/samples/richfaces-demo/src/main/java/org/richfaces/demo/extendeddatamodel/AuctionItem.java 2007-09-05
18:11:56 UTC (rev 2786)
@@ -3,6 +3,7 @@
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
+import javax.faces.event.ActionEvent;
public class AuctionItem {
private Integer pk;
@@ -60,25 +61,23 @@
public void setQtyAvialable(Integer qtyAvialable) {
this.qtyAvialable = qtyAvialable;
}
- public String placeBid() {
- if (qtyRequested!=null && bid!=null) {
+ public void placeBid(ActionEvent event) {
+ FacesContext ctx = FacesContext.getCurrentInstance();
+ if (bid!=null) {
System.out.println("place bid for pk="+getPk()+"
bid="+getBid()+" qty="+getQtyRequested());
- FacesContext ctx = FacesContext.getCurrentInstance();
- if (qtyRequested>qtyAvialable) {
- ctx.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR,"Requested
quantity is grater that avialable quantity","You cannot request more auction
items, that actually avialable on auction"));
- won = loose = false;
- } else if (bid<=highestBid) {
- ctx.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN,"Bid amount is
lower that highest bid","You need to bid amount higher that highest
bid"));
+ if (bid<=highestBid) {
+ ctx.addMessage(event.getComponent().getClientId(ctx), new
FacesMessage(FacesMessage.SEVERITY_WARN,"Bid amount is lower that highest
bid","You need to bid amount higher that highest bid"));
won = false;
loose = true;
} else {
highestBid = bid;
won = true;
loose = false;
- amount = qtyRequested*bid;
+ amount = bid;
}
+ } else {
+ ctx.addMessage(event.getComponent().getClientId(ctx), new
FacesMessage(FacesMessage.SEVERITY_ERROR,"Bid value is missing","You must
provide bid value"));
}
- return null;
}
public UIComponent getBidInput() {
Modified:
trunk/samples/richfaces-demo/src/main/webapp/richfaces/dataTable/examples/extendedDataModel.xhtml
===================================================================
---
trunk/samples/richfaces-demo/src/main/webapp/richfaces/dataTable/examples/extendedDataModel.xhtml 2007-09-05
17:46:02 UTC (rev 2785)
+++
trunk/samples/richfaces-demo/src/main/webapp/richfaces/dataTable/examples/extendedDataModel.xhtml 2007-09-05
18:11:56 UTC (rev 2786)
@@ -4,13 +4,11 @@
xmlns:f="http://java.sun.com/jsf/core"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich">
-
- <rich:messages />
-
+ <rich:messages />
<h:form>
<rich:datascroller for="auction" maxPages="5"/>
<rich:spacer height="30" />
- <rich:dataTable id="auction" value="#{auctionDataModel}"
var="item" rows="25">
+ <rich:dataTable id="auction" value="#{auctionDataModel}"
var="item" rows="10">
<rich:column>
<f:facet name="header">
<h:outputText value="Description"/>
@@ -27,29 +25,17 @@
</rich:column>
<rich:column>
<f:facet name="header">
- <h:outputText value="Qty Avialable"/>
- </f:facet>
- <h:outputText value="#{item.qtyAvialable}"/>
- </rich:column>
- <rich:column>
- <f:facet name="header">
<h:outputText value="Your Bid"/>
</f:facet>
<h:inputText id="bid" value="#{item.bid}">
<f:convertNumber />
</h:inputText>
- <a4j:commandLink action="#{item.placeBid}" value="Bid!"
reRender="bid,qty,amount,highestBid" />
+ <a4j:commandLink id="bid_link"
actionListener="#{item.placeBid}" value="Place a bid!"
reRender="bid,amount,highestBid" />
+ <rich:message for="bid_link" />
+ <rich:message for="bid" />
</rich:column>
<rich:column>
<f:facet name="header">
- <h:outputText value="Your Qty"/>
- </f:facet>
- <h:inputText id="qty" value="#{item.qtyRequested}">
- <f:convertNumber />
- </h:inputText>
- </rich:column>
- <rich:column>
- <f:facet name="header">
<h:outputText value="Amount"/>
</f:facet>
<h:outputText id="amount" value="#{item.amount}" >
Modified:
trunk/samples/richfaces-demo/src/main/webapp/richfaces/dataTable/extended-data-model.xhtml
===================================================================
---
trunk/samples/richfaces-demo/src/main/webapp/richfaces/dataTable/extended-data-model.xhtml 2007-09-05
17:46:02 UTC (rev 2785)
+++
trunk/samples/richfaces-demo/src/main/webapp/richfaces/dataTable/extended-data-model.xhtml 2007-09-05
18:11:56 UTC (rev 2786)
@@ -7,7 +7,29 @@
xmlns:rich="http://richfaces.org/rich">
<ui:composition template="/templates/component-sample.xhtml">
<ui:define name="sample">
- <p>Some explanation how to use ExtendedDataModel will be here
+ <p>
+Perhaps the most obvious problem of DataTable and javax.faces.model.DataModel is lack of
support for more complicated scenarios that uses
+data from the database.
+To solve that problem <b>Richfaces</b> has two major tools:
+<ul>
+ <li>
+ set of data-driven components that render data sets in many different ways
(<b>rich:dataTable</b> , <b>rich:dataGrid</b>,
<b>rich:dataList</b>, <b>a4j:repeat</b> etc.).
+ All this components derived it common functionality from the common core that, in
addition to standard javax.faces.model.DataModel,
+ can understand and use
+ </li>
+ <li>
+ extended data model classes <b>org.ajax4jsf.model.ExtendedDataModel</b> and
<b>org.ajax4jsf.model.SerializableDataModel</b>. This two classes works
+ together to provide functions that missing in standard DataModel.
+ </li>
+</ul>
+The most important additional functions are:
+<ul>
+ <li>access for rows by primary keys instead of index position</li>
+ <li>implementation of "visitor" pattern over the "range" of
rows to support "table scroller" or "paginator" functions</li>
+ <li>ability to serialize table data so it may be used on a post-back processing
without additional database query</li>
+</ul>
+To use this extensions you need to implement your own DataModel that extends one of our
ExtendedDataModel classes and implement few of
+important functions. Below is the example of such implementation.
</p>
<div class="sample-container" >
@@ -18,7 +40,7 @@
</ui:include>
<ui:include src="/templates/include/sourceview.xhtml">
- <ui:param name="sourcepath"
value="/WEB-INF/src/org/richfaces/datatable/ExpenseReport.java"/>
+ <ui:param name="sourcepath"
value="/WEB-INF/src/org/richfaces/demo/extendeddatamodel/AuctionDataModel.java"/>
<ui:param name="openlabel" value="View Page Source" />
</ui:include>