Archive for August, 2004

js does xmlrpc

Posted 8/29/2004 By Jason

Today I explored some new (to me) technologies to support a feature I was playing with. On a complex form representing a row being edited in a database, I had several 1-to-many relationships that I wanted to edit (i.e. make additions to) without submitting the main form. It is an intranet application, so I have the ability to rely on the fact that users will be using IE, and js will be enabled.

From the usual bag of tricks, my initial thought was you could have javascript submit a hidden form in a non-visible frame, and have the results come back with some onLoad() js that would update the main form (even did a little flow diagram, will attach at the end of the post). But I remembered Harry mentioning using js and php to communicate by serializing data in mutually compatible formats. This is the scriptserver project which he blogged about a while back. Harry also sent me a link to this js library to implement xmlrpc.

I have to admit that I have not played around with xmlrpc to date (at least in terms of actually doing anything with the technology, I have read enough to have the gist of xmlrpc and SOAP). This is mainly because I kept asking my Unix admin at work to compile php with the xmlrpc extension, and he always complained that he could not get the extension to compiled on HP-UX. I have finally started to push for some Linux web servers at work, so that will not persist as an issue in the future. Anyway, I decided to play around with this javascript xmlrpc library and see what I could come up with.
Read the remainder of this entry »

Creative use of Data:Table

Posted 8/22/2004 By Jason

Harry recently blogged about the Data:Table component I wrote for WACT. His post talked about the common method of using the data:table tag, i.e. feed it a data set and have it generate a table, perhaps using some declarative markup in the template to modify the results. Used in this context, you can output nicely formatted HTML tables with minimal amounts of code.

I had an interesting problem recently that challenged the way I used the data:table component. I needed to display 18 months of data in a table. Each row represented a different item, and the months were to be laid out in the columns of the table.

When I started to work with the table, I initially started with the traditional style of putting all of the tags specifying the layout in the template. With just two months of data, it might have looked something like this:

<data:table from="tableData" autogen="n">
  <data:column name="itemdesc">
    <data:header>Description</data:header>
  </data:column>
  <data:group>
    <data:header>{$m1label}</data:header>
    <data:column name="m1val">
      <data:header>Value</data:header>
      <data:cell>{$m1val|number}</data:cell>
    </data:column>
    <data:column name="m1val2">
      <data:header>Input</data:header>
      <data:cell><input type="text" name="{$m1key}" value="{$m1val2|number}"></data:cell>
    </data:column>
  </data:group>
  <data:group>
    <data:header>{$m2label}</data:header>
    <data:column name="m2val">
      <data:header>Value</data:header>
      <data:cell>{$m2val|number}</data:cell>
    </data:column>
    <data:column name="m2val2">
      <data:header>Input</data:header>
      <data:cell><input type="text" name="{$m2key}" value="{$m2val2|number}"></data:cell>
    </data:column>
  </data:group>
</data:table>

You can see where the group of columns for month two is just a cut and paste with minor tweaks to the variables. While this worked fine, I knew this was not what I wanted to maintain for the long run. Ideally I could use a loop to specify the templates for a single month once and have it increment through the values, but the data:table component does not support other WACT looping structures inside of it (a list component), and WACT templates do not support variable variables that would be required to iterate over the months.
Read the remainder of this entry »

Stealth PHP Singletons

Posted 8/18/2004 By Jason

I explained a bit of my code in a post up on SitePoint that reminded me of one of my favorite bag of php tricks: associating a superglobal key reference with a class variable.

<?php
$this->_stack =& $_SESSION[NOTIFY_SESSION_KEY];
?>

This has the effect of making a “stealth” static member, as well as effectively making the class a singleton (i.e. every instance of the class will access and manipulate the same data, and is therefore equivalent).

The context of my post was explaining a session based user notification queue. I have been using WACT recently, so I included a helper method to return the queue as an ArrayDataSet.

So without further ado, here is the test case and code.

Read the remainder of this entry »

Math Tricks

Posted 8/14/2004 By Jason

Inspired by a wired article I googled for a Vedic Math tutorial.

I have always found these little math tricks interesting, mainly from the perspective of trying to figure out how they work. I think it is a kind of a mental excersize similar to figuring out a clever optimization algorithm in programming.

Anyway, this Vedic math reminded me of one of my favorite stories about a young Gauss (eminent 19th century contributor to mathematics and statistics) whose math teacher instructed them to add up the numbers from 1 to 100 on their slate to keep them quite and occupied for a while. The story continues that, much to the teacher