cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeremy Quinn <jer...@media.demon.co.uk>
Subject Re: cvs commit: xml-cocoon/webapp/docs/samples/xsp cookie.xsp
Date Wed, 02 May 2001 18:16:56 GMT
At 10:52 PM +0200 30/4/01, giacomo wrote:
>Don't get me wrong. If someone come up with a markup that makes sense
>for action, transormers, whatever I'm +1 for implementing a
>MarkupForActionCompilationAction because I know the model of server
>pages is very convenient :)

OK, lets give it a go.

What can Actions do (please correct me here :)

	1. be passed named parameters
	2. set and get Request and Session properties

This is an entirely fictitious comment book example using the Crudlet TagLib.

In the first file, representing the Action, does all of the Bean creation,
setting Bean Properties automatically from form fields (via their
authenticating "editors"), copying in values from other places and writing
to the Space.

The second file, the XSP, outputs a few properties (as simple values and
blobs of XML) from Beans that are being transparently managed by the
Crudlet TagLib via the user's Session.

The Action

<?xml version="1.0"?>
<act:action
	xmlns:act="http://apache.org/cocoon/action/1.0"
  xmlns:xsp-request="http://apache.org/xsp/request"
  xmlns:crudlet="http://www.crudlet.org/cocoon/XSP/Crudlet/2.0"
>

	<!-- declare the Bean for this request -->
	<crudlet:bean name="comment" class="org.crudlet.CommentBook"
scope="request"/>

	<!-- assign matching form field names to Bean Properties (validates
internally) -->
	<crudlet:assign bean="comment" autoform="true">

		<!-- copy info from another active Bean -->
		<crudlet:property name="Username">
			<crudlet:value-of bean="User" property="Username"/>
		</crudlet:property>

		<!-- copy info extracted from URL by the SiteMap, passed as a parameter
to the Action -->
		<crudlet:property name="ParentId">
			<act:parameter name="PageId"/>
		</crudlet:property>

		<!-- fork on success or failure of the Assign (each property validated) -->
		<crudlet:success>
			<!-- send success message so SiteMap can react (or is it just XSP or
XSLT that can?) -->
			<!-- added a new tag to the Request TagLib (should this be in the
"act" ns?) -->
			<xsp-request:set-parameter name="assign">true</xsp-request:set-parameter>

			<!-- create the Bean in the Space -->
			<crudlet:event bean="comment" action="create">

				<!-- fork on success or failure of the Create Event (whole bean
validation) -->
				<crudlet:success>
					<!-- send success message -->
					<xsp-request:set-parameter
name="create">true</xsp-request:set-parameter>
				</crudlet:success>
				<crudlet:failure>
					<!-- send failure message -->
					<xsp-request:set-parameter
name="create">false</xsp-request:set-parameter>
				</crudlet:failure>
			</crudlet:event>
		</crudlet:success>
		<crudlet:failure>
			<!-- send failure message -->
			<xsp-request:set-parameter
name="assign">false</xsp-request:set-parameter>
		</crudlet:failure>
	</crudlet:assign>

</act:action>

The XSP Page

<?xml version="1.0"?>
<xsp:page
	xmlns:xsp="http://apache.org/xsp"
  xmlns:xsp-request="http://apache.org/xsp/request"
  xmlns:crudlet="http://www.crudlet.org/cocoon/XSP/Crudlet/2.0"
>
<page
	xmlns:select="http://www.r2r.com/2001/Select/1.0"
>
	<!-- Pass the Action results to the XSLT (?) -->
	<act>
		<assign><xsp-request:get-parameter name="assign"/></assign>
		<create><xsp-request:get-parameter name="create"/></create>
	</act>

	<!-- info about the comment -->
	<meta>
		<comment-id><crudlet:value-of bean="comment"
property="CommmentId"/></comment-id>
		<parent-id><crudlet:value-of bean="comment"
property="ParentId"/></parent-id>
		<author-id><crudlet:value-of bean="comment"
property="Username"/></author-id>
		<prefs><crudlet:copy-of bean="User" property="Preferences.Display"/><prefs>
		<title><crudlet:value-of bean="comment" property="Content.Title"/></title>
	</meta>

	<!-- the comment -->
	<comment>

		<!-- the page introduction -->
		<intro>
			<p>Welcome to blah blah ...</p>
		</intro>

		<!-- the body of the page -->
		<main>
			<crudlet:copy-of bean="comment" property="Content"/>
		</main>

		<!-- the page's action -->
		<!-- show an edit button if this comment is from this User, etc. -->
		<!-- xmlns:select is filtered by XSLT -->
		<!-- the "action" chooses the "button" that matches it, or "*" -->
		<action>
			<xsp:attribute name="select:choose">
				<crudlet:value-of bean="comment" property="Username"/>
			</xsp:attribute>
			<button action="edit">													<!-- Author -->
				<xsp:attribute name="select:match">
					<crudlet:value-of bean="User" property="Username"/>
				</xsp:attribute>
			</button>
			<button action="admin" select:match="Admin"/>		<!-- Admin user -->
			<button action="reply" select:match="*"/>				<!-- anyone else -->
		</action>
	</comment>
</page>
</xsp:page>


In Cocoon 1, we would have to keep the contents of the Action and the XSP
(above) in the same file, but if we could use XSP Taglibs that need to make
no output inside XML that defines "XSP" Actions and ones that make output
in XSP Pages, we could develop sets of simple generic Actions and XSP
Outputs for our Web Apps that can be mixed and matched by the SiteMap, all
sharing TagLibs.


Does this help?


regards Jeremy


-- 
   ___________________________________________________________________

   Jeremy Quinn                                           Karma Divers
                                                       webSpace Design
                                            HyperMedia Research Centre

   <mailto:sharkbait@mac.com>     		 <http://www.media.demon.co.uk>
    <phone:+44.[0].20.7737.6831>        <pager:jermq@sms.genie.co.uk>

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


Mime
View raw message