Dynamic 动态列表约束未在数据列表的alfresco中更新

Dynamic 动态列表约束未在数据列表的alfresco中更新,dynamic,datalist,alfresco,constraints,Dynamic,Datalist,Alfresco,Constraints,我试图创建一个动态列表约束。将项目添加到数据库时,下拉列表中的数据不会刷新 ListOfValuesQueryConstraint.java package org.alfresco.ryden; import java.util.ArrayList; import java.util.List; import java.io.Serializable; import java.sql.*; import org.alfresco.repo.dictionary.constraint.Lis

我试图创建一个动态列表约束。将项目添加到数据库时,下拉列表中的数据不会刷新

ListOfValuesQueryConstraint.java

package org.alfresco.ryden;

import java.util.ArrayList;

import java.util.List;
import java.io.Serializable;
import java.sql.*;
import org.alfresco.repo.dictionary.constraint.ListOfValuesConstraint;
import org.alfresco.web.bean.generator.BaseComponentGenerator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import javax.faces.model.SelectItem;
public class ListOfValuesQueryConstraint extends ListOfValuesConstraint implements Serializable {

private static Log logger = LogFactory.getLog(BaseComponentGenerator.class);
private static final long serialVersionUID=1;

private List allowedLabels;

public void setAllowedValues(List allowedValues) {}
public void setCaseSensitive(boolean caseSensitive) {}

public void initialize() {
super.setCaseSensitive(false);
this.loadDB();
}
public List getAllowedValues() {
this.loadDB();
return super.getAllowedValues(); // In earlier post there is no return statement..
//return this.getAllowedValues();
}
public List getAllowedLabels() {
return this.allowedLabels;
}

public void setAllowedLabels(List allowedLabels) {
this.allowedLabels=allowedLabels;
}

public List getSelectItemList() {
List result = new ArrayList(this.getAllowedValues().size());
for(int i=0;i<this.getAllowedValues().size();i++) {
result.add(new SelectItem((Object)this.getAllowedValues().get(i),this.allowedLabels.get(i)));
}
return result;
}

protected void loadDB() {

String driverName = "com.mysql.jdbc.Driver";
String serverName = "localhost:3307";
String mydatabase = "propertyrecord";
String username = "propertyrecord";
String password = "rydenproperty";

List av = new ArrayList();
List al=new ArrayList();

try {
Connection connection = null;
Class.forName(driverName);
String url = “jdbc:mysql://” + serverName + “/” + mydatabase;
connection = DriverManager.getConnection(url, username, password);
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery(“select propertyRef from propertyrecord”);
while (rs.next()) {
av.add(rs.getString(“propertyRef”));
al.add(rs.getString(“propertyRef”));
System.out.println(“value of prop pavani “+rs.getString(“propertyRef”));
logger.debug(“value of prop pavani “+rs.getString(“propertyRef”));
}
rs=null;
}
catch (Exception e) {}

super.setAllowedValues(av);
this.setAllowedLabels(al);
}
}
package org.alfresco.ryden;

import java.util.List;

import javax.faces.component.UIComponent;
import javax.faces.component.UISelectOne;
import javax.faces.context.FacesContext;

import org.alfresco.repo.dictionary.constraint.ListOfValuesConstraint;
import org.alfresco.service.cmr.dictionary.Constraint;
import org.alfresco.service.cmr.dictionary.ConstraintDefinition;
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
import org.alfresco.web.bean.generator.TextFieldGenerator;
import org.alfresco.web.ui.repo.component.property.PropertySheetItem;
import org.alfresco.web.ui.repo.component.property.UIPropertySheet;
import org.apache.log4j.Logger;

import org.alfresco.ryden.ListOfValuesQueryConstraint;

