cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic changing of Web Form labels

dynamolalit
Champ on-the-rise
Champ on-the-rise
Hi,

I have a requirement that states when user changes the language selection in alfresco say from English to German,the xsd using which he is generating the content ,that xsd labels should be changed from English to translated German labels automatically  when user selects to create the content.
For this,i have written a java class which will load property file as per language selection whose snippet is as

public void setLabels(String langPassed) {
      LabelPropertyReader.setLabelPropertyFile(langPassed);
      DynamicXSDGenerator generator = new DynamicXSDGenerator();
      generator.getLanguageLabel();      
      generator.getLevel1Label();
      generator.getLevel2Label();
      generator.getLevel3Label();
      generator.getLevel4Label();
      generator.getHeadingLabel();
      generator.getTaxonomyLabel();
      generator.getBodyLabel();
      generator.getRelatedInfoLabel();
      generator.getLinkNameLabel();
      generator.getLinkUrlLabel();
      generator.getLinkDescLabel();
      generator.getLinkOwnerLabel();
      generator.getLinkOwnerEmailLabel();
      generator.getLinkExpDateLabel();
      generator.getContentExpDateLabel();
   }

where LabelPropertyReader class is another class whcih loads the file actually.

Now,i have created a tld for exposing java methods to xml as :


<?xml version="1.0" encoding="UTF-8" ?>

<taglib xmlns="http://java.sun.com/xml/ns/j2ee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-jsptaglibrary_2_0.xsd"
        version="2.0">

    <tlib-version>1.0</tlib-version>
    <short-name>ejustxsd</short-name>
    <uri>http://www.alfresco.org/alfresco/ejustxsd</uri>
     <function>
      <name>getLanguageLabel</name>
      <function-class>org.alfresco.ext.DynamicXSDGenerator</function-class>
      <function-signature>java.lang.String getLanguageLabel()</function-signature>
    </function>
    <function>
      <name>getLevel1Label</name>
      <function-class>org.alfresco.ext.DynamicXSDGenerator</function-class>
      <function-signature>java.lang.String getLevel1Label()</function-signature>
    </function>
    <function>
      <name>getLevel2Label</name>
      <function-class>org.alfresco.ext.DynamicXSDGenerator</function-class>
      <function-signature>java.lang.String getLevel2Label()</function-signature>
    </function>
    <function>
      <name>getLevel3Label</name>
      <function-class>org.alfresco.ext.DynamicXSDGenerator</function-class>
      <function-signature>java.lang.String getLevel3Label()</function-signature>
    </function>
    <function>
      <name>getLevel4Label</name>
      <function-class>org.alfresco.ext.DynamicXSDGenerator</function-class>
      <function-signature>java.lang.String getLevel4Label()</function-signature>
    </function>
    <function>
      <name>getHeadingLabel</name>
      <function-class>org.alfresco.ext.DynamicXSDGenerator</function-class>
      <function-signature>java.lang.String getHeadingLabel()</function-signature>
    </function>
    <function>
      <name>getTaxonomyLabel</name>
      <function-class>org.alfresco.ext.DynamicXSDGenerator</function-class>
      <function-signature>java.lang.String getTaxonomyLabel()</function-signature>
    </function>
    <function>
      <name>getBodyLabel</name>
      <function-class>org.alfresco.ext.DynamicXSDGenerator</function-class>
      <function-signature>java.lang.String getBodyLabel()</function-signature>
    </function>
    <function>
      <name>getRelatedInfoLabel</name>
      <function-class>org.alfresco.ext.DynamicXSDGenerator</function-class>
      <function-signature>java.lang.String getRelatedInfoLabel()</function-signature>
    </function>
    <function>
      <name>getLinkNameLabel</name>
      <function-class>org.alfresco.ext.DynamicXSDGenerator</function-class>
      <function-signature>java.lang.String getLinkNameLabel()</function-signature>
    </function>
    <function>
      <name>getLinkUrlLabel</name>
      <function-class>org.alfresco.ext.DynamicXSDGenerator</function-class>
      <function-signature>java.lang.String getLinkUrlLabel()</function-signature>
    </function>
    <function>
      <name>getLinkDescLabel</name>
      <function-class>org.alfresco.ext.DynamicXSDGenerator</function-class>
      <function-signature>java.lang.String getLinkDescLabel()</function-signature>
    </function>
    <function>
      <name>getLinkOwnerLabel</name>
      <function-class>org.alfresco.ext.DynamicXSDGenerator</function-class>
      <function-signature>java.lang.String getLinkOwnerLabel()</function-signature>
    </function>
    <function>
      <name>getLinkOwnerEmailLabel</name>
      <function-class>org.alfresco.ext.DynamicXSDGenerator</function-class>
      <function-signature>java.lang.String getLinkOwnerEmailLabel()</function-signature>
    </function>
    <function>
      <name>getLinkExpDateLabel</name>
      <function-class>org.alfresco.ext.DynamicXSDGenerator</function-class>
      <function-signature>java.lang.String getLinkExpDateLabel()</function-signature>
    </function>
    <function>
      <name>getContentExpDateLabel</name>
      <function-class>org.alfresco.ext.DynamicXSDGenerator</function-class>
      <function-signature>java.lang.String getContentExpDateLabel()</function-signature>
    </function>   
