2011-03-18 6 views
0

동적 목록 제약 조건을 만들려고했습니다. 항목이 데이터베이스에 추가되면 드롭 다운의 데이터가 새로 고쳐지지 않습니다.데이터리스트에서 alfresco에서 동적 목록 제약 조건이 업데이트되지 않습니다.

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); 
} 
} 

CustomListComponentGenerator.java

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; 
} 

} 

맞춤 model.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> 

웹 클라이언트 설정-있는 Custom.xml

<config evaluator="node-type" condition="cdl:assignationform"> 
    <property-sheet> 
     <show-property name="cdl:assignationpropertyRef" component-generator="CustomListComponentGenerator" /> 
    </property-sheet> 
    </config> 

얼굴 - 설정 - beans.xml 환경 나는 다른 파일을 변경해야하는지 여부를 모르는

<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> 

또는 위의 코드에서 잘못된 점이 있습니다. 새로운 소식 alfresco. 어떤 도움도 깊이 감사드립니다.

감사합니다, Pavani

+0

검사로 컴파일 자바를 복사해야합니다? f = 4 및 t = 11687 – shorif2000

답변

0

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); 
    } 
} 

맞춤 model.xml

ListOfCountriesQueryConstraint.java를 다음 시도하고

를 작동하기 때문에, 필요에 따라 변경

<constraint name="sp:country" type="org.spectrum.customConstraints.ListOfCountriesQueryConstraint"> <parameter name="allowedValues"> <list> </list> </parameter> <parameter name="caseSensitive"><value>true</value></parameter> </constraint> 

바람둥이/webapps에/야외/WEB-INF/클래스 여기 https://forums.alfresco.com/en/viewtopic.php/조직이/XXX/

관련 문제