velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Steve O'Hara" <soh...@pivotal-solutions.co.uk>
Subject Strange Caching Problem with Macros
Date Sun, 22 Jun 2008 11:55:34 GMT
I'm getting a problem when caching is turned on whereby a method call is
not being run consistently.

I have a macro as per below;

    #macro(macroShowGrid $FieldNames $SortFieldName)
 
#set($Rows=$Entity.getConstituentGrid($FieldNames,$SortFieldName))
        #if ($PreviousBrand)
#set($OldRows=$PreviousBrand.getConstituentGrid($FieldNames,$SortFieldNa
me)) #end
        #set($FieldNames=$utils.splitToList($FieldNames,","))
        
        #foreach($Row in $Rows)
            <tr>
                #foreach($Field in $FieldNames)
                    #if ($velocityCount==1) #macroWriteImage($Row $Field
"") #end
                    <td
style="background-color:white;vertical-align:top;">
                        #if ($velocityCount==1)
                            #set($Number=$Row.get($Field))
                            #if($Number.matches("[0-9]+"))
 
#set($Url="$AppPath/$PageType/explorer?datasrc=$DataSource&new&view=bran
d&key=$Number")
                            #else
 
#set($Url="$AppPath/$PageType/explorer?datasrc=$DataSource&new&view=inde
x&minutenumber=$Number")
                            #end
                            <a href="$Url" target="_blank"
#macroMouseOver("View this record")>$Row.get($Field)</a>
                        #else
                            $Row.get($Field)
                        #end
                    </td>
                #end
            </tr>
        #end
    #end

This macro is called from with another macro;

    #macro(macroShowProductIngredients $FieldName $FieldTitle
$FieldComment $FieldList $FieldOrder)
        #if ($Entity.getValue($FieldName).length()>0 ||
$Entity.getValue($FieldComment).length()>0)
        <table border="1" bordercolor="#CDCB99" cellspacing="0"
cellpadding="3" bgcolor="#E2E0C8"
style="margin-top:8px;margin-left:4px">
            <tr>
                <td colspan="5">$FieldTitle</td>
            </tr>
            <tr>
                #set($Fields=$utils.splitToList($FieldList,","))
                <td nowrap width="100" colspan="2"align="center">Minute
Number</td>
                <td nowrap width="100%">Description</td>
                <td nowrap align="center">Level (%)</td>
                <td nowrap width="150" align="left">Supplier</td>
            </tr>
            #macroShowGrid($FieldList $FieldOrder)
            #set($PreviousFieldValue="")
            #set($FieldValue="")
            #if ($PreviousBrand)
#set($PreviousFieldValue=$PreviousBrand.getValue($FieldComment)) #end
            #set ($FieldValue=$Entity.getValue($FieldComment))
            #if ($FieldValue.length()>0 || $PreviousFieldValue.length>0
|| $PreviousBrand)
                <tr>
                    <td bgcolor="#FFFFFF" valign="top" colspan="5">
                        #macroShowValue($FieldValue $PreviousFieldValue)
                    </td>
                </tr>
            #end
        </table>
        #end
    #end



All works fine when caching is turned off but when I turn it on, the
method call $Entity.getConstituentGrid($FieldNames,$SortFieldName) is
not being run.  The value of $Rows is always undefined.  I say always, I
don't mean always, it seems to be a bit intermittent.
These macros are inline and I'm using a custom file based resource
loader.

My understanding of caching was that it cached the structure of the
template in an AST, not the contents?
I've checked that the $Entity object is valid, which it is and that it
has a different Class ID each call, which it does which would indicate
the Context is definitely getting given a different Entity each call.
The parameters are correct for the call too.

Thanks,
Steve




---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org


Mime
View raw message