cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Owen Tallman <>
Subject problem with enum and CForms selection-list
Date Thu, 02 Jun 2005 19:46:05 GMT
I've followed the examples and advice I've been able to find and can't
get past this problem. I want to use a typesafe enum to populate the
fields of  a selection-list in my form. I modelled it after the Sex
enum in the form2* example. Things proceed to the point of calling
form.load(bean) in my flowscript, and I get this stack trace:

	at org.apache.cocoon.forms.datatype.typeimpl.EnumType.getTypeClass(
	at org.apache.cocoon.forms.formmodel.Field.setValue(
	at org.apache.cocoon.forms.binding.ValueJXPathBinding.doLoad(
	at org.apache.cocoon.forms.binding.JXPathBindingBase.loadFormFromModel(
	at org.apache.cocoon.forms.binding.ComposedJXPathBindingBase.doLoad(
	at org.apache.cocoon.forms.binding.ContextJXPathBinding.doLoad(
	at org.apache.cocoon.forms.binding.JXPathBindingBase.loadFormFromModel(
	at org.apache.cocoon.forms.binding.JXPathBindingBase.loadFormFromModel(
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(
	at java.lang.reflect.Method.invoke(
	at org.mozilla.javascript.continuations.ContinuationInterpreter.interpret(
	at org.mozilla.javascript.continuations.ContinuationInterpreter.interpret(
	at org.mozilla.javascript.continuations.ContinuationInterpreter.interpret(
	at org.apache.cocoon.components.flow.javascript.fom.FOM_JavaScriptInterpreter.callFunction(
	at org.apache.cocoon.components.treeprocessor.sitemap.CallFunctionNode.invoke(

... and so on

Here's the form definition. The part that breaks occurs near the end:

<?xml version="1.0"?>
<fd:form xmlns:fd=""
        <fd:field id="tab-state">
          <fd:datatype base="string"/>

        <fd:booleanfield id="selectAll">
            <fd:label>Select All</fd:label>

        <fd:booleanfield id="clearAll">
            <fd:label>Clear All</fd:label>
                java.lang.System.err.println("Clear All!");                  
                event.source.value = false;

		<fd:repeater id="packages">

				<!-- fd: string as id -->
				<fd:field id="id">
					<fd:datatype base="string"/>
				<fd:booleanfield id="selection">
				<fd:output id="key">
					<fd:datatype base="string"/>
				<fd:output id="packageName">
					<fd:datatype base="string"/>
				<fd:output id="ownerName">
					<fd:datatype base="string"/>

        <fd:field id="locationType">
          <fd:label>Select locations to search:</fd:label>
          <fd:datatype base="enum"/>
            <fd:converter type="enum">
            <fd:selection-list type="enum"


The binding looks like this:

<?xml version="1.0"?>
<fb:context xmlns:fb="" path="/">
	<!-- This binding maps into a collection of reports -->
	<fb:repeater id="packages" parent-path="." row-path="targets">
			<fb:value id="id" path="@id"/>
		<!-- On binding, this maps values in each row to corresponding properties of a
             com.envisn.nv.query.LookupInfo bean -->
			<fb:value id="id" path="id"/>
			<fb:value id="key" path="key"/>
			<fb:value id="packageName" path="displayPath"/>
			<fb:value id="ownerName" path="ownerName"/>

    <!-- the locationType enum binding -->
    <fb:value id="locationType" path="locationType"/>


The enum class looks like this (actually it pretty much contains the
"Sex" code now, as I wanted to eliminate as many variables in the
comparison as possible:

public class LocationType {

    public static final LocationType MALE = new LocationType("M");
    public static final LocationType FEMALE = new LocationType("F");
    public static final LocationType ANY = new LocationType("A");
    private String code;

    private LocationType(String code) { this.code = code; }

    public String toString() {
      // Will probably have some i18n support here
      switch(code.charAt(0)) {
          case 'M' : return this.getClass().getName() + ".MALE";
          case 'F' : return this.getClass().getName() + ".FEMALE";
          case 'A' : return this.getClass().getName() + ".ANY";
          default : return "unknown"; // Should never happen

and the bean class that it loads looks like this:

public class PackageAnalysisFormBean {

    private Collection targets = new ArrayList();
    private LocationType locationType = LocationType.ANY ;

    public Collection getTargets() {  return targets;   }

    public void setTargets(Collection targets) {  this.targets = targets; }

    public void addTarget(LookupInfo lookupInfo) { 
this.targets.add(lookupInfo);  }

    public LocationType getLocationType() { return locationType; }

    public void setLocationType(LocationType locationType) {
this.locationType = locationType;    }


Finally the flowscript. It uses a factory class to do a query and
populate the bean. That all worked fine prior to introducing the enum
for the selection-list::

function do_packageAnalysis(form) {

    var userSession = outerSession.getAttribute(userSessionKey) ;
    var bean =;
    var targets = bean.getTargets().toArray() ;

and it blows up there.

Everything worked fine in the earlier version with static selection
definitions. I have traced this as far as I can with logging, and the
bean's methods get called during the form load, and return legitimate
references.  I'd appreciate any hints about what might have gone wrong



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

View raw message