cancel
Showing results for 
Search instead for 
Did you mean: 

generating a 'created date' field for web content

bjornl
Champ in-the-making
Champ in-the-making
Hi,

I need to be able to produce listings of web content sorted on date, so it would be very useful to have the creation time of the generated xml file as a field in that generated file, like so;


<mytype>
<createdDate>2007-06-04</createdDate>
<anothernode />
</mytype>

Does anyone have a good idea how to achieve this without adding a date to the xsd definition itself, in that way relying on the user to enter a correct date?
Would there be a way to for example in some way render the date as a "fixed" or "default" element in the xsd only the first time it is rendered? Or anyone has a better approach to this?

// Björn
3 REPLIES 3

kvc
Champ in-the-making
Champ in-the-making
Bjorn:


You can add a callout to your web form to generate the date field, and then return that as a read-only field.

Here's an example of how read-only fields (fixed fields) can be specified in your XSD.  This works for both elements and attributes.  Note that difference between default and fixed values, where default is a pre-set modifiable value populated at form instantiation, and where fixed is returned read-only:


<xs:element name="elements">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="fixed_string" type="xs:normalizedString" fixed="fixed string element value"/>
              <xs:element name="default_string" type="xs:normalizedString" default="default string element value"/>
              <xs:element name="fixed_integer" type="xs:integer" fixed="3"/>
              <xs:element name="default_integer" type="xs:integer" default="3"/>
              <xs:element name="fixed_date" type="xs:date" fixed="1978-08-08"/>
              <xs:element name="default_date" type="xs:date" default="1978-08-08"/>
              <xs:element name="fixed_time" type="xs:time" fixed="14:45:00"/>
              <xs:element name="default_time" type="xs:time" default="14:45:00"/>
              <xs:element name="fixed_radio" type="five_string_values" fixed="three">
                <xs:annotation><xs:appinfo><alf:appearance>full</alf:appearance></xs:appinfo></xs:annotation>
              </xs:element>
              <xs:element name="default_radio" type="five_string_values" default="three">
                <xs:annotation><xs:appinfo><alf:appearance>full</alf:appearance></xs:appinfo></xs:annotation>
              </xs:element>
              <xs:element name="fixed_combobox" type="five_string_values" fixed="three">
                <xs:annotation><xs:appinfo><alf:appearance>minimal</alf:appearance></xs:appinfo></xs:annotation>
              </xs:element>
              <xs:element name="default_combobox" type="five_string_values" default="three">
                <xs:annotation><xs:appinfo><alf:appearance>minimal</alf:appearance></xs:appinfo></xs:annotation>
              </xs:element>
              <xs:element name="fixed_textarea" type="xs:string" fixed="fixed string value"/>
              <xs:element name="default_textarea" type="xs:string" default="default string value"/>
              <xs:element name="fixed_checkbox" type="xs:boolean" fixed="true"/>
              <xs:element name="default_checkbox" type="xs:boolean" default="true"/>
            </xs:sequence>
          </xs:complexType>
        </xs:element>


Let us know if you have any further questions.


Kevin

bjornl
Champ in-the-making
Champ in-the-making
Yeah I get the simple part, the fixed attribute. But what do you mean by "making a callout to my webform"? Could you give an example?

kvc
Champ in-the-making
Champ in-the-making
Bjorn:


You can use an xs:include in your schema to reference a JSP contained within   your web project to dynamically construct portions of the schema prior to our generating the XForm and rendering HTML form for the end-user to fill out.  You reference the JSP as follows in your schema:


  <xs:include schemaLocation="/media/releases/get_company_footer_choices_simple_type.jsp"/>

Note that the JSP page must be contained within your web project (if the form is subscribed to by a web project not having that JSP, it will not work.  We do plan on supporting centralized callouts in the data dictionary at a future point in time.

The implementation in the JSP you can find here:



<jsp:root version="1.2"
          xmlns:jsp="http://java.sun.com/JSP/Page"
     xmlns:c="http://java.sun.com/jsp/jstl/core"
     xmlns:pr="http://www.alfresco.org/alfresco/pr">  
  <!– xmlns:pr is mapped to /WEB-INF/pr.tld by web.xml –>
  <jsp:directive.page language="java" contentType="text/html; charset=UTF-8"/>
  <jsp:directive.page isELIgnored="false"/>

  <!–
  The expected output is in the form:
  <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
             xmlns:alfresco="http://www.alfresco.org/alfresco"
        elementFormDefault="qualified">
    <xs:simpleType name="company_footer_choices">
      <xs:restriction base="xs:string">
        <xs:enumeration value="company_footer_1.xml">
     <xs:annotation>
       <xs:appinfo>
         <alfresco:label>Company Footer 1 Name</alfresco:label>
       </xs:appinfo>
     </xs:annotation>
        </xs:enumeration>
        <xs:enumeration value="company_footer_2.xml">
     <xs:annotation>
       <xs:appinfo>
         <alfresco:label>Company Footer 2 Name</alfresco:label>
       </xs:appinfo>
     </xs:annotation>
        </xs:enumeration>
      </xs:restriction>
    </xs:simpleType>
  </xs:schema>
  –>
  <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
             xmlns:alf="http://www.alfresco.org"
          elementFormDefault="qualified">
    <xs:simpleType name="company_footer_choices">
      <xs:restriction base="xs:normalizedString">
   <!– call into CompanyFooterBean to retrieve all company footers –>
        <c:forEach items="${pr:getCompanyFooterChoices(pageContext)}" var="companyFooter">
          <jsp:element name="xs:enumeration">
       <!– this is the file name of the company footer –>
       <jsp:attribute name="value"><c:out value="${companyFooter.fileName}"/></jsp:attribute>
            <jsp:body>
           <xs:annotation>
           <xs:appinfo>
        <!– this produces the label displayed in the combobox within the press release form –>
                  <alf:label><c:out value="${companyFooter.name}"/></alf:label>
      </xs:appinfo>
              </xs:annotation>
            </jsp:body>
     </jsp:element>
        </c:forEach>
      </xs:restriction>
    </xs:simpleType>
  </xs:schema>
</jsp:root>

Let me know if that helps.


Kevin