4 Replies Latest reply on Oct 5, 2008 4:38 PM by twhitehead.twhiteheadjm.hotmail.com

    Email attachments and custom facelets composition components

    twhitehead.twhiteheadjm.hotmail.com

      I am trying to send a pdf attachment in an email. The pdfs are already being generated using p:document tags and are working fine.
      The seam documentation said I could send pdf attachments by simply putting my p:document inside the m:attachment
      However, in my pdfs I have used my own custom facelets composition components and instead of being rendered properly (as they do in the pdfs) they simply get placed as text in the pdf attachment.


      Here is my email:


      <m:message xmlns="http://www.w3.org/1999/xhtml" 
      xmlns:ui="http://java.sun.com/jsf/facelets" 
      xmlns:m="http://jboss.com/products/seam/mail"
      xmlns:h="http://java.sun.com/jsf/html" 
      xmlns:s="http://jboss.com/products/seam/taglib" 
      xmlns:p="http://jboss.com/products/seam/pdf"
      xmlns:f="http://java.sun.com/jsf/core" 
      xmlns:c="http://java.sun.com/jstl/core" 
      xmlns:val="http://www.virtualfm.co.za/jsf">
      ...
      from, to, subject
      ...
      <m:attachment fileName="MyFile.pdf" contentType="application/pdf">
           <p:document  pageSize="A4">
                <val:pdfH1 value="My Heading" />                       
           </p:document>
      </m:attachment>
      <m:body>
      <p>Some text</p>          
      </m:body>
      </m:message>
      



      and the val:pdfH1 file


      <ui:composition  xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:p="http://jboss.com/products/seam/pdf">
           <p:font size="20"  color="#004080" style="bold">
                <p:paragraph spacingAfter="10">#{value}</p:paragraph>
           </p:font>  
      </ui:composition>



      The attached pdf is rendered as


      <val:pdfH1 value="My Heading"></val:pdfH1 value="My Heading"> 



      If I put the contents of my tag directly into the email then it renders correctly.


      I dont want to have to redo all my reports specifically formated for the email.


      What I want to do is:


      <m:attachment fileName="MyFile.pdf" contentType="application/pdf">
           <ui:include src="alreadyExistingReport.xhtml" />
      </m:attachment>



        • 1. Re: Email attachments and custom facelets composition components
          twhitehead.twhiteheadjm.hotmail.com

          I see my problem has been fixed in 2.1.0.BETA
          JIRA - JBSEAM-3014


          So I am trying to upgrade to that but cant seem to get past this error:


          java.lang.IllegalStateException: duplicate factory for: org.jboss.seam.web.webSession (duplicate is specified in components.xml)




          I have two ear projects and one is upgraded and working, the other gives the above error. The components.xml files are identical in both projects.


          components.xml:



          <?xml version="1.0" encoding="UTF-8"?>
          <components xmlns="http://jboss.com/products/seam/components"
                xmlns:core="http://jboss.com/products/seam/core"
                xmlns:persistence="http://jboss.com/products/seam/persistence" 
                xmlns:security="http://jboss.com/products/seam/security"
                xmlns:mail="http://jboss.com/products/seam/mail"
                xmlns:pdf="http://jboss.com/products/seam/document"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                xsi:schemaLocation=
                     "http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.1.xsd 
                     http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.1.xsd 
                     http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.1.xsd
                     http://jboss.com/products/seam/mail http://jboss.com/products/seam/mail-2.1.xsd
                     http://jboss.com/products/seam/document http://jboss.com/products/seam/document-2.1.xsd
                     http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.1.xsd">
                <core:init debug="true" jndi-pattern="@jndiPattern@"/>
                <core:manager concurrent-request-timeout="500" 
                 conversation-timeout="120000" 
                 conversation-id-parameter="cid"
                 parent-conversation-id-parameter="pid"/> 
                <persistence:managed-persistence-context name="entityManager"
                         auto-create="true"
                         persistence-unit-jndi-name="java:/crsEntityManagerFactory"/>  
                
                <security:identity authenticate-method="#{authenticator.authenticate}" remember-me="false"/>
                
                <event type="org.jboss.seam.security.notLoggedIn">
                     <action execute="#{redirect.captureCurrentView}"/>
                </event>
                <event type="org.jboss.seam.security.loginSuccessful">
                     <action execute="#{redirect.returnToCapturedView}"/>
                </event>
                
                <mail:mail-session host="smtp.gmail.com" port="587" username="username" password="password" tls="true"/>
               <pdf:document-store use-extensions="true" error-page="/pdfMissing.seam" />
          </components>



          • 2. Re: Email attachments and custom facelets composition components
            twhitehead.twhiteheadjm.hotmail.com

            I found that the error is because jboss is creating a temporary copy of jboss-seam.jar as can be seen here



            08:39:39,953 INFO  [Initialization] reading jar:file:/C:/dev/jboss-4.2.2.GA/server/default/deploy/crs-ear.ear/jboss-seam.jar!/META-INF/components.xml
            08:39:39,953 INFO  [Initialization] reading jar:file:/C:/dev/jboss-4.2.2.GA/server/default/tmp/deploy/tmp6667jboss-seam.jar!/META-INF/components.xml
            08:39:39,953 INFO  [Initialization] reading jar:file:/C:/dev/jboss-4.2.2.GA/server/default/deploy/crs-ear.ear/crs.war/WEB-INF/lib/jboss-seam-ioc.jar!/META-INF/components.xml
            08:39:39,953 INFO  [Initialization] reading jar:file:/C:/dev/jboss-4.2.2.GA/server/default/deploy/crs-ear.ear/crs.war/WEB-INF/lib/jboss-seam-remoting.jar!/META-INF/components.xml
            08:39:39,953 INFO  [Initialization] reading jar:file:/C:/dev/jboss-4.2.2.GA/server/default/deploy/crs-ear.ear/crs.war/WEB-INF/lib/jboss-seam-ui.jar!/META-INF/components.xml
            



            so I moved the following lines out of the jboss-seam.jar components.xml into my own components.xml



            <factory name="org.jboss.seam.web.webSession" auto-create="true" scope="stateless" value="#{org.jboss.seam.web.session}" />
            
            <factory name="facesMessages" auto-create="true" scope="stateless" value="#{org.jboss.seam.international.statusMessages}" />
             
            <factory name="org.jboss.seam.faces.facesMessages" auto-create="true" scope="stateless" value="#{org.jboss.seam.international.statusMessages}" />
            



            and it is now starting up.


            However, both apps, one with the above fix and one without, give another error when I attempt to send email:



            08:50:18,484 WARN  [lifecycle] executePhase(RENDER_RESPONSE 6,com.sun.faces.context.FacesContextImpl@d92bd2) threw exception
            java.lang.IllegalStateException: Application was not properly initialized at startup, could not find Factory: javax.faces.application.ApplicationFactory



            • 3. Re: Email attachments and custom facelets composition components
              pmuir

              FYI I fixed the duplicate factory problem in trunk after CR1.


              Can you file a JIRA issue for your remaining problem?

              • 4. Re: Email attachments and custom facelets composition components
                twhitehead.twhiteheadjm.hotmail.com

                I had to go back to seam 2.0.3 as I could not get email to work at all with 2.1.0


                I will have another go next week and see if the problem still exists.


                I do want to move to 2.1.0 as I would like to do pdf attachments, use my own tags in email, and do asynchronous mail.


                I also want to try out the new authentication stuff.