diff --git a/source/java/org/alfresco/web/forms/xforms/Schema2XForms.java b/source/java/org/alfresco/web/forms/xforms/Schema2XForms.java index ab8ffecf47..63ce4078db 100644 --- a/source/java/org/alfresco/web/forms/xforms/Schema2XForms.java +++ b/source/java/org/alfresco/web/forms/xforms/Schema2XForms.java @@ -1283,9 +1283,10 @@ public class Schema2XForms implements Serializable " occurs " + occurs); // create the element and add it to the model. + boolean isRepeated = occurs.isRepeated() || (occurs.isOptional() && (controlType instanceof XSSimpleTypeDefinition == false)); final Element bindElement = this.createBind(xformsDocument, - pathToRoot + (occurs.isRepeated() ? "[position() != last()]" : "")); + pathToRoot + (isRepeated ? "[position() != last()]" : "")); final String bindId = bindElement.getAttributeNS(null, "id"); modelSection.appendChild(bindElement); @@ -1715,7 +1716,7 @@ public class Schema2XForms implements Serializable " default instance element for " + elementName + " at path " + path); // update the default instance - if (occurs.isRepeated()) + if (occurs.isRepeated() || (occurs.isOptional() && (element.getTypeDefinition() instanceof XSSimpleTypeDefinition == false))) { LOGGER.debug("adding " + (occurs.minimum + 1) + " default instance elements for " + elementName + @@ -1758,7 +1759,8 @@ public class Schema2XForms implements Serializable { // add xforms:repeat section if this element re-occurs - if (o.maximum == 1) + if ((o.isOptional() && controlType instanceof XSSimpleTypeDefinition) || + (o.maximum == 1 && o.minimum == 1)) { return formSection; } @@ -1854,14 +1856,15 @@ public class Schema2XForms implements Serializable } // create the element and add it to the model. + boolean isRepeated = occurs.isRepeated() || (occurs.isOptional() && (controlType instanceof XSSimpleTypeDefinition == false)); Element bindElement = - this.createBind(xformsDocument, pathToRoot + (occurs.isRepeated() ? "[position() != last()]" : "")); + this.createBind(xformsDocument, pathToRoot + (isRepeated ? "[position() != last()]" : "")); String bindId = bindElement.getAttributeNS(null, "id"); modelSection.appendChild(bindElement); bindElement = this.startBindElement(bindElement, schema, controlType, owner, occurs); // add a group if a repeat ! - if (owner instanceof XSElementDeclaration && occurs.maximum != 1) + if (owner instanceof XSElementDeclaration && occurs.isRepeated()) { final Element groupElement = this.createGroup(xformsDocument, modelSection, diff --git a/source/java/org/alfresco/web/forms/xforms/SchemaUtil.java b/source/java/org/alfresco/web/forms/xforms/SchemaUtil.java index 2e97d9ebcf..61e0d12016 100644 --- a/source/java/org/alfresco/web/forms/xforms/SchemaUtil.java +++ b/source/java/org/alfresco/web/forms/xforms/SchemaUtil.java @@ -72,6 +72,11 @@ public class SchemaUtil return this.isUnbounded() || this.maximum > 1; } + public boolean isOptional() + { + return this.minimum == 0 && this.maximum == 1; + } + public boolean isUnbounded() { return this.maximum == UNBOUNDED; diff --git a/source/test-resources/xforms/tests/bugs/ETHREEOH-1811.xsd b/source/test-resources/xforms/tests/bugs/ETHREEOH-1811.xsd new file mode 100644 index 0000000000..946445bc80 --- /dev/null +++ b/source/test-resources/xforms/tests/bugs/ETHREEOH-1811.xsd @@ -0,0 +1,103 @@ + + + + + + + + + + + English (US) + + + + + + + Japanese + + + + + + + + + + + + + + + + + + + + + + minimal + + + + + + + + + + + + + + + + Article + + + + + + + + + + + + + + + + + + + diff --git a/source/test-resources/xforms/tests/schema/optional-required.xsd b/source/test-resources/xforms/tests/schema/optional-required.xsd new file mode 100644 index 0000000000..2b7006e7ad --- /dev/null +++ b/source/test-resources/xforms/tests/schema/optional-required.xsd @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + +