You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Hugo Madureira <hm...@telbit.pt> on 2006/08/22 18:25:10 UTC

Ajax Cocoon Forms

Hello all!

I need to use Cocoon Forms with Ajax Requests. I don't want to have a 
whole page with the form. Instead, I need to use a div to hold the forms 
and use the Cocoon Forms using Ajax Requests. The problem is that the 
forms block include .js files in the html head tag and this can't be 
done using Ajax.

Is there a way to do this or to find all the .js files needed to load?

Thanks in advance,
Hugo Madureira

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


a Servelt call a Cocoon

Posted by rachid harradi <ra...@gmx.net>.
how  can i proviede a Sitemape,which receives data by HTTP and  represents  by means of transformer in HTML?.

my TestApplet 

StringBuffer uri = new StringBuffer("http://localhost:8080/cocoon/ameli/index.html");
    		BufferedReader br = null;
//    		"http://localhost:8080/Acocoon/servlet/TestServlet"
    	try {
                URL url=new URL(uri.toString());
//	    		 URL url=new URL("http://localhost:8080/cocoon/ameli/");
                URLConnection con = url.openConnection();

                // Prepare for both input and output
                con.setDoInput(true);
                con.setDoOutput(true);

                // Turn off caching
                con.setUseCaches(false);

                // Set the content type to be java-internal/classname
                con.setRequestProperty("Content-type","application/x-www-form-urlencoded ;charset=ISO-8859-1");

                // Write the serialized object as post data
                ObjectOutputStream out = new ObjectOutputStream(con.getOutputStream());
                out.writeObject(field_DescriptionsDoc);
                
//              InputStream in =con.getInputStream();
//              ObjectInputStream ois = new ObjectInputStream(in);
//           //
////              //Get reply from servlet
//              String reply = ois.readObject().toString();
//
//              //Show the corresponding message or redirect the user to the
//              //next page.
//              
//              System.out.println("the reply is: " + reply);
//              
//              oos.close();
//              ois.close();
                out.flush();
                out.close();


my Sitemape is


<?xml version="1.0" encoding="ISO-8859-1"?>
<map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">

<!--map:components>
   <map:generators>
      <map:generator name="objectionHTML" src="org.apache.cocoon.generation.StreamGenerator"/>
   </map:generators>

</map:components-->
	<!--map:pipelines>
		
			<map:pipeline match="/index.html">
			
			<map:act type="request">
    			<map:parameter name="parameters" value="true"/>
    			<map:generate src="http://my.server.com/path/to/my/servlet{requestQuery}"/>  
 		    </map:act>
			</map:pipeline>
	</map:pipelines-->
	<map:pipelines>
		<map:pipeline>
 			<map:match pattern="index.html/">
    			<map:generate type="stream"/>
    			<map:transform src="stylesheets/objection04.xslt"/>
    			<map:serialize type="html"/>
   			</map:match>
   			<!--map:pipeline match="">
  				<map:generate src="http://localhost:8080/Acocoon/servlet/TestServlet"/>
  				
  				<map:transform src="stylesheets/objection04.xslt"/>
    			<map:serialize type="html"/-->
			</map:pipeline>
		</map:pipelines>
</map:sitemap>

I would like to be shown HTML representation : automatic
-- 


Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen!
Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Ajax Cocoon Forms

Posted by Toby <to...@linux.it>.
Hugo Madureira wrote:
> I don't want to have a whole page with the form. Instead, I need to
> use a div to hold the forms and use the Cocoon Forms using Ajax
> Requests. The problem is that the forms block include .js files in the
> html head tag and this can't be done using Ajax.

I had a similar problem: I included some forms with CIncludes, so the
XSLT that would add the .js files to the head section would operate on a
snippet of a page and didn't even see a head tag.

I solved the problem by moving the XSLT transformer into the main
pipeline, so that it now operates on the whole page, after the
CIncludes, so it sees both the head section and the different forms.

Your situation is a bit more difficult though, as you probably haven't
even created the forms at the time when the page is sent to the browser.

I can see two solutions.  

The safer one, although more difficult, is to create a dummy head tag in
your forms' .jx files, so that the transformer can add the required .js
links to the Ajax response.  Then modify your form-loading Ajax code so
that it extracts the fake head section from the Ajax response and does
something appropriate with the .js files, such as adding them to the
real head section using DOM or some other trick.

The easier solution would be to add the needed .js files statically to
all your pages.

> find all the .js files needed to load

Just look for templates that match "head" in the various
src/blocks/forms/java/org/apache/cocoon/forms/resources/forms-*.xsl
(and other templates called by them.)

Keep in mind that the list of needed .js files varies depending on what
components you use in your forms.  You might even have to recreate some
of the logic in those XSLTs in client-side javascript, for example if
those templates add a few custom lines of script to the head section
depending on the particular form.


Toby

-- 
Signed/encrypted mail welcome.  GPG/PGP Key-Id: 0x15C5C2EA

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org