public class CustomListComponentGenerator extends TextFieldGenerator {
private static Logger log = Logger.getLogger(CustomListComponentGenerator.class);

// private String tutorialQuery =
// “( TYPE:\”{http://www.alfresco.org/model/content/1.0}content\” AND
// (@\\{http\\://www.alfresco.org/model/content/1.0\\}name:\”tutorial\”
// TEXT:\”tutorial\”))”
// ;

private boolean autoRefresh = false;

public boolean isAutoRefresh() {
return autoRefresh;
}

/**
* This gets set from faces-config-beans.xml, and allows some drop downs to
* be automaticlaly refreshable (i.e. country), and others not (i.e. city).
*/
public void setAutoRefresh(boolean autoRefresh) {
this.autoRefresh = autoRefresh;
}

@Override
@SuppressWarnings(“unchecked”)
protected UIComponent createComponent(FacesContext context, UIPropertySheet propertySheet, PropertySheetItem item) {
UIComponent component = super.createComponent(context, propertySheet, item);
log.info(“********************** ” + item + ” >” + component + ” >” + (component instanceof UISelectOne) + ” ” + isAutoRefresh());
if (component instanceof UISelectOne && isAutoRefresh()) {
component.getAttributes().put(“onchange”, “submit()”);
}
return component;
}

/**
* Retrieves the list of values constraint for the item, if it has one
*
* @param context
* FacesContext
* @param propertySheet
* The property sheet being generated
* @param item
* The item being generated
* @return The constraint if the item has one, null otherwise
*/
protected ListOfValuesConstraint getListOfValuesConstraint(FacesContext context, UIPropertySheet propertySheet, PropertySheetItem item) {
ListOfValuesConstraint lovConstraint = null;

log.info(“propertySheet: ” + propertySheet.getNode() + ” item: ” + item.getName());
// get the property definition for the item
PropertyDefinition propertyDef = getPropertyDefinition(context, propertySheet.getNode(), item.getName());

if (propertyDef != null) {
// go through the constaints and see if it has the
// list of values constraint
List constraints = propertyDef.getConstraints();
for (ConstraintDefinition constraintDef : constraints) {
Constraint constraint = constraintDef.getConstraint();
//log.info(“constraint: ” + constraint);
if (constraint instanceof ListOfValuesQueryConstraint) {
//Node currentNode = (Node) propertySheet.getNode();
// This is a workaround for the fact that constraints do not
// have a reference to Node.
//((ListOfValuesQueryConstraint) constraint).setNode(currentNode);
lovConstraint = (ListOfValuesQueryConstraint) constraint;
break;
}

if (constraint instanceof ListOfValuesConstraint) {
lovConstraint = (ListOfValuesConstraint) constraint;
break;
}
}
}
return lovConstraint;
}

}
package org.spectrum.customConstraints;

import java.util.ArrayList;
import java.util.List;
import java.sql.*;
import org.alfresco.repo.dictionary.constraint.ListOfValuesConstraint;
import org.alfresco.web.bean.generator.BaseComponentGenerator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.io.Serializable;
import javax.faces.model.SelectItem;

public class ListOfCountriesQueryConstraint extends ListOfValuesConstraint implements Serializable {

    private static Log logger = LogFactory.getLog(BaseComponentGenerator.class);
    private static final long serialVersionUID = 1;
    private List<String> allowedLabels;

    @Override
    public void setAllowedValues(List allowedValues) {
    }

    @Override
    public void setCaseSensitive(boolean caseSensitive) {
    }

    @Override
    public void initialize() {
        super.setCaseSensitive(false);
        this.loadDB();
    }

    @Override
    public List getAllowedValues() {
      this.loadDB();
      return super.getAllowedValues();
    }

    public List<String> getAllowedLabels() {
        return this.allowedLabels;
    }

    public void setAllowedLabels(List<String> allowedLabels) {
        this.allowedLabels = allowedLabels;
    }

    public List<SelectItem> getSelectItemList() {
        List<SelectItem> result = new ArrayList<SelectItem>(this.getAllowedValues().size());
        for (int i = 0; i < this.getAllowedValues().size(); i++) {
            result.add(new SelectItem((Object) this.getAllowedValues().get(i), this.allowedLabels.get(i)));
        }
        return result;
    }

    protected void loadDB() {

        String driverName = "org.gjt.mm.mysql.Driver";
        String serverName = "alfrescotest";
        String mydatabase = "alfresco_custom";
        String username = "root";
        String password = "support";

        List<String> av = new ArrayList<String>();
        List<String> al = new ArrayList<String>();


        try {
            Connection connection = null;
            Class.forName(driverName);
            String url = "jdbc:mysql://" + serverName + "/" + mydatabase;
            connection = DriverManager.getConnection(url, username, password);
            Statement stmt = connection.createStatement();
            ResultSet rs = stmt.executeQuery("select country from countries");
            while (rs.next()) {
                av.add(rs.getString("country"));
                al.add(rs.getString("country"));
            }
        } catch (Exception e) {
        }

        super.setAllowedValues(av);
        this.setAllowedLabels(al);
    }
}
自定义模型.xml

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

<!-- Definition of Property Base Model -->

