You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Oliver Scheel <ol...@netzturbine.de> on 2007/11/01 13:59:59 UTC

problem with the fd:messages field type and ajax

Hello,

I have a problem with the fd:messages field in combination with ajax.
My cocoon version is 2.1.10.

The goal of that form is to have some field values, each contains an identifier value.
The method 'validateIdentity(widget)' executes a biz action to check if there is no other element with equal identifier values.
That means if this validation fails i must have a parent widget which invalidates all of its children and print out the error message.
To group all identifiers a group widget is defined in this form.
To print out the error message the group widget contains an fd:messages element.

Ajax is required to request the suggestion list elements. 

Here is the form definition fragment:

<fd:form xmlns:fd="http://apache.org/cocoon/forms/1.0#definition"
	xmlns:i18n="http://apache.org/cocoon/i18n/2.1">
  <fd:widgets>
		
    <fd:group id="identifiers">
			
      <!-- widgets to setup id values for the new game -->
      <fd:widgets>

        <fd:field id="title" required="true">
	  <fd:label><i18n:text>title</i18n:text>:</fd:label>
          <fd:datatype base="string" />
        </fd:field>
				
        <fd:field id="category" required="true">
	  <fd:label><i18n:text>category</i18n:text>:</fd:label>
          <fd:datatype base="string" />
          <fd:suggestion-list type="javascript">
            <![CDATA[
              function addSuggestion(value){
                suggestions.push({
                  value: value,
                  label: value
                });
              }
		            		
              var suggestions = [];
              if(filter) {
                var filterValue = "" + filter;
                var phase = cocoon.request.getParameter("phase");
                if(phase && "init".equals(phase)) {
                  addSuggestion(filterValue);
                } else if(filterValue.length > 1) {
                  // FIXME dont know how to trim a filter value
                  // String.trim() doesnt work
                  suggestions = getCategorySuggestions(filterValue);
                  if(suggestions.length == 0) {
                    addSuggestion(filterValue);
                  }
                }
              }
		            		
              return suggestions;
            ]]>
          </fd:suggestion-list>
        </fd:field>

        <!-- locale -->
        <fd:field id="localeISOCode">
          <fd:label><i18n:text>locale</i18n:text>:</fd:label>
          <fd:datatype base="string" />
          <fd:selection-list type="flow-jxpath" list-path="localeSelection"
            value-path="value" label-path="label" />
        </fd:field>
				
        <fd:field id="platformName">
          <fd:label><i18n:text>platform.name</i18n:text>:</fd:label>
          <fd:datatype base="string" />
          <fd:selection-list type="flow-jxpath" list-path="platformSelection"
            value-path="value" label-path="label" />
        </fd:field>
				
        <fd:messages id="validationErrors"/>
      </fd:widgets>
			
      <fd:validation>
        <fd:javascript>
          return validateIdentity(widget);
        </fd:javascript>
      </fd:validation>
    </fd:group>

    <!-- more widgets -->
    
  </fd:widgets>
</fd:form>


This is my template code:

<?xml version="1.0"?>
<page xmlns:ft="http://apache.org/cocoon/forms/1.0#template"
	xmlns:i18n="http://apache.org/cocoon/i18n/2.1"
	xmlns:jx="http://apache.org/cocoon/templates/jx/1.0"
	xmlns:fi="http://apache.org/cocoon/forms/1.0#instance">

	<jx:import
		uri="resource://org/apache/cocoon/forms/generation/jx-macros.xml" />

	<head>
		<link rel="stylesheet" type="text/css" href="${cocoon.request.contextPath}/styles/advancedForm.css"/>
		<title>
			<i18n:text>${pageTitle}</i18n:text>
		</title>
	</head>
	<body>
		
		<!-- display search result header -->
		
		<ft:form-template action="${cocoon.request.contextPath}/products/new/continue" method="POST" ajax="true">

			<ft:continuation-id/>
			
			<ft:group id="identifiers">
				<table>
					<tr><td colspan="2"><ft:widget id="validationErrors"/></td></tr>
					<tr><td><ft:widget-label id="title"/></td><td><ft:widget id="title"/></td></tr>
					<tr><td><ft:widget-label id="category"/></td><td><ft:widget id="category" type="suggest"/></td></tr>
					<tr><td><ft:widget-label id="localeISOCode"/></td><td><ft:widget id="localeISOCode"/></td></tr>
					<tr><td><ft:widget-label id="platformName"/></td><td><ft:widget id="platformName"/></td></tr>
				</table>
			</ft:group>
			
			<!-- more widgets -->
		</ft:form-template> 
	</body>
</page>

The validation method is implemented like this:

function validateIdentity(widget) {
  var result = doTheValidationRequest(getFieldValues(widget));
  if(true != result) {
    // invalid
    widget.getChild("validationErrors").addMessage(new I18nMessage("duplicate.product"));
    return false;
  }
  return true;
}

If the result is not valid and the validation method try's to access the fd:messages field an error dialog appears with the message: 
no element 'identifiers.validationErrors' in source document

Please ... can anybody tell me what the problem is ???

THX

Oliver Scheel
ole@netztubine.de


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