Hi Isomorphic,
I have problem in displaying the data in my grid.
I have created a .jsp (empresaTipoDMI.jsp) file with a list grid, the .jsp file code is:
<%@ taglib uri="/WEB-INF/iscTaglib.xml" prefix="isomorphic" %>
<HTML>
<HEAD>
<SCRIPT>var isomorphicDir="isomorphic/";</SCRIPT>
<SCRIPT SRC=isomorphic/system/modules/ISC_Core.js></SCRIPT>
<SCRIPT SRC=isomorphic/system/modules/ISC_Foundation.js></SCRIPT>
<SCRIPT SRC=isomorphic/system/modules/ISC_Containers.js></SCRIPT>
<SCRIPT SRC=isomorphic/system/modules/ISC_Grids.js></SCRIPT>
<SCRIPT SRC=isomorphic/system/modules/ISC_Forms.js></SCRIPT>
<SCRIPT SRC=isomorphic/system/modules/ISC_DataBinding.js></SCRIPT>
<SCRIPT SRC=isomorphic/skins/TreeFrog/load_skin.js></SCRIPT>
</HEAD>
<BODY>
<SCRIPT>
<isomorphic:loadDS ID="empresaTipoDMI"/>
VStack.create({
left:50, top:75,
width:"70%",
membersMargin:20,
members:[
Label.create({
ID:"helpText",
autoDraw: false,
contents:"<ul>" +
"<li>click a record in the grid to view and edit that record in the form</li>" +
"<li>click <b>Save</b> to save changes to an edited record in the form</li>" +
"<li>click <b>Clear</b> to clear all fields in the form</li>" +
"<li>click <b>Filter</b> to filter (substring match) the grid based on the value of the 'Item' form value only.</li>" +
"<li>click <b>Fetch</b> to fetch records (exact match) for the grid based on the value of the 'Item' form value only.</li>" +
"<li>click <b>Delete</b> to delete all selected records</li>" +
"<li>double-click a record in the grid to edit inline (press Return, or arrow/tab to another record, to save)</li>" +
"</ul>"
}),
// databound ListGrid
// * click records to edit in boundForm and view in boundViewer
// * double-click record to edit inline (Return or arrow/tab off current row to save)
ListGrid.create({
ID:"boundList",
autoDraw: false,
dataSource: empresaTipoDMI,
showAllRecords:true,
height:200,
canEdit:true,
selectionChanged : function (record, state) {
if (this.selection.anySelected()) {
deleteBtn.enable();
saveBtn.setDisabled(this.selection.multipleSelected());
boundForm.editRecord(record);
boundViewer.viewSelectedData(this);
} else {
deleteBtn.disable();
saveBtn.disable();
}
}
}),
// databound SearchForm
// * click boundList records to edit
SearchForm.create({
ID:"boundForm",
autoDraw: false,
dataSource: empresaTipoDMI,
numCols:"2",
autoFocus:false
}),
// toolbar to perform various actions using the boundForm values (see helpText above)
Toolbar.create({
autoDraw:false,
membersMargin:10,
buttonConstructor: "IButton",
height: 22,
buttons:[
{title:"Save", click:"boundForm.saveData()", ID:"saveBtn"},
{title:"Clear", click:"boundForm.clearValues();boundForm.editNewRecord();saveBtn.enable()"},
{title:"Filter", click:"boundList.filterData(boundForm.getValuesAsCriteria());"},
{title:"Fetch", click:"boundList.fetchData(boundForm.getValuesAsCriteria());"},
{title:"Delete", ID:"deleteBtn", disabled: true, click:"boundList.removeSelectedData();boundList.deselectAllRecords()"}
]
}),
// databound DetailViewer
// * click boundList records to display
DetailViewer.create({
ID:"boundViewer",
autoDraw: false,
dataSource: empresaTipoDMI
})
]
});
boundList.filterData();
</SCRIPT>
</BODY>
</HTML>
My datasource
<DataSource
ID="empresaTipoDMI"
serverType="generic"
testFileName="empresaTipoDMI.data.xml">
<fields>
<field sqlType="integer" name="EmpresaTipoId" type="sequence" title="Tipo de Empresa" length="128" primaryKey="true"></field>
<field sqlType="varchar" name="Descripcion" type="text" title="Descripcion" length="128" required="true"></field>
</fields>
<serverObject lookupStyle="new" className="dmi.EmpresaTipoDMI"/>
</DataSource>
My manager class is:
package dmi;
import java.util.List;
import java.util.Map;
import model.EmpresaTipoVO;
import business.EmpresaTipoBO;
import com.isomorphic.datasource.DSRequest;
import com.isomorphic.datasource.DSResponse;
import com.isomorphic.log.Logger;
import com.isomorphic.util.DataTools;
public class EmpresaTipoDMI {
Logger log = new Logger(EmpresaTipoDMI.class.getName());
// By default, for a DSRequest of type "fetch", a method named "fetch" is invoked. You can
// customize this via the <serverObject> declaration.
public DSResponse fetch(DSRequest dsRequest) throws Exception {
System.out.println("procesing DMI fetch operation");
DSResponse dsResponse = new DSResponse();
EmpresaTipoBO empresaTipoBO = new EmpresaTipoBO();
// Fetch a List of matching SupplyItem Beans from some pre-existing Java object model
// provided by you, represented by "SupplyItemStore" in this example
EmpresaTipoVO empresaTipoVO = new EmpresaTipoVO();
if(dsRequest.getFieldValue("empresaTipoId") != null) {
System.out.println("4");
empresaTipoVO.setEmpresaTipoId((Integer)dsRequest.getFieldValue("empresaTipoId"));
} else {
System.out.println("5");
empresaTipoVO.setEmpresaTipoId(null);
}
System.out.println("6");
if(dsRequest.getFieldValue("descripcion") != null) {
System.out.println("7");
empresaTipoVO.setDescripcion((String)dsRequest.getFieldValue("descripcion"));
} else {
System.out.println("8");
empresaTipoVO.setDescripcion(null);
}
List empresaTipoList = empresaTipoBO.sel(empresaTipoVO);
long startRow = dsRequest.getStartRow();
long endRow = dsRequest.getEndRow();
long totalRows = empresaTipoList.size();
// clamp endRow to available rows and slice out requested range
endRow = Math.min(endRow, totalRows);
System.out.println("startRow = " + startRow);
System.out.println("endRow = " + endRow);
List results;
if (totalRows > 0) {
results = empresaTipoList.subList((int) startRow, (int) endRow);
} else {
results = empresaTipoList;
}
// DataSource protocol: return matching item beans
dsResponse.setData(results);
// tell client what rows are being returned, and what's available
dsResponse.setStartRow(startRow);
dsResponse.setEndRow(25);
dsResponse.setTotalRows(totalRows);
System.out.println("dsResponse.getStartRow() = " + dsResponse.getStartRow());
System.out.println("dsResponse.getEndRow() = " + dsResponse.getEndRow());
System.out.println("dsResponse.getTotalRows() = " + dsResponse.getTotalRows());
return dsResponse;
}
// Declared parameters of the method are automatically provided. For example, if your
// method declares a parameter of type HttpServletRequest, the current HttpServletRequest
// will be passed.
// If you declare a parameter that is a Java Bean, SmartClient will create an instance of
// the bean and apply the DSRequest data to the bean via Java reflection, matching
// DataSource fields to Java setter methods. For example, for the DataSource field
// "itemName", SupplyItem.setItemName() is called.
public EmpresaTipoVO add(EmpresaTipoVO empresaTipoVO) throws Exception {
log.info("procesing DMI add operation");
EmpresaTipoBO empresaTipoBO = new EmpresaTipoBO();
// most ORM systems can store a new Object with a single call like this.
empresaTipoBO.add(empresaTipoVO);
// return the record-as-saved so SmartClient can update client-side caches. This
// pattern ensures client-side components receive server-generated fields (such as an
// auto-generated primaryKey value). SmartClient can then update caches in place
// instead of re-fetching data.
return empresaTipoVO;
}
// The "update" method declares a parameter of type "Map" and so receives DSRequest.data as
// a Java Map. For an "update" operation, the data includes updated fields and always
// includes the field declared as primaryKey:true.
public EmpresaTipoVO update(Map record) throws Exception {
log.info("procesing DMI update operation");
EmpresaTipoBO empresaTipoBO = new EmpresaTipoBO();
EmpresaTipoVO inputVO = new EmpresaTipoVO();
EmpresaTipoVO outputVO = new EmpresaTipoVO();
// look up the existing data by primary key
if(record.get("empresaTipoId") != null) {
inputVO.setEmpresaTipoId((Integer)record.get("empresaTipoId"));
} else {
inputVO.setEmpresaTipoId(null);
}
if(record.get("descripcion") != null) {
inputVO.setDescripcion((String)record.get("descripcion"));
} else {
inputVO.setDescripcion(null);
}
List empresaTipoList = empresaTipoBO.sel(inputVO);
if(empresaTipoList != null && empresaTipoList.size() > 0) {
outputVO = (EmpresaTipoVO) empresaTipoList.get(0);
}
// DataTools.setProperties() is a SmartClient API that applies a Map of properties to a
// Bean via reflection, matching Map keys to setter methods on the Bean.
DataTools.setProperties(record, outputVO);
// store it, and return the record-as-saved so SmartClient can update client-side caches.
empresaTipoBO.upd(outputVO);
return outputVO;
}
public EmpresaTipoVO remove(EmpresaTipoVO empresaTipoVO) throws Exception {
log.info("procesing DMI remove operation");
EmpresaTipoBO empresaTipoBO = new EmpresaTipoBO();
empresaTipoBO.del(empresaTipoVO);
// on a removal, just return
return empresaTipoVO;
}
}
My BO (DAO) class is:
public List<EmpresaTipoVO> sel(EmpresaTipoVO inputVO) throws DAOSysException {
// initialize variables
EmpresaTipoVO outputVO = null;
Connection con = null;
ResultSet rs = null;
PreparedStatement prepStmt = null;
ArrayList<EmpresaTipoVO> list = new ArrayList<EmpresaTipoVO>();
StringBuffer selectStatement = new StringBuffer();
selectStatement.append(EMPRESATIPO_SEARCH_SQL);
if (inputVO.getEmpresaTipoId() != null ) {
selectStatement.append(" AND EmpresaTipoId = " + inputVO.getEmpresaTipoId());
}
if (inputVO.getDescripcion() != null ) {
selectStatement.append(" AND Descripcion LIKE " + "'%" + inputVO.getDescripcion() + "%'");
}
try {
con = getConnection();
prepStmt = con.prepareStatement(selectStatement.toString());
rs = prepStmt.executeQuery();
while(rs.next()) {
// create the tranfer object using data from rs
outputVO = new EmpresaTipoVO();
outputVO.setEmpresaTipoId(new Integer(rs.getInt(1)));
outputVO.setDescripcion(rs.getString(2));
// add the TO to the list
list.add(outputVO);
}
} catch (SQLException sqle) {
// handle exception
// sqle.printStackTrace();
StringBuffer sb = new StringBuffer();
sb.append("==> SQLException: ");
while (sqle != null) {
sb.append("Message: " + sqle.getMessage());
sb.append(", ");
sb.append("SQLState: " + sqle.getSQLState());
sb.append(", ");
sb.append("ErrorCode: " + sqle.getErrorCode());
sqle = sqle.getNextException();
}
throw new DAOSysException(sb.toString());
} catch (Exception e) {
// handle exception
// e.printStackTrace();
StringBuffer sb = new StringBuffer();
sb.append("==> Exception: ");
sb.append("Message: " + e.getMessage());
throw new DAOSysException(sb.toString());
} finally {
// close connection
closeAll(con, prepStmt, rs);
}
return list;
}
The value object is:
public class EmpresaTipoVO implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
// public members
public Integer empresaTipoId;
public String descripcion;
// default constructor
public EmpresaTipoVO() { }
// constructor accepting all values
public EmpresaTipoVO(Integer empresaTipoId, String descripcion) {
init(empresaTipoId, descripcion);
}
// constructor to create a new TO based
// using an existing TO instance
public EmpresaTipoVO(EmpresaTipoVO empresatipoVO) {
init(empresatipoVO.empresaTipoId, empresatipoVO.descripcion);
}
// method to set all the values
public void init(Integer empresaTipoId, String descripcion) {
setEmpresaTipoId(empresaTipoId);
setDescripcion(descripcion);
}
// getter methods
// accessor methods
public Integer getEmpresaTipoId() {
return empresaTipoId;
}
public String getDescripcion() {
return descripcion;
}
// setter methods
// mutator methods
public void setEmpresaTipoId(Integer anEmpresaTipoId) {
if (anEmpresaTipoId == null) {
empresaTipoId = null;
} else {
empresaTipoId = anEmpresaTipoId;
}
}
public void setDescripcion(String aDescripcion) {
if (aDescripcion == null) {
descripcion = null;
} else {
descripcion = aDescripcion;
}
}
public String toString() {
return "{ empresaTipoId=" + empresaTipoId + "; descripcion=" + descripcion + " }";
}
}
The empresaTipoList in the manager class is:
results = [{ empresaTipoId=0; descripcion=Empresa de Transporte Canacar }, { empresaTipoId=1; descripcion=Empresa de Transporte Individual }, { empresaTipoId=2; descripcion=Empresa de Transporte Filial }, { empresaTipoId=3; descripcion=Empresa de Transporte de Personal }, { empresaTipoId=4; descripcion=Empresa de Transporte de Autotanques }, { empresaTipoId=5; descripcion=Empresa de Transporte Especializada }, { empresaTipoId=6; descripcion=Empresa de Transporte Conatram }, { empresaTipoId=7; descripcion=Empresa de Transporte de Mudanzas }, { empresaTipoId=8; descripcion=Empresa de Trransporte Publico }, { empresaTipoId=9; descripcion=Empresa de Transporte Ferroviaria }, { empresaTipoId=10; descripcion=Empresa de Transporte Maritima }, { empresaTipoId=11; descripcion=Empresa de Logistica }, { empresaTipoId=12; descripcion=Empresa de Transporte Aereo }, { empresaTipoId=13; descripcion=Agente Aduanal Nacional }, { empresaTipoId=14; descripcion=Agente Aduanal Internacional }, { empresaTipoId=15; descripcion=Empresa de Carga Regular }, { empresaTipoId=16; descripcion=Empresa de Manufactura Automotriz }, { empresaTipoId=17; descripcion=Empresa de Manufactura Alimenticia }, { empresaTipoId=18; descripcion=Empresa Comercio Nacional }, { empresaTipoId=19; descripcion=Empresa Comercio Internacional }, { empresaTipoId=20; descripcion=Empresa de Manufactura en General }, { empresaTipoId=21; descripcion=Empresa de Industria Minera / Metalurgica }, { empresaTipoId=22; descripcion=Empresa de Industria Quimica }, { empresaTipoId=23; descripcion=Empresa deIndustria Construccion }, { empresaTipoId=24; descripcion=Empresa de Petroquimica }, { empresaTipoId=25; descripcion=Empresa Textil }]
I view the Developer Console and appears:
{
invalidateCache:false,
endRow:25,
data:[
{},
{},
{},
{},
{},
{},
{},
{},
{},
{},
{},
{},
{},
{},
{},
{},
{},
{},
{},
{},
{},
{},
{},
{},
{},
{}
],
status:0,
totalRows:26,
startRow:0,
isDSResponse:true
}
]//isc_RPCResponseEnd"
16:55:02.891:XRP7:INFO:RPCManager:rpcResponse(empresaTipoDMI_fetch)[fetch]: result: 26 records[status=0]
I am not able to see the data on the list grid. I am sure that I have 26 rows in the list grid but all of them are empty. I don´t know is my problem is in my manager (java class) or in my jsp or in the datasource definition.
I read that startRow and endRow is zero base. But I I assign endRow = Math.min(endRow, totalRows); the end row is 26 instead of 25 because there are 26 rows.
The code is deployed in apache-tomcat-5.5.20, jdk 1.6, SmartClient_70rc2_Evaluation
Please help me.