<model name="cdl:customdatalist" xmlns="http://www.alfresco.org/model/dictionary/1.0">

   <!-- Optional meta-data about the model -->
   <description>Custom Data Model</description>
   <author>Lalitha Akella</author>
   <version>1.0</version>

   <!-- Imports are required to allow references to definitions in other models -->
   <imports>
      <!-- Import Alfresco Dictionary Definitions -->
      <import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d"/>
      <!-- Import Alfresco Content Domain Model Definitions -->
      <import uri="http://www.alfresco.org/model/content/1.0" prefix="cm"/>
       <import uri="http://www.alfresco.org/model/datalist/1.0" prefix="dl"/>
   </imports>

   <!-- Introduction of new namespaces defined by this model -->
   <namespaces>
      <namespace uri="cdl.model" prefix="cdl"/>
   </namespaces>
     <constraints>
        <constraint name="cdl:PropertyRef" type="org.alfresco.ryden.ListOfValuesQueryConstraint" >
         <parameter name="allowedValues">
         <list>
         </list>
        </parameter>
          <parameter name="caseSensitive"><value>true</value></parameter>
        </constraint>
      </constraints>
    <types>

        <type name="cdl:applicationform">
            <title>Custom Application Form</title>
            <parent>dl:dataListItem</parent>
            <properties>
                <property name="cdl:applicationpropertyRef">
                    <title>Property Reference</title>
                    <type>d:text</type>
                    <mandatory>true</mandatory>
                    <constraints>
                        <constraint ref="cdl:PropertyRef" />
                    </constraints>
                </property>
                <property name="cdl:applicationpropAddress">
                    <title>Property Address</title>
                    <type>d:text</type>

                    <mandatory>false</mandatory>
                </property>
                <property name="cdl:apcreateddate">
                    <title>Created Date</title>
                    <type>d:date</type>
                    <mandatory>false</mandatory>
                </property>
                <property name="cdl:apcreatedby">
                    <title>Created By</title>
                    <type>d:text</type>
                    <mandatory>false</mandatory>
                </property>
                <property name="cdl:applicationstatus">
                    <title>Application Status</title>
                    <type>d:text</type>
                    <mandatory>false</mandatory>
                </property>
                <property name="cdl:applicationlink">
                    <title>Application Workflow Link</title>
                    <type>d:text</type>
                    <mandatory>false</mandatory>
                </property>
            </properties>
        <associations>
            <association name="cdl:applicationassignee">
               <title>Assignee</title>
               <source>
                  <mandatory>true</mandatory>
                  <many>true</many>
               </source>
               <target>
                  <class>cm:person</class>
                  <mandatory>true</mandatory>
                  <many>false</many>
               </target>
            </association>
            <association name="cdl:applicationattachments">
               <title>Attachments</title>
               <source>
                  <mandatory>true</mandatory>
                  <many>true</many>
               </source>
               <target>
                  <class>cm:cmobject</class>
                  <mandatory>true</mandatory>
                  <many>true</many>
               </target>
            </association>
         </associations>
      </type>   
      <type name="cdl:terminationform">
            <title>Custom Termination Form</title>
            <parent>dl:dataListItem</parent>
            <properties>
                <property name="cdl:terminationpropertyRef">
                    <title>Property Reference</title>
                    <type>d:text</type>
                    <mandatory>true</mandatory>
                    <constraints>
                        <constraint ref="cdl:PropertyRef" />
                    </constraints>
                </property>
                <property name="cdl:trcreateddate">
                    <title>Created Date</title>
                    <type>d:date</type>
                    <mandatory>false</mandatory>
                </property>
                <property name="cdl:trcreatedby">
                    <title>Created By</title>
                    <type>d:text</type>
                    <mandatory>false</mandatory>
                </property>
                <property name="cdl:terminationstatus">
                    <title>Termination Status</title>
                    <type>d:text</type>
                    <mandatory>false</mandatory>
                </property>
                <property name="cdl:terminationlink">
                    <title>Termination Workflow Link</title>
                    <type>d:text</type>
                    <mandatory>false</mandatory>
                </property>
            </properties>
        <associations>
            <association name="cdl:terminationassignee">
               <title>Assignee</title>
               <source>
                  <mandatory>true</mandatory>
                  <many>true</many>
               </source>
               <target>
                  <class>cm:person</class>
                  <mandatory>true</mandatory>
                  <many>false</many>
               </target>
            </association>
            <association name="cdl:terminationattachments">
               <title>Attachments</title>
               <source>
                  <mandatory>true</mandatory>
                  <many>true</many>
               </source>
               <target>
                  <class>cm:cmobject</class>
                  <mandatory>true</mandatory>
                  <many>true</many>
               </target>
            </association>
         </associations>
      </type>
    </types>

</model>
<config evaluator="node-type" condition="cdl:assignationform">
    <property-sheet>
        <show-property name="cdl:assignationpropertyRef" component-generator="CustomListComponentGenerator" />
    </property-sheet>
   </config>
