You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Timothy Larson <ti...@yahoo.com> on 2003/10/24 16:49:37 UTC

Fill woody repeater from flow

I guess I still do not completely grasp JavaScript.
It is easy enough from Java, but how would you
populate a repeater from a flowscript?
The context is I am trying to make a database query
by example person search form.

--Tim Larson


__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com

Re: Fill woody repeater from flow

Posted by Karel Vervaeke <ka...@pandora.be>.
Here's an example using binding:

function searchContact(form) {
  bean = {
    qryFirstName:"",
    qryLastName:"",
    qryAddress:"",
    qryPostalCode:"",
    qryCity:"",
    qryCountry:"",
    results: undefined // we'll set it later on
  };

  form.load(bean);
  form.showForm("woody/searchContact-query.xml");
  form.save(bean);
 
  // the next 7 lines are ugly, please disregard
  var wcps = new Packages.vd.util.WhereClausePartSet();
  if (bean.qryFirstName)  wcps.add("firstName" ,bean.qryFirstName+"%"  
,"like");
  if (bean.qryLastName)   wcps.add("lastName"  ,bean.qryLastName+"%"   
,"like");
  if (bean.qryAddress)    wcps.add("address"   
,bean.qryAddressName+"%","like");
  if (bean.qryPostalCode) wcps.add("postalCode",bean.qryPostalCode+"%" 
,"like");
  if (bean.qryCity)       wcps.add("city"      ,bean.qryCity+"%"       
,"like");
  if (bean.qryCountry)    wcps.add("country"   ,bean.qryCountry+"%"    
,"like");

  // the search function is backed up by hibernate's 'find'
  list = contactReg.search(wcps); // java.util.List

  bean.results = list.toArray();
 
  form.load(bean);
  form.showForm("woody/searchContact-results.xml");
}

Feedback is of coarse, welcome.
Karel


Re: Fill woody repeater from flow

Posted by Marc Portier <mp...@outerthought.org>.
Tim,

looks good

however, this got me thinking:

maybe we should get ourselves into making (declarative) binding support 
on java.sql.ResultSets, no?

The biggest catch however is the lack of symmetry in connecting to JDBC 
stuff: binding-back for the 'save is not to be done by handing over a 
resulset back to the jdbc connection :-(

Thoughts like these always kinda set me back on th etrack of just using 
some OR/mapping tool and stopping to think about it...

Still, making cforms (aka woody) easier for the jdbc-fans is a goal we 
should go for, and given the fact that the current implicit symmetry of 
the binding is limiting our thoughts we should maybe just set it asside 
and think allong other paths?

so, any thoughts on the subject dwelling out there?
-marc=


Timothy Larson wrote:

> --- Timothy Larson <ti...@yahoo.com> wrote:
> 
>>I guess I still do not completely grasp JavaScript.
>>It is easy enough from Java, but how would you
>>populate a repeater from a flowscript?
>>The context is I am trying to make a database query
>>by example person search form.
> 
> 
> Never mind.  Why do I figure things out right after I
> break down and ask about them? For posterity here is one,
> not necessarily efficient, way:
> 
> // Perform query and get results in ResultSet "result"
> //   Left as exercise for the reader.
> 
> // Clear the repeater
> while (0 in model.somewidget) { // While model.somewidget[0] exists
>   delete model.somewidget[0];
> }
> 
> // Populate the repeater
> while(result.next()) {
>   var field1 = result.getString("field1");
>   var field2 = result.getString("field2");
>   var max = model.people.length;
>   var row = model.people[max]; // Magically creates a new row
>   row.field1 = field1;
>   row.field2 = field2;
> }
> 
> --Tim Larson
> 
> 
> __________________________________
> Do you Yahoo!?
> The New Yahoo! Shopping - with improved product search
> http://shopping.yahoo.com
> 

-- 
Marc Portier                            http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
Read my weblog at              http://radio.weblogs.com/0116284/
mpo@outerthought.org                              mpo@apache.org


Re: Fill woody repeater from flow

Posted by Timothy Larson <ti...@yahoo.com>.
--- Timothy Larson <ti...@yahoo.com> wrote:
> I guess I still do not completely grasp JavaScript.
> It is easy enough from Java, but how would you
> populate a repeater from a flowscript?
> The context is I am trying to make a database query
> by example person search form.

Never mind.  Why do I figure things out right after I
break down and ask about them? For posterity here is one,
not necessarily efficient, way:

// Perform query and get results in ResultSet "result"
//   Left as exercise for the reader.

// Clear the repeater
while (0 in model.somewidget) { // While model.somewidget[0] exists
  delete model.somewidget[0];
}

// Populate the repeater
while(result.next()) {
  var field1 = result.getString("field1");
  var field2 = result.getString("field2");
  var max = model.people.length;
  var row = model.people[max]; // Magically creates a new row
  row.field1 = field1;
  row.field2 = field2;
}

--Tim Larson


__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com