Information Technology Reference
In-Depth Information
}catch (Exception e) {
e.printStackTrace();}
return dataList;}}
Last layer is query layer, the interface with JSF, which includes specific query
classes. All query classes are inherited from the abstract class DataModelList; they
are instantiated in the JSF's backing Bean according to different purposes, one
instance of query class is a DetachedCriteria object. In the food traceability system,
there are two query actions, so its need to design two query classes named
batchGoodsDataModel and originalGoodsDataModel. The key codes are as follows:
@Override
protected DetachedCriteria getDetachedCriteria() {
DetachedCriteria detachedCriteria =
DetachedCriteria.forClass(TableReceive.class);
for(int i=0;i<criterions.size();i++){
detachedCriteria.add(criterions.get(i)); }
return detachedCriteria; }
In the JSF framework, the Backing Bean collects the data from the JSF pages
referenced on Backing Bean, So Bean can be seen as the logic part of the JSF.
As the requirement is relatively simple in the food traceability system, two query
pages share a common Backing Bean named QueryBean. Meanwhile, the interaction
with the Middle Layer is implemented in QueryBean.When a user clicked the query
button, the method queryAction () defined in QueryBean will be called. The major
task of queryAction () is creating a batchGoodsDataModel object, actually, that object
is a DetachedCriteria object encapsulating query values in the JSF pages.After
collecting all query conditions, the method query () of batchGoodsDataModel object
is called to return the results from DataAccess in the form of DataModel, thus, the
component DataTable can use result as data source directly, without transforming.
The key codes are as follows:
batchGoodsDataModel batchDataModel=new batchGoodsDataModel();
if(this.batchNo==null || this.batchNo.isEmpty()){
return "NullInput";}
if(this.batchNo.length()<10){return "noRecords";}
String batchLast=this.batchNo.substring(0, 10);
String goodsNo=this.batchNo.substring(10);
Criterion criterion1=Restrictions.like("batchNo","%"+batchLast);
Criterion criterion2=Restrictions.eq("goodsNo",goodsNo);
batchDataModel.getCriterions().add(criterion1);
batchDataModel.getCriterions().add(criterion2);
2.3 The Advantage of Middle Layer
Using polymorphism, an important feature of the object-oriented programming, in
abstract class DataModelList to return different off-line objects under the complicated
application has many benefits. It can build a multi-layer Middle Layer with high reli-
ability, maintainability, expansibility and reuse.
Search WWH ::




Custom Search