</taglib>

Also, i have used this tld in my xsd as below:


<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
   xmlns:eJustice_Small_Claims="http://www.alfresco.org/alfresco/eJustice_Small_Claims,http://www.alfresco.org/alfresco/ejustxsd"
   targetNamespace="http://www.alfresco.org/alfresco/eJustice_Small_Claims,http://www.alfresco.org/alfresco/ejustxsd"
   xmlns:alf="http://www.alfresco.org"   
   elementFormDefault="qualified">

<xs:element name="eJustice_Small_Claims">
      <xs:annotation>
         <xs:documentation source="ospi.label">eJustice_Small_Claims_Title</xs:documentation>
         <xs:documentation source="ospi.description">eJustice_Small_Claims_Desc</xs:documentation>
      </xs:annotation>
      <xs:complexType>
         <xs:sequence>
         <xs:element name="eJustice_language" type="eJustice_Small_Claims:LanguageSelect"
                default="English">
               <xs:annotation>
                   <xs:appinfo>
                     <alf:label>${ejustxsd:getLanguageLabel}</alf:label>
                     <alf:appearance>compact</alf:appearance>
                    </xs:appinfo>
               </xs:annotation>
         </xs:element>      
…..
</xs:schema>
      

Here i want to update the name or <alf:label> tag to show appropriate label.

Also i have placed this tld file in WEB-INF directory of alfresco war & declared entry for this in ../WEB-INF/web.xml as

 
<taglib>
    <taglib-uri>http://www.alfresco.org/alfresco/ejustxsd</taglib-uri>
    <taglib-location>/WEB-INF/ejsutxsd.tld</taglib-location>
</taglib>

But i am getting this on my Web Client

$$ejustxsd:getLanguageLabel$$

What i can understand form this is that alfresco is not able to parse the "ejustxsd:getLanguageLabel".Its taking this as static only.

Can anyone help me on this.
1 REPLY 1

dynamolalit
Champ on-the-rise
Champ on-the-rise
Oops…  :shock:

I went too far this time.Simpler way is to put ${labelName} in xsd & define properties in language.properties files as:

<?xml version="1.0"?>

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

<xs:element name="eJustice_Small_Claims">
      <xs:annotation>
         <xs:documentation source="ospi.label">eJustice_Small_Claims_Title</xs:documentation>
         <xs:documentation source="ospi.description">eJustice_Small_Claims_Desc</xs:documentation>
      </xs:annotation>
      <xs:complexType>
         <xs:sequence>
         <xs:element name="eJustice_language" type="eJustice_Small_Claims:LanguageSelect"
                default="English">
               <xs:annotation>
                   <xs:appinfo>
                     <alf:label>${language}</alf:label>
                     <alf:appearance>compact</alf:appearance>
                    </xs:appinfo>
               </xs:annotation>
         </xs:element>   
….
</xs:schema>

where "language" property is defined in English property file as :

language=Language

& for Geman label is

language=Sprache

Simply update properties files as per language under "../WEB-INF/classes/alfresco/messages" folder in alfresco war with your required labels & alfresco will do the rest.
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.