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.
Werner,
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"/>
<map:serialize/>
</map:match>
"borrowed" from the example in
http://marc.theaimsgroup.com/?l=xml-cocoon-users&m=100349922300307&w=2
How should do I do it in my HelloActionSX.java 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?
Struts-code:
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 {
myMapping.loadMapping(".../mapping.xml");
marshaller.setMapping(myMapping);
marshaller.marshal(helloForm);
}
catch ( MarshalException me) {
System.out.println("MarshalException: " + me.getMessage() );
}
catch ( ValidationException ve ) {
System.out.println("ValidationException: " + ve.getMessage() );
}
catch ( MappingException mapEx) {
mapEx.printStackTrace();
System.out.println("MappingException: " + mapEx.getMessage() );
}
finally {
//writer.close();
}
actionForward = mapping.findForward("hello");
return actionForward;
}
}
--
Dag
---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faq/index.html>
To unsubscribe, e-mail: <[EMAIL PROTECTED]>
For additional commands, e-mail: <[EMAIL PROTECTED]>