<managed-bean>
                <description>
                        Bean that generates a custom generator component
                </description>
                <managed-bean-name>
                        CustomListComponentGenerator
                </managed-bean-name>
                <managed-bean-class>
                        org.alfresco.ryden.CustomListComponentGenerator
                </managed-bean-class>
                <managed-bean-scope>request</managed-bean-scope>
                 <managed-property>
                        <property-name>autoRefresh</property-name>
                        <value>true</value>
                </managed-property>
        </managed-bean>
<constraint name="sp:country" type="org.spectrum.customConstraints.ListOfCountriesQueryConstraint">
                        <parameter name="allowedValues">
                        <list>
                        </list>
                </parameter>
                        <parameter name="caseSensitive"><value>true</value></parameter>
                </constraint>

自定义数据模型
拉利塔阿克拉
1
符合事实的
定制申请表
dl:dataListItem
属性引用
d:文本
符合事实的
物业地址
d:文本
错误的
创建日期
d:日期
错误的
创建人
d:文本
错误的
应用状况
d:文本
错误的
应用程序工作流链接
d:文本
错误的
受让人
符合事实的
符合事实的
cm:人
符合事实的
错误的
附件
符合事实的
符合事实的
cm:cmobject
符合事实的
符合事实的
自定义终止表格
dl:dataListItem
属性引用
d:文本
符合事实的
创建日期
d:日期
错误的
创建人
d:文本
错误的
终止状态
d:文本
错误的
终止工作流链接
d:文本
错误的
受让人
符合事实的
符合事实的
cm:人
符合事实的
错误的
附件
符合事实的
符合事实的
cm:cmobject
符合事实的
符合事实的
web客户端配置custom.xml

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

<!-- Definition of Property Base Model -->

<model name="cdl:customdatalist" xmlns="http://www.alfresco.org/model/dictionary/1.0">

   <!-- Optional meta-data about the model -->
   <description>Custom Data Model</description>
   <author>Lalitha Akella</author>
   <version>1.0</version>

   <!-- Imports are required to allow references to definitions in other models -->
   <imports>
      <!-- Import Alfresco Dictionary Definitions -->
      <import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d"/>
      <!-- Import Alfresco Content Domain Model Definitions -->
      <import uri="http://www.alfresco.org/model/content/1.0" prefix="cm"/>
       <import uri="http://www.alfresco.org/model/datalist/1.0" prefix="dl"/>
   </imports>

   <!-- Introduction of new namespaces defined by this model -->
   <namespaces>
      <namespace uri="cdl.model" prefix="cdl"/>
   </namespaces>
     <constraints>
        <constraint name="cdl:PropertyRef" type="org.alfresco.ryden.ListOfValuesQueryConstraint" >
         <parameter name="allowedValues">
         <list>
         </list>
        </parameter>
          <parameter name="caseSensitive"><value>true</value></parameter>
        </constraint>
      </constraints>
    <types>

        <type name="cdl:applicationform">
            <title>Custom Application Form</title>
            <parent>dl:dataListItem</parent>
            <properties>
                <property name="cdl:applicationpropertyRef">
                    <title>Property Reference</title>
                    <type>d:text</type>
                    <mandatory>true</mandatory>
                    <constraints>
                        <constraint ref="cdl:PropertyRef" />
                    </constraints>
                </property>
                <property name="cdl:applicationpropAddress">
                    <title>Property Address</title>
                    <type>d:text</type>

                    <mandatory>false</mandatory>
                </property>
                <property name="cdl:apcreateddate">
                    <title>Created Date</title>
                    <type>d:date</type>
                    <mandatory>false</mandatory>
                </property>
                <property name="cdl:apcreatedby">
                    <title>Created By</title>
                    <type>d:text</type>
                    <mandatory>false</mandatory>
                </property>
                <property name="cdl:applicationstatus">
                    <title>Application Status</title>
                    <type>d:text</type>
                    <mandatory>false</mandatory>
                </property>
                <property name="cdl:applicationlink">
                    <title>Application Workflow Link</title>
                    <type>d:text</type>
                    <mandatory>false</mandatory>
                </property>
            </properties>
        <associations>
            <association name="cdl:applicationassignee">
               <title>Assignee</title>
               <source>
                  <mandatory>true</mandatory>
                  <many>true</many>
               </source>
               <target>
                  <class>cm:person</class>
                  <mandatory>true</mandatory>
                  <many>false</many>
               </target>
            </association>
            <association name="cdl:applicationattachments">
               <title>Attachments</title>
               <source>
                  <mandatory>true</mandatory>
                  <many>true</many>
               </source>
               <target>
                  <class>cm:cmobject</class>
                  <mandatory>true</mandatory>
                  <many>true</many>
               </target>
            </association>
         </associations>
      </type>   
      <type name="cdl:terminationform">
            <title>Custom Termination Form</title>
            <parent>dl:dataListItem</parent>
            <properties>
                <property name="cdl:terminationpropertyRef">
                    <title>Property Reference</title>
                    <type>d:text</type>
                    <mandatory>true</mandatory>
                    <constraints>
                        <constraint ref="cdl:PropertyRef" />
                    </constraints>
                </property>
                <property name="cdl:trcreateddate">
                    <title>Created Date</title>
                    <type>d:date</type>
                    <mandatory>false</mandatory>
                </property>
                <property name="cdl:trcreatedby">
                    <title>Created By</title>
                    <type>d:text</type>
                    <mandatory>false</mandatory>
                </property>
                <property name="cdl:terminationstatus">
                    <title>Termination Status</title>
                    <type>d:text</type>
                    <mandatory>false</mandatory>
                </property>
                <property name="cdl:terminationlink">
                    <title>Termination Workflow Link</title>
                    <type>d:text</type>
                    <mandatory>false</mandatory>
                </property>
            </properties>
        <associations>
            <association name="cdl:terminationassignee">
               <title>Assignee</title>
               <source>
                  <mandatory>true</mandatory>
                  <many>true</many>
               </source>
               <target>
                  <class>cm:person</class>
                  <mandatory>true</mandatory>
                  <many>false</many>
               </target>
            </association>
            <association name="cdl:terminationattachments">
               <title>Attachments</title>
               <source>
                  <mandatory>true</mandatory>
                  <many>true</many>
               </source>
               <target>
                  <class>cm:cmobject</class>
                  <mandatory>true</mandatory>
                  <many>true</many>
               </target>
            </association>
         </associations>
      </type>
    </types>

