在Seam 1.1.1中,PDF视图就像应用程序中的任何其他页面一样:一个包含EL表达式的facelets模板,这些表达式将底层Seam组件的值绑定到页面上。因此,如果您已经了解Seam,生成PDF只需学习新的iText特定标签。
以下是一个简单的Seam PDF中的Hello示例
<p:document [=>xmlns:p=]"=>http://jboss.com/products/seam/pdf" title="Hello"> <p:paragraph>Hello #{user.name}!</p:paragraph> </p:document>
只需将此文档放入Seam项目的docroot目录中,然后像访问任何其他facelets页面一样访问页面。还有什么比这更简单吗?
对于更大的文档,我们可能需要将文档分成章节
<p:document [=>xmlns:p=]"=>http://jboss.com/products/seam/pdf" title="Hello"> <p:chapter number="1"> <p:title><p:paragraph>Hello</p:paragraph></p:title> <p:paragraph>Hello #{user.name}!</p:paragraph> </p:chapter> <p:chapter number="2"> <p:title><p:paragraph>Goodbye</p:paragraph></p:title> <p:paragraph>Goodbye #{user.name}.</p:paragraph> </p:chapter> </p:document>
当然,这个特性的真正用途是用于报告,所以我想您想知道如何渲染动态列表和表格。好吧,这是一个列表
<p:document [=>xmlns:p=]"=>http://jboss.com/products/seam/pdf" [=>xmlns:ui=]"=>http://java.sun.com/jsf/facelets" title="Hello"> <p:list style="numbered"> <[=>ui:repeat] value="#{documents}" var="doc"> <p:listItem>#{doc.name}</p:listItem> </[=>ui:repeat]> </p:list> </p:document>
这是一个表格
<p:document [=>xmlns:p=]"=>http://jboss.com/products/seam/pdf" [=>xmlns:ui=]"=>http://java.sun.com/jsf/facelets" title="Hello"> <p:table columns="3" headerRows="1"> <p:cell>name</p:cell> <p:cell>owner</p:cell> <p:cell>size</p:cell> <[=>ui:repeat] value="#{documents}" var="doc"> <p:cell>#{doc.name}</p:cell> <p:cell>#{doc.user.name}</p:cell> <p:cell>#{doc.size}</p:cell> </[=>ui:repeat]> </p:table> </p:document>
当然,还有很多其他功能可用:章节、锚点、字体等,但这应该足以让您了解这些新功能的风味。有关更多信息,请查看Seam 1.1.1中的示例。