Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Enhancement: More methods for Velocity

    Hi Isomorphic,

    is there a list of all variables one could use in velocity expressions? I didn't find it in the docs. I'm looking for the members of $sessionAttributes (perhaps application server dependent?), $dsRequest, $dataSources and so on listed in http://www.smartclient.com/smartgwte...tySupport.html.

    Most likely I'm missing "$dataSources.DSNAME.getByUniqueField(String fieldName, String value)"-API in the velocity support.

    My use case is the following: See this USERS table definition:
    Code:
    CREATE TABLE t_login 
        ( 
         [B]id INTEGER[/B] NOT NULL, 
         [B]loginname VARCHAR2 (50 CHAR)[/B] NOT NULL, 
         passwdhash VARCHAR2 (64 CHAR) NOT NULL, 
         lastlogin DATE, 
         CONSTRAINT [B]PK_login PRIMARY KEY (id)[/B],
         CONSTRAINT [B]UC_login_loginname UNIQUE (loginname)[/B]
        );
    As Tomcat does not return something else than the user name entered in j_username, I don't have the user_id I'd need here:
    Code:
    <DataSource schema="myschema" dbName="Oracle" tableName="othertable" ID="T_LOGIN" serverType="sql">
    	<fields>
    		<field primaryKey="true" hidden="true" name="ID" type="sequence"></field>
    		<field name="...... />
    		<field name="...... />
    		<field name="...... />
    		<field name="MODIFIED_BY" required="true" hidden="true" type="int" [B]foreignKey="T_LOGIN.ID"[/B]></field>
    		<field name="MODIFIED_AT" required="true" type="datetime"></field>
    	</fields>
    	<operationBindings>
    		<operationBinding operationType="add">
    			<values fieldName="MODIFIED_BY" value="[B]need_id_here[/B]" />
    			<values fieldName="MODIFIED_AT" value="$currentDate" />
    		</operationBinding>
    		<operationBinding operationType="update">
    			<values fieldName="MODIFIED_BY" value="[B]need_id_here[/B]" />
    			<values fieldName="MODIFIED_AT" value="$currentDate" />
    		</operationBinding>
    	</operationBindings>
    </DataSource>
    While writing this text I got an idea: I'll use a fake-ds.xml for T_LOGIN with just the loginname and id columns, but define loginname as PK there. I should be able to use
    Code:
    $dataSource.T_LOGIN_FAKE.fetchById($sessionAttributes.username).ID
    then.

    But nevertheless my questions:

    Is there some detailed documentation on available velocity variables?
    Could you integrate the mentioned $dataSources.DSNAME.getByUniqueField-API?
    Is there some better approach for my use case than firing a velocity-fetch to the DB for each and every update/insert? Perhaps adding the user-id to the session?

    Thank you,
    Blama

    #2
    A variable such as $dsRequest is the DSRequest object, therefore you can use standard Velocity to access bean properties, call methods, etc - see Velocity docs for details.

    Note also dsRequest.addToTemplateContext().

    Comment

    Working...
    X