As we transition to the new Hyland Community, some post links may be temporarily disrupted as we finalize redirects. We apologize for the inconvenience and are working to resolve this as quickly as possible. Details.
package com.cascading.demo; import java.util.List; import javax.faces.component.StateHolder; import javax.faces.component.UIComponent; import javax.faces.context.FacesContext; import javax.faces.convert.Converter; import javax.faces.convert.ConverterException; import javax.faces.model.SelectItem; public class ListOfValuesQueryConverter implements Converter,StateHolder { private List<SelectItem> list; public ListOfValuesQueryConverter(List<SelectItem> list) { this.list=list; } public Object getAsObject(FacesContext context, UIComponent component, String value) throws ConverterException { return new Object(); } @SuppressWarnings("unchecked") public String getAsString(FacesContext context, UIComponent component, Object value) throws ConverterException { if(value instanceof String) { for(SelectItem item : list) { if (item.getValue().equals(value)) { return item.getLabel(); } } } else if(value instanceof List) { String result=""; for(String val : (List<String>)value) { for(SelectItem item : list) { if (item.getValue().equals(val)) { result += item.getLabel() + " "; break; } } } return result; } return new String(); } public ListOfValuesQueryConverter() {} public Object saveState(FacesContext context) { return (Object)this.list; } public void restoreState(FacesContext context, Object state) { this.list=(List<SelectItem>)state; } public boolean isTransient() { return false; } public void setTransient(boolean newTransientValue) {} }
package com.cascading.demo; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; import java.util.ArrayList; import java.util.List; import javax.faces.component.UIComponent; import javax.faces.component.UIOutput; import javax.faces.component.UISelectItems; import javax.faces.component.UISelectOne; import javax.faces.context.FacesContext; import javax.faces.model.SelectItem; import org.alfresco.service.cmr.dictionary.PropertyDefinition; import org.alfresco.web.app.servlet.FacesHelper; import org.alfresco.web.bean.generator.TextFieldGenerator; import org.alfresco.web.bean.repository.Node; import org.alfresco.web.ui.common.ComponentConstants; import org.alfresco.web.ui.repo.component.property.PropertySheetItem; import org.alfresco.web.ui.repo.component.property.UIPropertySheet; public class CustomListComponentGenerator extends TextFieldGenerator { @Override public UIComponent generate(FacesContext context, String id) { UIOutput component = (UIOutput) context.getApplication() .createComponent(ComponentConstants.JAVAX_FACES_OUTPUT); component.setRendererType(ComponentConstants.JAVAX_FACES_TEXT); FacesHelper.setupComponentId(context, component, id); return component; } protected UIComponent createComponent(FacesContext context, UIPropertySheet propertySheet, PropertySheetItem item) { /* * UIComponent component = super.createComponent(context, propertySheet, * item); if (component instanceof UISelectOne) * component.getAttributes().put("onchange", "submit()"); * System.out.println("IN createComponent"); return component; */ UIComponent component = null; PropertyDefinition propertyDef = getPropertyDefinition(context, propertySheet.getNode(), item.getName()); if (propertySheet.inEditMode()) { Node currentNode = (Node) propertySheet.getNode(); component = context.getApplication().createComponent( UISelectOne.COMPONENT_TYPE); FacesHelper.setupComponentId(context, component, item.getName()); UISelectItems itemsComponent = (UISelectItems) context .getApplication() .createComponent("javax.faces.SelectItems"); List<SelectItem> valueList = getValueList(currentNode, propertyDef); itemsComponent.setValue(valueList); component.getChildren().add(itemsComponent); } else { component = generate(context, item.getName()); } if (component instanceof UISelectOne) { // component.getAttributes().put("autoSubmit", Boolean.TRUE); component.getAttributes().put("onchange", "submit()"); } return component; } private List<SelectItem> getValueList(Node currentNode, PropertyDefinition propertyDef) { List<SelectItem> valueList = new ArrayList<SelectItem>(); System.out.println("Debugg:" + propertyDef.getName().toString()); // Create ContactName List boolean root = false; if (propertyDef.getName().toString() .equals("{http://www.cascading.com/model/content/1.0}car")) { String baantendernumber = null; if (currentNode.hasProperty("ccd:car")) { String driverName = "org.gjt.mm.mysql.Driver"; String serverName = "localhost"; String mydatabase = "cascading"; String username = "root"; String password = "root"; Connection connection = null; Statement stmt = null; ResultSet rs = null; try { Class.forName(driverName); String url = "jdbc:mysql://" + serverName + "/" + mydatabase; connection = DriverManager.getConnection(url, username, password); stmt = connection.createStatement(); rs = stmt.executeQuery("select code,label from codelabel"); valueList.add(new SelectItem("–Select–", "–Select–")); while (rs.next()) { System.out.println("debugg:" + rs.getString("code")); valueList.add(new SelectItem(rs.getString("code"), rs .getString("label"))); } } catch (Exception e) { } // valueList.add(new SelectItem("indian","indian")); // valueList.add(new SelectItem("russian","russian")); } } if (propertyDef.getName().toString() .equals("{http://www.cascading.com/model/content/1.0}car1")) { String countryName = (String) currentNode.getProperties().get( "{http://www.cascading.com/model/content/1.0}car"); if (countryName != null && countryName.equals("india")) { valueList.add(new SelectItem("–Select–", "–Select–")); valueList.add(new SelectItem("indian1", "indian1")); valueList.add(new SelectItem("indian2", "indian2")); } else if (countryName != null && countryName.equals("russia")) { valueList.add(new SelectItem("–Select–", "–Select–")); valueList.add(new SelectItem("russian1", "russian1")); valueList.add(new SelectItem("russian2", "russian2")); } else { valueList.add(new SelectItem("–Select–", "–Select–")); } } if (propertyDef.getName().toString() .equals("{http://www.cascading.com/model/content/1.0}car2")) { String countryName = (String) currentNode.getProperties().get( "{http://www.cascading.com/model/content/1.0}car1"); if (countryName != null && countryName.equals("indian1")) { valueList.add(new SelectItem("–Select–", "–Select–")); valueList.add(new SelectItem("indian11", "indian11")); valueList.add(new SelectItem("indian12", "indian12")); } else if (countryName != null && countryName.equals("russian1")) { valueList.add(new SelectItem("–Select–", "–Select–")); valueList.add(new SelectItem("russian11", "russian11")); valueList.add(new SelectItem("russian12", "russian12")); } else if (countryName != null && countryName.equals("indian2")) { valueList.add(new SelectItem("–Select–", "–Select–")); valueList.add(new SelectItem("indian21", "indian21")); valueList.add(new SelectItem("indian22", "indian22")); } else if (countryName != null && countryName.equals("russian2")) { valueList.add(new SelectItem("–Select–", "–Select–")); valueList.add(new SelectItem("russian21", "russian21")); valueList.add(new SelectItem("russian22", "russian22")); } else { valueList.add(new SelectItem("–Select–", "–Select–")); } } if (propertyDef.getName().toString() .equals("{http://www.cascading.com/model/content/1.0}car3")) { String countryName = (String) currentNode.getProperties().get( "{http://www.cascading.com/model/content/1.0}car2"); if (countryName != null && countryName.equals("indian11")) { valueList.add(new SelectItem("–Select–", "–Select–")); valueList.add(new SelectItem("indian111", "indian111")); valueList.add(new SelectItem("indian112", "indian112")); } else if (countryName != null && countryName.equals("russian11")) { valueList.add(new SelectItem("–Select–", "–Select–")); valueList.add(new SelectItem("russian111", "russian111")); valueList.add(new SelectItem("russian112", "russian112")); } else if (countryName != null && countryName.equals("indian21")) { valueList.add(new SelectItem("–Select–", "–Select–")); valueList.add(new SelectItem("indian211", "indian211")); valueList.add(new SelectItem("indian212", "indian212")); } else if (countryName != null && countryName.equals("russian21")) { valueList.add(new SelectItem("–Select–", "–Select–")); valueList.add(new SelectItem("russian211", "russian211")); valueList.add(new SelectItem("russian212", "russian212")); } else { valueList.add(new SelectItem("–Select–", "–Select–")); } } return valueList; } protected void setupConverter(FacesContext context, UIPropertySheet propertySheet, PropertySheetItem property, PropertyDefinition propertyDef, UIComponent component) { super.setupConverter(context, propertySheet, property, propertyDef, component); if (!propertySheet.inEditMode() && propertyDef != null && component instanceof UIOutput) { Node currentNode = (Node) propertySheet.getNode(); ((UIOutput) component).setConverter(new ListOfValuesQueryConverter( this.getValueList(currentNode, propertyDef))); } } }