ivelin 02/05/09 00:26:07
Modified: src/scratchpad/src/org/apache/cocoon/samples/xmlform
UserBean.java WizardAction.java
src/scratchpad/src/org/apache/cocoon/transformation
XMLFormTransformer.java
src/scratchpad/src/org/apache/cocoon/xmlform Form.java
src/scratchpad/webapp/mount/xmlform/stylesheets
wizard2html.xsl xmlform2html.xsl
src/scratchpad/webapp/mount/xmlform/wizard userIdentity.xml
Log:
XMLForm 0.8.2
Added support for
<xf:selectMany/>
<xf:selectMany selectUIType='listbox'/>
Updated Wizard demo to include selectMany input.
Revision Changes Path
1.3 +27 -14
xml-cocoon2/src/scratchpad/src/org/apache/cocoon/samples/xmlform/UserBean.java
Index: UserBean.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/scratchpad/src/org/apache/cocoon/samples/xmlform/UserBean.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- UserBean.java 24 Apr 2002 12:22:51 -0000 1.2
+++ UserBean.java 9 May 2002 07:26:07 -0000 1.3
@@ -29,16 +29,18 @@
private short numInstalls = 1;
private String liveUrl = "http://";
private boolean publish = true;
- private Set roles = new HashSet();
private List favorites = new ArrayList();
+ private List roles;
+ private String hobbies[];
private Node system;
public UserBean ()
{
initDomNode();
- initRoleSet();
+ initRoles();
initFavorites();
+ initHobbies();
}
public String getFirstName() {
@@ -175,16 +177,25 @@
}
- public Set getRoles()
+ public List getRole()
{
return roles;
}
- public void setRoles( Set newRoles )
+ public void setRole( List newRoles )
{
roles = newRoles;
}
+ public String[] getHobby()
+ {
+ return hobbies;
+ }
+
+ public void setHobby( String[] newHobbies )
+ {
+ hobbies = newHobbies;
+ }
public List getFavorite()
{
@@ -196,17 +207,19 @@
favorites = newFavorites;
}
- public void initRoleSet()
+ public void initRoles()
+ {
+ roles = new ArrayList();
+ for (int i = 0; i < 10; i++)
+ {
+ roles.add( null );
+ }
+ }
+
+
+ public void initHobbies()
{
- roles.add( "Geek" );
- roles.add( "Hacker" );
- roles.add( "Student" );
- roles.add( "University Professor" );
- roles.add( "Developer" );
- roles.add( "Tech Lead" );
- roles.add( "Development Manager" );
- roles.add( "Executive" );
- roles.add( "Heir of the Apache" );
+ hobbies = new String[] {"", "", "", "", ""};
}
1.2 +15 -4
xml-cocoon2/src/scratchpad/src/org/apache/cocoon/samples/xmlform/WizardAction.java
Index: WizardAction.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/scratchpad/src/org/apache/cocoon/samples/xmlform/WizardAction.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- WizardAction.java 17 Apr 2002 17:59:15 -0000 1.1
+++ WizardAction.java 9 May 2002 07:26:07 -0000 1.2
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/xml-cocoon2/src/scratchpad/src/org/apache/cocoon/samples/xmlform/WizardAction.java,v
1.1 2002/04/17 17:59:15 ivelin Exp $
- * $Revision: 1.1 $
- * $Date: 2002/04/17 17:59:15 $
+ * $Header:
/home/cvs/xml-cocoon2/src/scratchpad/src/org/apache/cocoon/samples/xmlform/WizardAction.java,v
1.2 2002/05/09 07:26:07 ivelin Exp $
+ * $Revision: 1.2 $
+ * $Date: 2002/05/09 07:26:07 $
*
* ====================================================================
* The Apache Software License, Version 1.1
@@ -192,7 +192,8 @@
// set the page control flow parameter
// according to the validation result
- if ( getForm().getViolations () != null )
+ if ( getCommand().equals( CMD_NEXT ) &&
+ getForm().getViolations () != null )
{
// errors, back to the same page
return page( getFormView() );
@@ -201,6 +202,10 @@
{
// validation passed
// continue with control flow
+
+ // clear validation left overs in case the user
+ // did not press the Next button
+ getForm().clearViolations();
// get the user submitted command (through a submit button)
String command = getCommand();
@@ -271,6 +276,12 @@
{
// deal with the publish checkbox
form.setValue( "/publish", Boolean.FALSE );
+ }
+ else if ( formView.equals ( VIEW_USERID ) )
+ {
+ // deal with the publish checkbox
+ UserBean ub = (UserBean) form.getModel();
+ ub.initRoles ();
}
}
1.6 +45 -13
xml-cocoon2/src/scratchpad/src/org/apache/cocoon/transformation/XMLFormTransformer.java
Index: XMLFormTransformer.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/scratchpad/src/org/apache/cocoon/transformation/XMLFormTransformer.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- XMLFormTransformer.java 24 Apr 2002 12:22:51 -0000 1.5
+++ XMLFormTransformer.java 9 May 2002 07:26:07 -0000 1.6
@@ -58,6 +58,7 @@
import java.util.Collection;
import java.util.SortedSet;
import java.util.Stack;
+import java.lang.reflect.Array;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
@@ -92,8 +93,9 @@
* The original code was built by Torsten Curdt as
* part of the Preceptor API
*
- * @author: Torsten Curdt <[EMAIL PROTECTED]>
- * @author: Ivelin Ivanov <[EMAIL PROTECTED]>
+ * @author: Ivelin Ivanov <[EMAIL PROTECTED]>, May 2002
+ * @author: Michael Ratliff, [EMAIL PROTECTED] <[EMAIL PROTECTED]>, May 2002
+ * @author: Torsten Curdt <[EMAIL PROTECTED]>, March 2002
*/
public class XMLFormTransformer extends AbstractSAXTransformer
@@ -436,15 +438,13 @@
}
else if (TAG_SELECTMANY.equals(name))
{
- //NYI - Not Yet Implemented
- throw new SAXException("tag selectMany Not Yet Implemented");
+ startElementSimpleField( uri, name, raw, attributes, currentForm
);
}
else if (
TAG_SUBMIT.equals(name) ||
TAG_CANCEL.equals(name) ||
TAG_RESET.equals(name) )
{
- //NYI
super.startElement(uri, name, raw, attributes);
}
else
@@ -615,18 +615,50 @@
getLogger().debug("Value of form [id=" + form.getId() + ", ref=" +
String.valueOf(ref) + "] = [" + value_ + "]") ;
- // render the value subelement
- super.startElement(uri, "value", NS_PREFIX + ":" + "value", NOATTR);
- if (value_ != null)
+ // render the value subelement(s)
+ if (value_ instanceof Collection)
{
- String v = String.valueOf( value_ );
- super.characters(v.toCharArray(),0,v.length());
+ Iterator i=((Collection) value_).iterator();
+ while (i.hasNext())
+ {
+ renderValueSubElement( i.next() );
+ }
+ }
+ else if ( value_ != null && value_.getClass().isArray () )
+ {
+ int len = Array.getLength ( value_ );
+ for (int i = 0; i < len; i++ )
+ {
+ renderValueSubElement( Array.get ( value_, i ) );
+ }
}
- super.endElement( uri, "value", NS_PREFIX + ":" + "value" );
-
+ else
+ {
+ renderValueSubElement( value_ );
+ }
} // end of startElementSimpleField
+ /**
+ * Outputs a <xf:value> element.
+ * Used when transforming XMLForm elements
+ * with reference to the model
+ *
+ * @param vobj provides the text content
+ * within the <xf:value> element
+ *
+ */
+ protected void renderValueSubElement( Object vobj )
+ throws SAXException
+ {
+ super.startElement( NS, "value", NS_PREFIX + ":" + "value", NOATTR);
+ if (vobj != null)
+ {
+ String v = String.valueOf( vobj );
+ super.characters(v.toCharArray(),0,v.length());
+ }
+ super.endElement( NS, "value", NS_PREFIX + ":" + "value" );
+ }
/**
* Start processing elements of our namespace.
@@ -709,7 +741,7 @@
}
else if (TAG_SELECTMANY.equals(name))
{
- // NYI
+ super.endElement(uri, name, raw);
}
else if (TAG_SUBMIT.equals(name))
{
1.4 +38 -18
xml-cocoon2/src/scratchpad/src/org/apache/cocoon/xmlform/Form.java
Index: Form.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/scratchpad/src/org/apache/cocoon/xmlform/Form.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Form.java 24 Apr 2002 12:22:51 -0000 1.3
+++ Form.java 9 May 2002 07:26:07 -0000 1.4
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/xml-cocoon2/src/scratchpad/src/org/apache/cocoon/xmlform/Form.java,v
1.3 2002/04/24 12:22:51 ivelin Exp $
- * $Revision: 1.3 $
- * $Date: 2002/04/24 12:22:51 $
+ * $Header:
/home/cvs/xml-cocoon2/src/scratchpad/src/org/apache/cocoon/xmlform/Form.java,v
1.4 2002/05/09 07:26:07 ivelin Exp $
+ * $Revision: 1.4 $
+ * $Date: 2002/05/09 07:26:07 $
*
* ====================================================================
* The Apache Software License, Version 1.1
@@ -99,7 +99,7 @@
* NOTE: This class is NOT thread safe
*
* @author Ivelin Ivanov, [EMAIL PROTECTED]
- * @version $Revision: 1.3 $ $Date: 2002/04/24 12:22:51 $
+ * @version $Revision: 1.4 $ $Date: 2002/05/09 07:26:07 $
*/
public class Form
@@ -168,6 +168,12 @@
}
+ public void clearViolations()
+ {
+ violations_ = null;
+ }
+
+
/**
* Encapsulates access to the model
*
@@ -183,24 +189,38 @@
}
- public void setValue(String path, Object[] values)
+ public void setValue(String xpath, Object[] values)
{
- Pointer pointer = jxcontext_.locateValue( path );
- Object property = pointer.getValue();
- if ( property == null )
+ // if there are multiple values to set
+ // (like in the selectMany case),
+ // iterate over the array and set individual values
+ if ( values.length > 1 )
{
- throw new RuntimeException( "Property for " + path + " is nul. Cannot
determine type." );
+ for (int i = 1; i <= values.length; i++ )
+ {
+ this.setValue( xpath + "[" + i + "]", values[i-1] );
+ }
}
- // if the property is a collection, set value as array
- if ( property instanceof Collection || property.getClass ().isArray () )
+ // in case there is only one value send,
+ // but the underlying model structure is a collection or array
+ else
{
- Object newValue = convertType( values, property.getClass () );
- pointer.setValue( newValue );
+ Pointer pointer = jxcontext_.locateValue( xpath );
+ Object property = pointer.getValue();
+ if ( property != null &&
+ ( property instanceof Collection ||
property.getClass().isArray() )
+ )
+ {
+ this.setValue( xpath + "[1]", values[0] );
+ }
+ // otherwise set the value of the first element
+ // (there shouldn't be other)
+ // in the values array
+ else
+ {
+ this.setValue( pointer, values[0] );
+ }
}
- // otherwise set the value of the first element
- // (there shouldn't be other)
- // in the values array
- else setValue( pointer, values[0] );
}
@@ -232,7 +252,7 @@
}
}
// set null value
- else pointer.setValue( property );
+ else pointer.setValue( value );
}
1.4 +2 -2
xml-cocoon2/src/scratchpad/webapp/mount/xmlform/stylesheets/wizard2html.xsl
Index: wizard2html.xsl
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/scratchpad/webapp/mount/xmlform/stylesheets/wizard2html.xsl,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- wizard2html.xsl 24 Apr 2002 12:22:51 -0000 1.3
+++ wizard2html.xsl 9 May 2002 07:26:07 -0000 1.4
@@ -6,8 +6,8 @@
a final document. It includes other presentational
parts of a page orthogonal to the xmlform.
- Author: Ivelin Ivanov, [EMAIL PROTECTED], April 2002
- Original Author: Konstantin Piroumian, [EMAIL PROTECTED], 21-Feb-2002
+ author: Ivelin Ivanov, [EMAIL PROTECTED], May 2002
+ original Author: Konstantin Piroumian, [EMAIL PROTECTED], 21-Feb-2002
-->
1.2 +109 -1
xml-cocoon2/src/scratchpad/webapp/mount/xmlform/stylesheets/xmlform2html.xsl
Index: xmlform2html.xsl
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/scratchpad/webapp/mount/xmlform/stylesheets/xmlform2html.xsl,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- xmlform2html.xsl 17 Apr 2002 17:59:16 -0000 1.1
+++ xmlform2html.xsl 9 May 2002 07:26:07 -0000 1.2
@@ -1 +1,109 @@
-<?xml version="1.0" encoding="iso-8859-1" ?>
<!--
Generic XMLForm processing stylesheet.
Converts XMLForm tags to HTML tags.
Syntax is borrowed from the XForms standard.
http://www.w3.org/TR/2002/WD-xforms-20020118/
This stylesheet is usually applied at the end of a
transformation process after laying out the xmlform
tags on the page is complete. At this stage xmlform tags
are rendered in device specific format.
Author: Ivelin Ivanov, [EMAIL PROTECTED], April 2002
Original Author: Torsten Curdt, [EMAIL PROTECTED], March 2002
-->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xf="http://xml.apache.org/cocoon/xmlform/2002"
>
<xsl:output method = "html" omit-xml-declaration = "yes" />
<xsl:template match="/">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="xf:form">
<form method="POST">
<xsl:copy-of select="@*"/>
<input type="hidden" name="cocoon-xmlform-view" value="[EMAIL
PROTECTED]"/>
<xsl:apply-templates />
</form>
</xsl:template>
<xsl:template match="xf:output">
[<xsl:value-of select="xf:value/text()"/>]
</xsl:template>
<xsl:template match="xf:textbox">
<input name="[EMAIL PROTECTED]" type="textbox" value="{xf:value/text()}"
/>
</xsl:template>
<xsl:template match="xf:password">
<input name="[EMAIL PROTECTED]" type="password" value="{xf:value/text()}"
/>
</xsl:template>
<xsl:template match="xf:selectBoolean">
<input name="[EMAIL PROTECTED]" type="checkbox" value="true">
<xsl:if test="xf:value/text() = 'true'">
<xsl:attribute name="checked"/>
</xsl:if>
</input>
</xsl:template>
<xsl:template match="xf:selectOne">
<select name="[EMAIL PROTECTED]">
<xsl:variable name="selected" select="xf:value/text()"/>
<xsl:for-each select="xf:item">
<option value="{xf:value}">
<xsl:if test="$selected = xf:value">
<xsl:attribute name="selected"/>
</xsl:if>
<xsl:value-of select="xf:caption"/>
</option>
</xsl:for-each>
</select>
</xsl:template>
<xsl:template match="xf:selectMany">
<!-- @todo -->
</xsl:template>
<xsl:template match="xf:submit">
<input name="[EMAIL PROTECTED]" type="submit" value="{xf:caption/text()}"
/>
</xsl:template>
<xsl:template match="*">
<xsl:copy><xsl:copy-of select="@*" /><xsl:apply-templates /></xsl:copy>
</xsl:template>
<xsl:template match="text()">
<xsl:value-of select="." />
</xsl:template>
</xsl:stylesheet>
\ No newline at end of file
+<?xml version="1.0" encoding="iso-8859-1" ?>
+
+
+<!--
+
+ Generic XMLForm processing stylesheet.
+ Converts XMLForm tags to HTML tags.
+
+ Syntax is borrowed from the XForms standard.
+ http://www.w3.org/TR/2002/WD-xforms-20020118/
+
+ This stylesheet is usually applied at the end of a
+ transformation process after laying out the xmlform
+ tags on the page is complete. At this stage xmlform tags
+ are rendered in device specific format.
+
+ author: Ivelin Ivanov, [EMAIL PROTECTED], May 2002
+ author: Michael Ratliff, [EMAIL PROTECTED] <[EMAIL PROTECTED]>, May 2002
+ Original Author: Torsten Curdt, [EMAIL PROTECTED], March 2002
+
+-->
+
+<xsl:stylesheet version="1.0"
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:xf="http://xml.apache.org/cocoon/xmlform/2002"
+>
+
+ <xsl:output method = "html" omit-xml-declaration = "yes" />
+
+
+ <xsl:template match="/">
+ <xsl:apply-templates />
+ </xsl:template>
+
+ <xsl:template match="xf:form">
+ <form method="POST">
+ <xsl:copy-of select="@*"/>
+ <input type="hidden" name="cocoon-xmlform-view" value="[EMAIL
PROTECTED]"/>
+ <xsl:apply-templates />
+ </form>
+ </xsl:template>
+
+ <xsl:template match="xf:output">
+ [<xsl:value-of select="xf:value/text()"/>]
+ </xsl:template>
+
+ <xsl:template match="xf:textbox">
+ <input name="[EMAIL PROTECTED]" type="textbox"
value="{xf:value/text()}" />
+ </xsl:template>
+
+ <xsl:template match="xf:password">
+ <input name="[EMAIL PROTECTED]" type="password"
value="{xf:value/text()}" />
+ </xsl:template>
+
+ <xsl:template match="xf:selectBoolean">
+ <input name="[EMAIL PROTECTED]" type="checkbox" value="true">
+ <xsl:if test="xf:value/text() = 'true'">
+ <xsl:attribute name="checked"/>
+ </xsl:if>
+ </input>
+ </xsl:template>
+
+ <xsl:template match="xf:selectOne">
+ <select name="[EMAIL PROTECTED]">
+ <xsl:variable name="selected" select="xf:value/text()"/>
+ <xsl:for-each select="xf:item">
+ <option value="{xf:value}">
+ <xsl:if test="$selected = xf:value">
+ <xsl:attribute name="selected"/>
+ </xsl:if>
+ <xsl:value-of select="xf:caption"/>
+ </option>
+ </xsl:for-each>
+ </select>
+ </xsl:template>
+
+
+ <xsl:template match="xf:selectMany | xf:[EMAIL PROTECTED]'listbox']">
+ <xsl:variable name="selected" select="xf:value"/>
+ <select name="[EMAIL PROTECTED]">
+ <xsl:attribute name="multiple"/>
+ <xsl:for-each select="xf:item">
+ <option value="{xf:value}">
+ <xsl:if test="xf:value = $selected">
+ <xsl:attribute name="selected"/>
+ </xsl:if>
+ <xsl:value-of select="xf:caption"/>
+ </option>
+ </xsl:for-each>
+ </select>
+ </xsl:template>
+
+ <xsl:template match="xf:submit">
+ <input name="[EMAIL PROTECTED]" type="submit"
value="{xf:caption/text()}" />
+ </xsl:template>
+
+
+ <xsl:template match="*">
+ <xsl:copy><xsl:copy-of select="@*" /><xsl:apply-templates /></xsl:copy>
+ </xsl:template>
+
+ <xsl:template match="text()">
+ <xsl:value-of select="." />
+ </xsl:template>
+
+</xsl:stylesheet>
+
+
+
1.3 +42 -1
xml-cocoon2/src/scratchpad/webapp/mount/xmlform/wizard/userIdentity.xml
Index: userIdentity.xml
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/scratchpad/webapp/mount/xmlform/wizard/userIdentity.xml,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- userIdentity.xml 19 Apr 2002 13:19:27 -0000 1.2
+++ userIdentity.xml 9 May 2002 07:26:07 -0000 1.3
@@ -6,7 +6,7 @@
XMLForm instance document for the Cocoon Feedback Wizard.
Original Author: Torsten Curdt, [EMAIL PROTECTED], March 2002
- Author: Ivelin Ivanov, [EMAIL PROTECTED], April 2002
+ Author: Ivelin Ivanov, [EMAIL PROTECTED], April 2002
-->
@@ -41,6 +41,46 @@
<xf:violations class="error"/>
</xf:textbox>
+ <xf:selectMany ref="/role" selectUIType='listbox'>
+ <xf:caption>Professional roles</xf:caption>
+ <xf:item>
+ <xf:caption>Geek</xf:caption>
+ <xf:value>Geek</xf:value>
+ </xf:item>
+ <xf:item>
+ <xf:caption>Hacker</xf:caption>
+ <xf:value>Hacker</xf:value>
+ </xf:item>
+ <xf:item>
+ <xf:caption>Student</xf:caption>
+ <xf:value>Student</xf:value>
+ </xf:item>
+ <xf:item>
+ <xf:caption>University Professor</xf:caption>
+ <xf:value>University Professor</xf:value>
+ </xf:item>
+ <xf:item>
+ <xf:caption>Software Developer</xf:caption>
+ <xf:value>Developer</xf:value>
+ </xf:item>
+ <xf:item>
+ <xf:caption>Technical Leader</xf:caption>
+ <xf:value>Tech Lead</xf:value>
+ </xf:item>
+ <xf:item>
+ <xf:caption>Development Manager</xf:caption>
+ <xf:value>Development Manager</xf:value>
+ </xf:item>
+ <xf:item>
+ <xf:caption>Executive</xf:caption>
+ <xf:value>Executive</xf:value>
+ </xf:item>
+ <xf:item>
+ <xf:caption>Heir of the Apache tribe</xf:caption>
+ <xf:value>Heir of the Apache tribe</xf:value>
+ </xf:item>
+ </xf:selectMany>
+
<xf:submit id="next" class="button">
<xf:caption>Next</xf:caption>
</xf:submit>
@@ -53,5 +93,6 @@
</xf:output>
</document>
+
----------------------------------------------------------------------
In case of troubles, e-mail: [EMAIL PROTECTED]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]