Monday, June 30, 2008

New 'EvalAtPrint' attribute in CFDocumentItem

A new evalAtPrint attribute has been added to cfdocumentitem tag in ColdFusion 801 which is applicable when the item type is header or footer. The default value of this attribute is false.

Note: The cfdocumentitem behavior with the default evalAtPrint value is identical to the behavior in ColdFusion MX 7, but differs from the behavior of the ColdFusion 8 release.

When the evalAtPrint attribute value is false, the default value, ColdFusion evaluates the cfdocumentitem tag body at the same time when it is processing the cfdocument tag. This is the behavior identical to CFMX7. In this case you can use CFDocument variables (TotalPageCount, CurrentPageNumber, TotalSectionpageCount and CurrentSectionpageNumber) only inside cfoutput and not in any expression because the page numbers are not known unless the cfdocument body content is evaluated and layed out.

In order to use CFDocument variables in expression inside CFDocumentItem tagbody, you should set evalAtPrint to true as shown in the following example.

<cfdocument format="pdf">
<cfdocumentitem type="header" evalAtPrint="true">
<cfif (CFDocument.currentPageNumber % 2 eq 0)>
<cfoutput> Page is even</cfoutput>
<cfelse>
<cfoutput> Page is odd</cfoutput>
</cfif>
</cfdocumentitem >
Document body…
</cfdocument>

In this case, ColdFusion evaluates the cfdocumentitem tag body when it prints the header or footer, not when it evaluates the cfdocument tag body. This ensures that the cfdocument tag body is already evaluated and layed out and page number information is available when cfdocumentitem tag is being evaluated

A side effect of this is, if a variable is used inside both cfdocument and cfdocumentitem, cfdocumentitem tag will only see the final value of that variable. In the following example, cfdocumentitem will always get 11 as value of ‘I’ and hence all the headers will print ‘Chapter 11’.


<cfdocument format="pdf" >
<cfloop from=1 to=10 index="i">
<cfdocumentsection>
<cfdocumentitem type="header" >
<cfoutput>Chapter #i#</cfoutput>
</cfdocumentitem >
DocumentSection body
</cfdocumentsection>
</cfloop>
</cfdocument>

To handle this, you can now pass the variable into the cfdocumentitem tag as a custom attribute, as shown in the following example:

<cfdocument format="pdf" >
<cfloop from=1 to=10 index="i">
<cfdocumentsection>
<cfdocumentitem type="header" evalAtPrint="true" no = #i#>
<cfoutput>Chapter #attributes.no#</cfoutput>

<cfif (CFDocument.currentPageNumber % 2 eq 0)>
<cfoutput> Page is even</cfoutput>
<cfelse>
<cfoutput> Page is odd</cfoutput>
</cfif>
</cfdocumentitem >
Document Body.
</cfdocumentsection>
</cfloop>
</cfdocument>

CFUnited Presentation - All about CFThread

I did a presentation on "All about CFThread" at CFUnited this year and I think it went fairly well. It was a repeat session - once on friday 21st June and another on Saturday 22nd June and both the sessions had pretty good number of people attending it. Thanks a lot to all those attended. As promised, I have uploaded my presentation and the sample code up here.

Please feel free to ask me questions if you have any.

Friday, June 27, 2008

Back from hiatus

I took a long long break from blogosphere and now that I am rejuvenated after CFUnited, I am back. :-) Thinking about it, it was a really long break - my last post was on Feb 18th which makes it 4 months. So what did I do in those last 4 months? Well lot of things ;-)

  • I GOT MARRIED :-) So thats the biggest thing that happened. I took a one month long vacation to get married, went to Mauritius for my honeymoon and we had a really great time. Here is one of our pics. In case you want to see more of these, you can head over to Flickr. :D

 

  • There was a more than one month long Cricket series called "Indian Premier League" and I watched each and every match ;-)
  • All of us in the ColdFusion team were quite busy (and still are) in research, planning and implentation for the Centaur. In other words, I was working for you guys.

Now that I am back, you should see some regular posts from me. The next one goes in a while.