</model>
<config evaluator="node-type" condition="cdl:assignationform">
    <property-sheet>
        <show-property name="cdl:assignationpropertyRef" component-generator="CustomListComponentGenerator" />
    </property-sheet>
   </config>
<managed-bean>
                <description>
                        Bean that generates a custom generator component
                </description>
                <managed-bean-name>
                        CustomListComponentGenerator
                </managed-bean-name>
                <managed-bean-class>
                        org.alfresco.ryden.CustomListComponentGenerator
                </managed-bean-class>
                <managed-bean-scope>request</managed-bean-scope>
                 <managed-property>
                        <property-name>autoRefresh</property-name>
                        <value>true</value>
                </managed-property>
        </managed-bean>
<constraint name="sp:country" type="org.spectrum.customConstraints.ListOfCountriesQueryConstraint">
                        <parameter name="allowedValues">
                        <list>
                        </list>
                </parameter>
                        <parameter name="caseSensitive"><value>true</value></parameter>
                </constraint>

faces config beans.xml

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

<!-- Definition of Property Base Model -->

<model name="cdl:customdatalist" xmlns="http://www.alfresco.org/model/dictionary/1.0">

   <!-- Optional meta-data about the model -->
   <description>Custom Data Model</description>
   <author>Lalitha Akella</author>
   <version>1.0</version>

   <!-- Imports are required to allow references to definitions in other models -->
   <imports>
      <!-- Import Alfresco Dictionary Definitions -->
      <import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d"/>
      <!-- Import Alfresco Content Domain Model Definitions -->
      <import uri="http://www.alfresco.org/model/content/1.0" prefix="cm"/>
       <import uri="http://www.alfresco.org/model/datalist/1.0" prefix="dl"/>
   </imports>

   <!-- Introduction of new namespaces defined by this model -->
   <namespaces>
      <namespace uri="cdl.model" prefix="cdl"/>
   </namespaces>
     <constraints>
        <constraint name="cdl:PropertyRef" type="org.alfresco.ryden.ListOfValuesQueryConstraint" >
         <parameter name="allowedValues">
         <list>
         </list>
        </parameter>
          <parameter name="caseSensitive"><value>true</value></parameter>
        </constraint>
      </constraints>
    <types>

        <type name="cdl:applicationform">
            <title>Custom Application Form</title>
            <parent>dl:dataListItem</parent>
            <properties>
                <property name="cdl:applicationpropertyRef">
                    <title>Property Reference</title>
                    <type>d:text</type>
                    <mandatory>true</mandatory>
                    <constraints>
                        <constraint ref="cdl:PropertyRef" />
                    </constraints>
                </property>
                <property name="cdl:applicationpropAddress">
                    <title>Property Address</title>
                    <type>d:text</type>

                    <mandatory>false</mandatory>
                </property>
                <property name="cdl:apcreateddate">
                    <title>Created Date</title>
                    <type>d:date</type>
                    <mandatory>false</mandatory>
                </property>
                <property name="cdl:apcreatedby">
                    <title>Created By</title>
                    <type>d:text</type>
                    <mandatory>false</mandatory>
                </property>
                <property name="cdl:applicationstatus">
                    <title>Application Status</title>
                    <type>d:text</type>
                    <mandatory>false</mandatory>
                </property>
                <property name="cdl:applicationlink">
                    <title>Application Workflow Link</title>
                    <type>d:text</type>
                    <mandatory>false</mandatory>
                </property>
            </properties>
        <associations>
            <association name="cdl:applicationassignee">
               <title>Assignee</title>
               <source>
                  <mandatory>true</mandatory>
                  <many>true</many>
               </source>
               <target>
                  <class>cm:person</class>
                  <mandatory>true</mandatory>
                  <many>false</many>
               </target>
            </association>
            <association name="cdl:applicationattachments">
               <title>Attachments</title>
               <source>
                  <mandatory>true</mandatory>
                  <many>true</many>
               </source>
               <target>
                  <class>cm:cmobject</class>
                  <mandatory>true</mandatory>
                  <many>true</many>
               </target>
            </association>
         </associations>
      </type>   
      <type name="cdl:terminationform">
            <title>Custom Termination Form</title>
            <parent>dl:dataListItem</parent>
            <properties>
                <property name="cdl:terminationpropertyRef">
                    <title>Property Reference</title>
                    <type>d:text</type>
                    <mandatory>true</mandatory>
                    <constraints>
                        <constraint ref="cdl:PropertyRef" />
                    </constraints>
                </property>
                <property name="cdl:trcreateddate">
                    <title>Created Date</title>
                    <type>d:date</type>
                    <mandatory>false</mandatory>
                </property>
                <property name="cdl:trcreatedby">
                    <title>Created By</title>
                    <type>d:text</type>
                    <mandatory>false</mandatory>
                </property>
                <property name="cdl:terminationstatus">
                    <title>Termination Status</title>
                    <type>d:text</type>
                    <mandatory>false</mandatory>
                </property>
                <property name="cdl:terminationlink">
                    <title>Termination Workflow Link</title>
                    <type>d:text</type>
                    <mandatory>false</mandatory>
                </property>
            </properties>
        <associations>
            <association name="cdl:terminationassignee">
               <title>Assignee</title>
               <source>
                  <mandatory>true</mandatory>
                  <many>true</many>
               </source>
               <target>
                  <class>cm:person</class>
                  <mandatory>true</mandatory>
                  <many>false</many>
               </target>
            </association>
            <association name="cdl:terminationattachments">
               <title>Attachments</title>
               <source>
                  <mandatory>true</mandatory>
                  <many>true</many>
               </source>
               <target>
                  <class>cm:cmobject</class>
                  <mandatory>true</mandatory>
                  <many>true</many>
               </target>
            </association>
         </associations>
      </type>
    </types>

