I hacked this into my Object.vm for OM class generation - in the foreach
loop for columns

#if($cjtype == "String")
    /**
     * Get the $cfc max size - 
     * This is the maximum length constraint on the DB Column.
     * 
     * @return int
     */
     public int get${cfc}Max()
     {
        return $col.Size;
     }     
#end

   /**
     * Get the $cfc required setting 
     * This is the NOT NULL constraint on the DB Column.
     * 
     * @return boolean
     */
     public boolean get${cfc}Required()
     {
        return $col.isNotNull();
     }

Then each column has an getColRequired() method and if it is a VARCHAR
column it has a getColMax() method

and I can do this:
<input name="title" maxlength="$entry.TitleMax" value="$entry.Title">

or some such... and can also use some javascript in conjunction with the
$entry.TitleRequired return

It also makes validating stuff easier on the server side. 

Torque Rocks. 


-----Original Message-----
From: James Bullen [mailto:[EMAIL PROTECTED]] 
Sent: Wednesday, May 01, 2002 3:23 PM
To: 'Turbine Users List'
Subject: accessing column metadata in templates



i want to use column metadata in my templates. a simple case is setting
the maxlength attribute in an input element in a form.

eg.
in the sample app schema:
    <column name="TITLE" size="255" type="VARCHAR"/>

defines the Title column for the Rdf object and says it has a size of
255. it seems reasonable to want to access that metadata in a form to
set maxlength. i couldn't see any examples of this, nor any discussion
in the archive. you can use intake to define a maxlength but this is
done server-side (requiring a roundtrip to enforce), and duplicates the
definition.

so i want another approach. i tried putting a TableMap in the context in
Form.java

            TableMap tabmap = RdfPeer.getTableMap();
            context.put("tabmap", tabmap);

(which required making getTableMap public - the first hint i was heading
in the wrong direction ;)

then, in theory, in Form.vm i could say something like:

    #set ( $col = $tabmap.getColumn("TITLE") )
    <input name="title" maxlength="$col.getSize()" value="$entry.Title">

unfortunately getSize() always returns 0 ... i haven't investigated this
further because i feel like i'm off track.

does anyone have a good way to do this? it feels like the sort of ground
that should be well-trodden ...

any help appreciated.


cheers,
james


--
To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to