cancel
Showing results for 
Search instead for 
Did you mean: 

WCM Web Forms - any way to choose between element tags?

gennaromonaco
Champ in-the-making
Champ in-the-making
Is there any way to create a .wsd that allows the form user to select between one of two different element tags?

For instance, I currently have:


   <xs:element name="test_form">
      <xs:complexType>
         <xs:sequence>
            <xs:element name="spots" minOccurs="1" maxOccurs="unbounded">
               <xs:complexType>
                  <xs:sequence>
                     <xs:element name="type" type="xs:normalizedString"/>
                     <xs:element name="title" type="xs:normalizedString"/>
                     <xs:element name="blurb" type="xs:string"/>
                     <xs:element name="image" type="xs:anyURI"/>
                     <xs:element name="url" type="xs:normalizedString"/>
                     <xs:element name="target" default="_top">
                        <xs:simpleType>
                           <xs:restriction base="xs:string">
                              <xs:enumeration value="_top"/>
                              <xs:enumeration value="_blank"/>
                           </xs:restriction>
                        </xs:simpleType>
                     </xs:element>
                  </xs:sequence>
               </xs:complexType>
            </xs:element>
         </xs:sequence>
      </xs:complexType>
   </xs:element>

… but what I would really like is to have the user decide whether or not he/she would like to provide a url or an internal_url.

Basically, the form would give them a choice of picking one of those fields (elements) or the other.

Possible?

Thanks!
5 REPLIES 5

arielb
Champ in-the-making
Champ in-the-making
yes - you want to use inheritence between your types which would like something along the lines of this:


<xs:complexType name="abstract_url" abstract="true">
<xs:sequence>
  <xs:element name="some_property" type="xs:normalizedString"/>
</xs:sequence>
</xs:complexType>

<xs:complexType name="external_url" abstract="false">
<xs:complexContent>
<xs:extension base="abstract_url">
<xs:sequence>
  <xs:element name="some_other_property" type="xs:normalizedString"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>

<xs:complexType>
<xs:complexContent>
<xs:extension base="abstract_url">
<xs:sequence>
  <xs:element name="some_other_other_property" type="xs:normalizedString"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>


so if in test_form you use <xs:element name="url" type="abstract_url"/>.  you'll get a toggle for all non abstract extensions of abstract_url for the user to choose from.

gennaromonaco
Champ in-the-making
Champ in-the-making
Hi arielb,

Thanks for the advice.
I tried the following, adding an abstract complexType as you mentioned…


<?xml version="1.0"?>

<xs:schema
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:amm="http://alfresco/amm"
    targetNamespace="http://alfresco/amm"
    elementFormDefault="qualified">

   <xs:complexType name="abstract_url" abstract="true">
      <xs:sequence>
         <xs:element name="some_property" type="xs:normalizedString"/>
      </xs:sequence>
   </xs:complexType>

   <xs:complexType name="external_url" abstract="false">
      <xs:complexContent>
         <xs:extension base="abstract_url">
            <xs:sequence>
               <xs:element name="some_other_property" type="xs:normalizedString"/>
            </xs:sequence>
         </xs:extension>
      </xs:complexContent>
   </xs:complexType>         

   <xs:complexType name="internal_url" abstract="false">
      <xs:complexContent>
         <xs:extension base="abstract_url">
            <xs:sequence>
               <xs:element name="some_other_other_property" type="xs:normalizedString"/>
            </xs:sequence>
         </xs:extension>
      </xs:complexContent>
   </xs:complexType>

   <xs:element name="test_form">
     <xs:complexType>
       <xs:sequence>
         <xs:element name="spots" minOccurs="1" maxOccurs="unbounded">
            <xs:complexType>
              <xs:sequence>
                <xs:element name="type" type="xs:normalizedString"/>
                <xs:element name="title" type="xs:normalizedString"/>
                <xs:element name="blurb" type="xs:string"/>
                <xs:element name="image" type="xs:anyURI"/>
                <xs:element name="url" type="abstract_url"/>
                <xs:element name="target" default="_top">
                  <xs:simpleType>
                     <xs:restriction base="xs:string">
                       <xs:enumeration value="_top"/>
                       <xs:enumeration value="_blank"/>
                     </xs:restriction>
                  </xs:simpleType>
                </xs:element>
              </xs:sequence>
            </xs:complexType>
         </xs:element>
       </xs:sequence>
     </xs:complexType>
   </xs:element>   