</model>
<config evaluator="node-type" condition="cdl:assignationform">
    <property-sheet>
        <show-property name="cdl:assignationpropertyRef" component-generator="CustomListComponentGenerator" />
    </property-sheet>
   </config>
<managed-bean>
                <description>
                        Bean that generates a custom generator component
                </description>
                <managed-bean-name>
                        CustomListComponentGenerator
                </managed-bean-name>
                <managed-bean-class>
                        org.alfresco.ryden.CustomListComponentGenerator
                </managed-bean-class>
                <managed-bean-scope>request</managed-bean-scope>
                 <managed-property>
                        <property-name>autoRefresh</property-name>
                        <value>true</value>
                </managed-property>
        </managed-bean>
<constraint name="sp:country" type="org.spectrum.customConstraints.ListOfCountriesQueryConstraint">
                        <parameter name="allowedValues">
                        <list>
                        </list>
                </parameter>
                        <parameter name="caseSensitive"><value>true</value></parameter>
                </constraint>

生成自定义生成器组件的Bean
自定义列表组件生成器
org.alfresco.ryden.CustomListComponentGenerator
要求
自动刷新
符合事实的
我不知道我是否应该更改任何其他文件,或者上面的代码中出现了一些错误。 我不熟悉户外。非常感谢您的帮助

谢谢,
Pavani

尝试以下操作,并根据需要更改为

countriesQueryConstraint.java列表

package org.alfresco.ryden;

import java.util.ArrayList;

