My goal is to create a PDF containing all the products ordered from my orderHome page.
The problem is that the @DataModel field from the OrderHome object can be accessed from the HTML view, but not for the PDF view. I've got the following Error :
/pdf/order/printOrder.xhtml @171,62 <c:forEach items="#{orderLines}"> Must evaluate to a Collection, Map, Array, or null.My question is : is there any problem with @DataModel (which is here in Conversation context, as its owner class) and PDF generated with <p:document/> tag ?
Here is the orderHome.xml file :
<ui:composition ... >
...
<rich:dataTable value="#{orderLines}" ...>
<rich:column ...>
...
</rich:column>
</rich:dataTable>
<h:commandButton value="#{messages['order.print']}" action="#{OrderHome.print()}"/>
...
</ui:composition>The OrderHome.java file :
@Name("orderHome")
public class OrderHome extends EntityHome<Order> {
...
@DataModel
protected List<OrderLine> orderLines;
...
@Override
protected void initInstance() {
super.initInstance();
initOrderProducts();
}
public void initOrderProducts() {
orderedProducts = getInstance().getOrderLines()
}
public void print() {
computeTotalOrder(); // specific method
}
private void computeTotalOrder() {
double total = 0;
for(final OrderLine orderLine : orderLines) {
total += orderLine.getPrice();
}
getInstance.setTotalOrder(total);
}
...
}The orderHome.page.xml file :
<?xml ...?>
<page ...>
<begin-conversation join="true" flush-mode="manual" />
<navigation from-action="#{orderHome.print()}">
<redirect view-id="/pdf/order/printOrder.xhtml"/>
</navigation>
</page>And finaly the printOrder.xhtml page :
<p:document ...>
...
<c:forEach items="#{orderLines}" var="orderLine">
...
</c:forEach>
...
</p:document>I've googled for a long time and already tried to replace my <h:commandButton> with some <s:link> or <a:commandButton>, but nothing changed ...