cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Owen Tallman <owen.tall...@gmail.com>
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:

java.lang.NullPointerException
	at org.apache.cocoon.forms.datatype.typeimpl.EnumType.getTypeClass(EnumType.java:55)
	at org.apache.cocoon.forms.formmodel.Field.setValue(Field.java:161)
	at org.apache.cocoon.forms.binding.ValueJXPathBinding.doLoad(ValueJXPathBinding.java:103)
	at org.apache.cocoon.forms.binding.JXPathBindingBase.loadFormFromModel(JXPathBindingBase.java:162)
	at org.apache.cocoon.forms.binding.ComposedJXPathBindingBase.doLoad(ComposedJXPathBindingBase.java:96)
	at org.apache.cocoon.forms.binding.ContextJXPathBinding.doLoad(ContextJXPathBinding.java:52)
	at org.apache.cocoon.forms.binding.JXPathBindingBase.loadFormFromModel(JXPathBindingBase.java:162)
	at org.apache.cocoon.forms.binding.JXPathBindingBase.loadFormFromModel(JXPathBindingBase.java:176)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:324)
	at org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:230)
	at org.mozilla.javascript.ScriptRuntime.call(ScriptRuntime.java:1244)
	at org.mozilla.javascript.continuations.ContinuationInterpreter.interpret(ContinuationInterpreter.java:1134)
	at org.mozilla.javascript.continuations.ContinuationInterpreter.interpret(ContinuationInterpreter.java:190)
	at org.mozilla.javascript.continuations.ContinuationInterpreter.interpret(ContinuationInterpreter.java:138)
	at org.mozilla.javascript.continuations.InterpretedFunctionImpl.call(InterpretedFunctionImpl.java:121)
	at org.mozilla.javascript.ScriptRuntime.call(ScriptRuntime.java:1244)
	at org.apache.cocoon.components.flow.javascript.fom.FOM_JavaScriptInterpreter.callFunction(FOM_JavaScriptInterpreter.java:755)
	at org.apache.cocoon.components.treeprocessor.sitemap.CallFunctionNode.invoke(CallFunctionNode.java:135)

... and so on

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

<?xml version="1.0"?>
<fd:form xmlns:fd="http://apache.org/cocoon/forms/1.0#definition"
xmlns:i18n="http://apache.org/cocoon/i18n/2.1">
	<fd:widgets>
        <fd:field id="tab-state">
          <fd:datatype base="string"/>
        </fd:field>

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

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

		<fd:repeater id="packages">

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

        <fd:field id="locationType">
          <fd:label>Select locations to search:</fd:label>
          <fd:datatype base="enum"/>
            <fd:converter type="enum">
                <fd:enum>com.envisn.nv.form.enums.LocationType</fd:enum>
            </fd:converter>
            <fd:selection-list type="enum"
class="com.envisn.nv.form.enums.LocationType"/>
        </fd:field>

	</fd:widgets>
</fd:form>

The binding looks like this:

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

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

</fb:context>

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 = Packages.com.envisn.nv.form.WidgetFactory.getPackageAnalysisForm(userSession);
    var targets = bean.getTargets().toArray() ;
    form.load(bean);
---------

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
here.

Thanks

Owen

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


Mime
View raw message