import java.util.List;
import java.io.Serializable;
import java.sql.*;
import org.alfresco.repo.dictionary.constraint.ListOfValuesConstraint;
import org.alfresco.web.bean.generator.BaseComponentGenerator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import javax.faces.model.SelectItem;
public class ListOfValuesQueryConstraint extends ListOfValuesConstraint implements Serializable {

private static Log logger = LogFactory.getLog(BaseComponentGenerator.class);
private static final long serialVersionUID=1;

private List allowedLabels;

public void setAllowedValues(List allowedValues) {}
public void setCaseSensitive(boolean caseSensitive) {}

public void initialize() {
super.setCaseSensitive(false);
this.loadDB();
}
public List getAllowedValues() {
this.loadDB();
return super.getAllowedValues(); // In earlier post there is no return statement..
//return this.getAllowedValues();
}
public List getAllowedLabels() {
return this.allowedLabels;
}

public void setAllowedLabels(List allowedLabels) {
this.allowedLabels=allowedLabels;
}

public List getSelectItemList() {
List result = new ArrayList(this.getAllowedValues().size());
for(int i=0;i<this.getAllowedValues().size();i++) {
result.add(new SelectItem((Object)this.getAllowedValues().get(i),this.allowedLabels.get(i)));
}
return result;
}

protected void loadDB() {

String driverName = "com.mysql.jdbc.Driver";
String serverName = "localhost:3307";
String mydatabase = "propertyrecord";
String username = "propertyrecord";
String password = "rydenproperty";

List av = new ArrayList();
List al=new ArrayList();

try {
Connection connection = null;
Class.forName(driverName);
String url = “jdbc:mysql://” + serverName + “/” + mydatabase;
connection = DriverManager.getConnection(url, username, password);
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery(“select propertyRef from propertyrecord”);
while (rs.next()) {
av.add(rs.getString(“propertyRef”));
al.add(rs.getString(“propertyRef”));
System.out.println(“value of prop pavani “+rs.getString(“propertyRef”));
logger.debug(“value of prop pavani “+rs.getString(“propertyRef”));
}
rs=null;
}
catch (Exception e) {}

super.setAllowedValues(av);
this.setAllowedLabels(al);
}
}
package org.alfresco.ryden;

import java.util.List;

import javax.faces.component.UIComponent;
import javax.faces.component.UISelectOne;
import javax.faces.context.FacesContext;

import org.alfresco.repo.dictionary.constraint.ListOfValuesConstraint;
import org.alfresco.service.cmr.dictionary.Constraint;
import org.alfresco.service.cmr.dictionary.ConstraintDefinition;
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
import org.alfresco.web.bean.generator.TextFieldGenerator;
import org.alfresco.web.ui.repo.component.property.PropertySheetItem;
import org.alfresco.web.ui.repo.component.property.UIPropertySheet;
import org.apache.log4j.Logger;

import org.alfresco.ryden.ListOfValuesQueryConstraint;

public class CustomListComponentGenerator extends TextFieldGenerator {
private static Logger log = Logger.getLogger(CustomListComponentGenerator.class);

// private String tutorialQuery =
// “( TYPE:\”{http://www.alfresco.org/model/content/1.0}content\” AND
// (@\\{http\\://www.alfresco.org/model/content/1.0\\}name:\”tutorial\”
// TEXT:\”tutorial\”))”
// ;

private boolean autoRefresh = false;

public boolean isAutoRefresh() {
return autoRefresh;
}

/**
* This gets set from faces-config-beans.xml, and allows some drop downs to
* be automaticlaly refreshable (i.e. country), and others not (i.e. city).
*/
public void setAutoRefresh(boolean autoRefresh) {
this.autoRefresh = autoRefresh;
}

@Override
@SuppressWarnings(“unchecked”)
protected UIComponent createComponent(FacesContext context, UIPropertySheet propertySheet, PropertySheetItem item) {
UIComponent component = super.createComponent(context, propertySheet, item);
log.info(“********************** ” + item + ” >” + component + ” >” + (component instanceof UISelectOne) + ” ” + isAutoRefresh());
if (component instanceof UISelectOne && isAutoRefresh()) {
component.getAttributes().put(“onchange”, “submit()”);
}
return component;
}

/**
* Retrieves the list of values constraint for the item, if it has one
*
* @param context
* FacesContext
* @param propertySheet
* The property sheet being generated
* @param item
* The item being generated
* @return The constraint if the item has one, null otherwise
*/
protected ListOfValuesConstraint getListOfValuesConstraint(FacesContext context, UIPropertySheet propertySheet, PropertySheetItem item) {
ListOfValuesConstraint lovConstraint = null;

log.info(“propertySheet: ” + propertySheet.getNode() + ” item: ” + item.getName());
// get the property definition for the item
PropertyDefinition propertyDef = getPropertyDefinition(context, propertySheet.getNode(), item.getName());

if (propertyDef != null) {
// go through the constaints and see if it has the
// list of values constraint
List constraints = propertyDef.getConstraints();
for (ConstraintDefinition constraintDef : constraints) {
Constraint constraint = constraintDef.getConstraint();
//log.info(“constraint: ” + constraint);
if (constraint instanceof ListOfValuesQueryConstraint) {
//Node currentNode = (Node) propertySheet.getNode();
// This is a workaround for the fact that constraints do not
// have a reference to Node.
//((ListOfValuesQueryConstraint) constraint).setNode(currentNode);
lovConstraint = (ListOfValuesQueryConstraint) constraint;
break;
}

if (constraint instanceof ListOfValuesConstraint) {
lovConstraint = (ListOfValuesConstraint) constraint;
break;
}
}
}
return lovConstraint;
}

}
package org.spectrum.customConstraints;

