wcwilson
01-23-2003, 11:53 AM
Hi again,
I am making the contacts sample app searchable and am running into an issue when I load in a different set of records (the same data set as contactdata.xml - just out of a database). If I do a query for first name or last name starts with w, I get back three rows that display correctly. If I then doe a query that brings back more rows, just the first three (because there were three rows in the first selection) and the last row show up. The rows in between don't appear until I resize the window (or anything else that causes a refresh). Here is my code for loadContacts(just in case I missed a command):
<method name="loadContacts">
var s = searchfield.getText();
searchsection.datapath.dataset.setQueryString({sea rchtext: s});
searchsection.datapath.dataset.doRequest();
</method>
Is there anything I am missing, or is this a bug?
--Wayne
I am not really familiar with the data API, but it
appears that might be a bug in B2. I tried making
a test case with the JDBCTest example, I added
a query parameter to allow you to request n rows
of data.
I then made a test case which re-sends the query like you did:
<canvas width="1000" height="800" debug="true">
<!-- setup HTTP datasource -->
<dataset name="xml" autorequest="true" id="xml"
src="http://www.beartronics.com:8080/examples/servlet/JDBCTest"/>
<class name="field" bgcolor="green" width="34" height="34">
</class>
<view>
<simplelayout axis="y" spacing="4"/>
<button onclick="parent.data(5)">Data 5</button>
<button onclick="parent.data(10)">Data 10</button>
<method name="data" args="n">
xml.setQueryString({nlines: n});
xml.doRequest();
</method>
<view fontstyle="bold">
<simplelayout axis="x" spacing="4"/>
<text width="100" name="name" label="name" />
<text width="40" name="age" label="age" />
<text width="200" name="job" label="job" />
</view>
<view datapath="xml:/sqldata/row">
<text bgcolor="#ffcccc" width="100" name="name" datapath="name/text()" />
<text bgcolor="#ffcccc" width="40" name="age" datapath="age/text()" />
<text bgcolor="#ffcccc" width="200" name="job" datapath="job/text()" />
<simplelayout axis="x" spacing="4"/>
</view>
</view>
</canvas>
And that does update properly when the buttons are clicked; clicking the first button shows five rows,
clicking the second button shows ten rows, and the clickng the first button again shows five rows. But this is in my development world, which has a large number of bugs fixed from the B2 release. Maybe try my example in your B2 world and see if it updates properly?
Someone needs to take a look at the contacts code and see if there is something else specifically that would prevent automatic updating of that window. Maybe you can send us a copy of your code in a zip file.
/* JDBCTest.java
*
*/
import java.io.*;
import java.text.*;
import java.util.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import org.jdom.*;
import org.jdom.output.*;
import com.bitmechanic.sql.*;
/**
* Example JDBC to XML conversion, talking to Postgres,
*
* Demonstrates use of JDBC connection pool as well.
* See http://www.bitmechanic.com/projects/jdbcpool/ for connection pool library
*
* @author Henry Minsky
*/
public class JDBCTest extends HttpServlet {
private ConnectionPoolManager pool;
private String alias = "jdbcalias";
public void init(ServletConfig config) throws javax.servlet.ServletException {
super.init(config);
// Setup connection pool
try {
//
// Reap stale connections every 2 minutes
pool = new ConnectionPoolManager(120);
pool.addAlias(alias, // pool name
"org.postgresql.Driver", //driver
"jdbc:postgresql:testdb", //url is jdbc:postgresql:DATABASE_NAME
"postgres", // user
"", // password
20, // maxconn
600, // idletimeout
600); // checkout timeout
} catch (Exception e) {
}
}
/*
CREATE TABLE "employees" (
"name" text,
"age" integer,
"job" text
);
--
-- Data for TOC Entry ID 3 (OID 34973)
--
-- Name: employees Type: TABLE DATA Owner: hqm
--
INSERT INTO "employees" ("name","age","job") VALUES ('fred frumble',33,'punch press operator');
INSERT INTO "employees" ("name","age","job") VALUES ('freda fertilizer',23,'farm hand');
INSERT INTO "employees" ("name","age","job") VALUES ('larry loser',43,'swill dispenser');
INSERT INTO "employees" ("name","age","job") VALUES ('godfrey mustard',33,'farm hand');
INSERT INTO "employees" ("name","age","job") VALUES ('keyser soze',38,'manager');
INSERT INTO "employees" ("name","age","job") VALUES ('pavel curtis',23,'rental agent');
INSERT INTO "employees" ("name","age","job") VALUES ('arno sacknusen',23,'librariant');
INSERT INTO "employees" ("name","age","job") VALUES ('listeria bradford',23,'cow wrangler');
INSERT INTO "employees" ("name","age","job") VALUES ('bardley bartles',23,'interpreter');
INSERT INTO "employees" ("name","age","job") VALUES ('louis king',26,'collaborator');
INSERT INTO "employees" ("name","age","job") VALUES ('boxcar bill',73,'laundry folder');
INSERT INTO "employees" ("name","age","job") VALUES ('legrange orton',87,'water softener');
INSERT INTO "employees" ("name","age","job") VALUES ('martin muldoon',27,'lazyboy recliner');
*/
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/xml");
PrintWriter out = response.getWriter();
String query = "SELECT name, age, job FROM employees";
String nlines = request.getParameter("nlines");
int nl = 100000;
if (nlines != null) {
try {
nl = Integer.parseInt(nlines);
} catch (NumberFormatException e) {
}
}
try {
Document doc = new Document();
Element root = new Element("sqldata");
doc.setRootElement(root);
Connection conn = DriverManager.getConnection(ConnectionPoolManager. URL_PREFIX + alias, null, null);
Statement stmt = conn.createStatement();
ResultSet resultset = stmt.executeQuery(query);
//Get the ResultSet information
ResultSetMetaData resultmetadata = resultset.getMetaData();
//Determine the number of columns in the ResultSet
int numCols = resultmetadata.getColumnCount();
while (resultset.next() && nl-- > 0) {
List elts = new ArrayList();
for (int i=1; i <= numCols; i++) {
//For each column index, determine the column name
String colName = resultmetadata.getColumnName(i);
//Get the column value
String colVal = resultset.getString(i);
//Output the name and value
Element elt = new Element(colName);
elt.setText(colVal);
elts.add(elt);
}
Element row = new Element("row");
row.setChildren(elts);
root.addContent(row);
}
resultset.close();
stmt.close();
conn.close();
XMLOutputter outputter = new XMLOutputter();
try {
outputter.output(doc, out);
}
catch (IOException e) {
out.println(e);
}
} catch (SQLException e) {
out.println(e);
}
}
}
wcwilson
02-03-2003, 09:59 AM
FYI, this issue goes away with the new release...
--Wayne
vBulletin® v3.8.4, Copyright ©2000-2012, Jelsoft Enterprises Ltd.