cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dag Nygaard>
Subject Re: Combining Cocoon and Struts
Date Thu, 03 Oct 2002 11:49:15 GMT
Werner Guttmann wrote:
> We have been using both of the following two options to establish a clean contract
> between Struts and Cocoon:
> - Use of XMLizable interface from within XSPs
> - Use of Castor XML
> In both cases, you would use Struts actions to go to the model and return you the
> data and bind it to a the HttpRequest/HttpSession. From there on, simply forward
> your request to a Cocoon pipeline which takes care of the (de)marshalling required
> to convert your object model to SAX events which are then processed further
> downstream.
> I hope this helps.
> Werner

Thanks to all of you who previous replied to my question! Alot of
"floating objects" became clearer.

I think I know what you are saying, in a broad sense. But since I am not
that drilled in Cocoon and Struts yet, I hope you (or somebody else?)
could assist us in the right directions a little bit more...
Note: We have already looked at a sucessful Struts-Cocoon combination
where Struts creates a xml-file and forwards control to a Cocoon
pipeline. OK, for research, but not for multiuser environment... :)

Given a new pipeline:
   <map:match pattern="myrequest">
     <map:generate type="request"/>
     <map:transform src="stylesheets/myrequest.xsl"/>
"borrowed" from the example in 

How should do I do it in my file? The code below is
from the version were we write the xml to a file between Struts and
Cocoon, slightly modified... The form contains two string-fields and a
submit button. The form entries are collected and written with
appropriate xml-tags, to the temp-file. Struts sends control to the
Cocoon-pipeline, which prestents the entries on a new page.
Should we marshal the request in the same way that we marshal the form?
Previously we used a FileWriter as ContentHandler-paramameter to the
marshal-construct. What should we use for the request,
SAXContentHandler?  Or, do we somehow just push out the request directly
to the Cocoon-pipeline?

public class HelloActionSX extends AbstStrutsActionBase {

   public ActionForward perform(
      ActionMapping mapping, 
      ActionForm form, 
      HttpServletRequest request, 
      HttpServletResponse response) throws IOException,ServletException
      // Where to go next    
      ActionForward actionForward = null;
      HelloForm helloForm = (HelloForm) form; // get the form bean
      // Do something with the form - i.e. extract the values
      String firstname = helloForm.getFirstName();
      String lastname = helloForm.getLastName();
      //-- load mapping
      //-- marshal the form
      Mapping myMapping = new Mapping();

      // FileWriter writer = new FileWriter("tempfile.xml");
*** How do we replace writer? With SAXContentHandler? with unmodified
request, i.e. convert the request in Cocoon? *****
      Marshaller marshaller = new Marshaller(writer);
      try {
      catch ( MarshalException me) {
         System.out.println("MarshalException: " + me.getMessage() );
      catch ( ValidationException ve ) {
         System.out.println("ValidationException: " + ve.getMessage() );
      catch ( MappingException mapEx) {
         System.out.println("MappingException: " + mapEx.getMessage() );
      finally {
      actionForward = mapping.findForward("hello"); 
      return actionForward;


Please check that your question  has not already been answered in the
FAQ before posting.     <>

To unsubscribe, e-mail:     <>
For additional commands, e-mail:   <>

View raw message