</xs:schema>

This, however, resulted in the following error …


org.alfresco.web.forms.FormProcessor$ProcessingException: org.alfresco.web.forms.xforms.FormBuilderException: error parsing schema: at line 12 column 38: src-resolve.4.1: Error resolving component 'abstract_url'. It was detected that 'abstract_url' has no namespace, but components with no target namespace are not referenceable from schema document 'null'. If 'abstract_url' is intended to have a namespace, perhaps a prefix needs to be provided. If it is intended that 'abstract_url' has no namespace, then an 'import' without a "namespace" attribute should be added to 'null'.

So I switched all references to abstract_url to be amm:abstract_url but that only resulted in the following error …


org.alfresco.web.forms.FormProcessor$ProcessingException: org.alfresco.web.forms.xforms.FormBuilderException: error parsing schema: at line 40 column 56: src-resolve: Cannot resolve the name 'amm:abstract_url' to a(n) 'type definition' component.

Any idea what I'm doing wrong?

Thanks in advance for your help!
- Gennaro

gennaromonaco
Champ in-the-making
Champ in-the-making
Some progress made.
Here is my latest code:


<?xml version="1.0"?>

<xs:schema
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:amm="http://alfresco/amm"
    targetNamespace="http://alfresco/amm"
    elementFormDefault="qualified">

   <xs:complexType name="abstractUrl" abstract="true"/>

   <xs:complexType name="externalUrl" abstract="false">
      <xs:complexContent>
         <xs:extension base="amm:abstractUrl">
            <xs:sequence>
               <xs:element name="property_1" type="xs:normalizedString"/>
            </xs:sequence>
         </xs:extension>
      </xs:complexContent>
   </xs:complexType>

   <xs:complexType name="internalUrl" abstract="false">
      <xs:complexContent>
         <xs:extension base="amm:abstractUrl">
            <xs:sequence>
               <xs:element name="property_2" type="xs:normalizedString"/>
            </xs:sequence>
         </xs:extension>
      </xs:complexContent>
   </xs:complexType>

   <xs:element name="test_form">
     <xs:complexType>
       <xs:sequence>
         <xs:element name="spots" minOccurs="1" maxOccurs="unbounded">
            <xs:complexType>
              <xs:sequence>
                <xs:element name="type" type="xs:normalizedString"/>
                <xs:element name="title" type="xs:normalizedString"/>
                <xs:element name="blurb" type="xs:string"/>
                <xs:element name="image" type="xs:anyURI"/>
                <xs:element name="url" type="amm:abstractUrl"/>
                <xs:element name="target" default="_top">
                  <xs:simpleType>
                     <xs:restriction base="xs:string">
                       <xs:enumeration value="_top"/>
                       <xs:enumeration value="_blank"/>
                     </xs:restriction>
                  </xs:simpleType>
                </xs:element>
              </xs:sequence>
            </xs:complexType>
         </xs:element>
       </xs:sequence>
     </xs:complexType>
   </xs:element>   

</xs:schema>

This renders w/o error, however, what it shows is a Url group (with an arrow to open and close it) with only one element in it - the latest element extension, property_2 from the internalUrl complexType. The element named property_1 from the externalUrl complexType is nowhere to be found, and there is no option/switch for switching/choosing between one or the other.

Any ideas?

Thanks again!
- Gennaro

gennaromonaco
Champ in-the-making
Champ in-the-making
By the way…

Just in case my version number matters for what is/isn't available in WCM Web Forms, I'm running the Enterprise 2.0.0 version of Alfresco on Linux.

Under the Repository Properties tab of the System Information page of the Administration Console…

Installed Schema 38
Installed Version 2.0.0 (build-23)
Server Schema 38
Server Version 2.0.0 (build-23)

- Gennaro

kvc
Champ in-the-making
Champ in-the-making
Ah, that is the indeed the issue.

Full support for the xf:switch XForm control was added in our 2.0.1E maintenance release, and is also currently checked into head to be part of our upcoming 2.1.0 Community release (end June).

I recommend downloading our latest nightly build or checking out our latest source to try this same form on the 2.1.0 codeline.  Or, if you are on subscription (either as a customer or partner), just work directly with 2.0.1E.

Thanks.

Kevin