import java.util.ArrayList;
import java.util.List;
import java.sql.*;
import org.alfresco.repo.dictionary.constraint.ListOfValuesConstraint;
import org.alfresco.web.bean.generator.BaseComponentGenerator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.io.Serializable;
import javax.faces.model.SelectItem;

public class ListOfCountriesQueryConstraint extends ListOfValuesConstraint implements Serializable {

    private static Log logger = LogFactory.getLog(BaseComponentGenerator.class);
    private static final long serialVersionUID = 1;
    private List<String> allowedLabels;

    @Override
    public void setAllowedValues(List allowedValues) {
    }

    @Override
    public void setCaseSensitive(boolean caseSensitive) {
    }

    @Override
    public void initialize() {
        super.setCaseSensitive(false);
        this.loadDB();
    }

    @Override
    public List getAllowedValues() {
      this.loadDB();
      return super.getAllowedValues();
    }

    public List<String> getAllowedLabels() {
        return this.allowedLabels;
    }

    public void setAllowedLabels(List<String> allowedLabels) {
        this.allowedLabels = allowedLabels;
    }

    public List<SelectItem> getSelectItemList() {
        List<SelectItem> result = new ArrayList<SelectItem>(this.getAllowedValues().size());
        for (int i = 0; i < this.getAllowedValues().size(); i++) {
            result.add(new SelectItem((Object) this.getAllowedValues().get(i), this.allowedLabels.get(i)));
        }
        return result;
    }

    protected void loadDB() {

        String driverName = "org.gjt.mm.mysql.Driver";
        String serverName = "alfrescotest";
        String mydatabase = "alfresco_custom";
        String username = "root";
        String password = "support";

        List<String> av = new ArrayList<String>();
        List<String> al = new ArrayList<String>();


        try {
            Connection connection = null;
            Class.forName(driverName);
            String url = "jdbc:mysql://" + serverName + "/" + mydatabase;
            connection = DriverManager.getConnection(url, username, password);
            Statement stmt = connection.createStatement();
            ResultSet rs = stmt.executeQuery("select country from countries");
            while (rs.next()) {
                av.add(rs.getString("country"));
                al.add(rs.getString("country"));
            }
        } catch (Exception e) {
        }

        super.setAllowedValues(av);
        this.setAllowedLabels(al);
    }
}
package org.spectrum.customConstraints;
导入java.util.ArrayList;
导入java.util.List;
导入java.sql.*;
导入org.alfresco.repo.dictionary.constraint.ListOfValuesConstraint;
导入org.alfresco.web.bean.generator.BaseComponentGenerator;
导入org.apache.commons.logging.Log;
导入org.apache.commons.logging.LogFactory;
导入java.io.Serializable;
导入javax.faces.model.SelectItem;
公共类ListOfCountriesQueryConstraint扩展了ListOfValuesConstraint实现可序列化{
私有静态日志记录器=LogFactory.getLog(BaseComponentGenerator.class);
私有静态最终长serialVersionUID=1;
允许使用的私有列表标签;
@凌驾
public void setAllowedValues(列出allowedValues){
}
@凌驾
public void setCaseSensitive(布尔值区分大小写){
}
@凌驾
公共无效初始化(){
super.setCaseSensitive(false);
这是loadDB();
}
@凌驾
公共列表getAllowedValues(){
这是loadDB();
返回super.getAllowedValues();
}
公共列表getAllowedLabels(){
返回此.allowedLabels;
}
公共void setAllowedLabels(列出allowedLabels){
this.allowedLabels=allowedLabels;
}
公共列表getSelectItemList(){
列表结果=新的ArrayList(this.getAllowedValues().size());
对于(int i=0;i