cancel
Showing results for 
Search instead for 
Did you mean: 

Define invisible element in xsd, Possible??

xexiz
Champ in-the-making
Champ in-the-making
Hello, here's what I am trying to do.. tell me if it's possible and how it is plz Smiley Happy

I would like to add an element in my xsd schema that won't appear in the XForms, like adding a node "CreationDate" which will contain the date when you create this xml. but I dont want this to be visible in the Alfresco UI form. Just want this element in the final xml generated by the form, with the today's date!

Thanks Smiley Happy
12 REPLIES 12

pmonks
Star Contributor
Star Contributor
It's not quite what you're after, but you can easily define a read-only field by adding the "fixed" facet to any element in your XML schema.  This doesn't visually remove the field from the web form, but does make it non-editable.

It's also possible to define a custom XForms widget that generates an <input type="hidden"> HTML form field, although unfortunately the field still takes up some vertical whitespace within the web form (which can be mitigated somewhat if you put all of the hidden fields at the end of your schema).  Details on the custom XForms widget functionality are at http://wiki.alfresco.com/wiki/Forms_Developer_Guide#Configuring_UI_control_mappings_in_web-client-co... .  For a hidden widget I'd suggest inheriting the existing TextField widget and simply changing the type of field that's generated (from "text" to "hidden").

pmonks
Star Contributor
Star Contributor
Oh and to embed today's date within the schema you'd use a dynamic include (see http://wiki.alfresco.com/wiki/Forms_Developer_Guide#Using_dynamic_types_in_schemas).

xexiz
Champ in-the-making
Champ in-the-making
Yay! thanks for the complete answer! Smiley Happy I'll give it a try today and give some news on my progress!!

thanks a lot!!

xexiz
Champ in-the-making
Champ in-the-making
Well for now I'm already stuck.. there is a stupid error making no sense at all.. the JSP wont do what i want for now (adding a hidden form field with today's date as default value) but well at least i'm not having error when "Preview File" in my sandbox on the jsp.

By the way, if i remove both red lines the xsd work well 😉 only if im trying to include the jsp that generate this error

im simply trying to make my include work first and here's the error i'm having
org.alfresco.web.forms.FormProcessor$ProcessingException: org.alfresco.web.forms.xforms.FormBuilderException: errors parsing schema: at line 37 column 5: The element type "hr" must be terminated by the matching end-tag "". at line -1 column -1: The element type "hr" must be terminated by the matching end-tag "".

XSD
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:alf="http://www.alfresco.org" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:include schemaLocation="/getCreationDate.jsp"/>
  <xs:element name="News">
    <xs:complexType>
      <xs:sequence>
        <xs:element minOccurs="1" maxOccurs="2" name="Content">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="Title" type="xs:normalizedString" />
              <xs:element name="Body" type="xs:string" />
            </xs:sequence>
            <xs:attribute name="lang">
              <xs:simpleType>
                <xs:restriction base="xs:normalizedString">
                  <xs:enumeration value="en">
                    <xs:annotation>
                      <xs:appinfo>
                        <alf:label xmlns:alf="http://www.alfresco.org">English</alf:label>
                      </xs:appinfo>
                    </xs:annotation>
                  </xs:enumeration>
                  <xs:enumeration value="fr">
                    <xs:annotation>
                      <xs:appinfo>
                        <alf:label xmlns:alf="http://www.alfresco.org">Français</alf:label>
                      </xs:appinfo>
                    </xs:annotation>
                  </xs:enumeration>
                </xs:restriction>
              </xs:simpleType>
            </xs:attribute>
          </xs:complexType>
        </xs:element>
        <xs:element name="Type">
          <xs:simpleType>
            <xs:restriction base="xs:normalizedString">
              <xs:enumeration value="Financial Results" />
              <xs:enumeration value="Internal Communications" />
            </xs:restriction>
          </xs:simpleType>
        </xs:element>
        <xs:element name="PublishingDate" type="xs:date" />
        <xs:element name="CreationDate" type="creation_date"/>
        <xs:element name="NbForIndex" type="xs:integer">
          <xs:annotation>
            <xs:appinfo>
              <alf:label xmlns:alf="http://www.alfresco.org">How much will appear on index?</alf:label>
            </xs:appinfo>
          </xs:annotation>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

JSP
<jsp:root version="1.2" xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:c="http://java.sun.com/jsp/jstl/core">
<jsp:directive.page language="java" contentType="text/html; charset=UTF-8" isELIgnored="false"/>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:alf="http://www.alfresco.org/alfresco" elementFormDefault="qualified">
   <xs:simpleType name="creation_date">
      <xs:restriction base="xs:normalizedString">
         <jsp:element name="xs:normalizedString">
            <jsp:attribute name="value"><c:out value="2008-01-25"/></jsp:attribute>
            <jsp:body>
               <xs:annotation>
                  <xs:appinfo>
                     <alf:label><c:out value="CreationDate"/></alf:label>
                  </xs:appinfo>
               </xs:annotation>
            </jsp:body>
         </jsp:element>
      </xs:restriction>
   </xs:simpleType>
</xs:schema>
</jsp:root>

pmonks
Star Contributor
Star Contributor
For starters the MIME type (content type) returned by the JSP is wrong - the MIME type for XML Schema is "text/xml".

The error message suggests that the XML Schema fragment generated by the JSP is not valid, so in addition to fixing the MIME type it would also be worth previewing the JSP directly (via the "preview" icon in the Alfresco web client) and validating the output with an XML validation tool.

xexiz
Champ in-the-making
Champ in-the-making
ok, the error is now

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

so i guess then my JSP isnt right! Smiley Sad even if I've type <xs:simpleType name="creation_date">

pmonks
Star Contributor
Star Contributor
Did you validate the output from the JSP in an XML validation tool (XML Spy, oXygen, etc.)?

xexiz
Champ in-the-making
Champ in-the-making
the JSP seems to generate this source:

<?xml version="1.0" encoding="utf-8" ?>
<xs:schema xmlns:alf="http://www.alfresco.org/alfresco" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
   <xs:simpleType name="creation_date">
      <xs:restriction base="xs:normalizedString">
         <xs:normalizedString value="2008-01-25">
            <xs:annotation>
               <xs:appinfo>
                  <alf:label>CreationDate</alf:label>
               </xs:appinfo>
            </xs:annotation>
         </xs:normalizedString>
      </xs:restriction>
   </xs:simpleType>
</xs:schema>
which is unvalid "The 'http://www.w3.org/2001'XMLSchema:normalizedString' element is not supported in this context.

but the fact is I really dont know what to put in the jsp so it could include the today's date! I pick something from the forum and try to modify it but I've never write a JSP which would define a schema type.. so i'm kinda lost… Smiley Sad

pmonks
Star Contributor
Star Contributor
Generating XML Schema from a JSP is not really any different from generating anything else from a JSP, except that XML Schema has a strict format that must be adhered to.  A good introduction to XML Schema is at: http://www.w3schools.com/schema/default.asp.

An XML tool with strong XML Schema support can help too - you might start by constructing the schema by hand in the tool, for example, then paste that into the JSP to get the dynamic include working, then finally replace hardcoded portions of the schema with JSP logic.