Announcement Announcement Module
Collapse
No announcement yet.
Working with null views Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Working with null views

    I need to generate a pdf at the end of a series of state transitions. Scanning the documentation indicates that a 'null view' seems to be the correct way to do this (2.6.1.7, seems almost to have an example). I can see how to create the 'null view', but I'm unsure how the create the associated action bean.

    Code:
            <view-state id="displayPdf">
                <render-actions>
                    <action bean="pdfWriter" method="write"/>
                </render-actions>
            </view-state>
    Can anyone provide an example action that would write the content to a binary stream?

    -k.

  • #2
    In this case your action have to get access to the HttpServletResponse to write out the PDF data. To do that you'll have to downcast the external context to ServletExternalContext. Here is some code:

    Code:
    public class PdfAction extends AbstractAction {
    	
    	@Override
    	protected Event doExecute(RequestContext context) throws Exception {
    		byte[] pdfData = ...;
    		
    		ServletExternalContext externalContext = (ServletExternalContext)context.getExternalContext();
    		externalContext.getResponse().setContentType("application/pdf");
    		externalContext.getResponse().getOutputStream().write(pdfData);
    		
    		return success();
    	}
    }
    The downside to doing this is that your flow is now HTTP servlet specific, i.e. you cannot reuse it in a portlet environment for instance. That might ofcourse not be a problem for your case.

    Erwin

    Comment


    • #3
      What if it is a problem and I can't be sure I'm in a servlet container?

      Comment


      • #4
        In that case it's best to factor out the "environment specific behavior" into a FlowExecutionListener, like suggested here:

        http://www.ervacon.com/products/swf/tips/tip3.html

        Erwin

        Comment

        Working...
        X