velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nathan Bubna" <nbu...@gmail.com>
Subject Re: Strange Caching Problem with Macros
Date Tue, 24 Jun 2008 02:32:20 GMT
can you replicate this with a simpler example at all?  it's a bit hard
to spot the tree in the forest. :)  it's not obvious to me what the
problem is, and i can't run your example, so it's rather hard to track
down.  could you also let us know what version of Velocity this is and
perhaps what your velocity.properties are when you experience this?

On Sun, Jun 22, 2008 at 4:55 AM, Steve O'Hara
<sohara@pivotal-solutions.co.uk> wrote:
>
> 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
>

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


Mime
View raw message