TCProperty property = item.getLatestItemRevision().getTCProperty("xxx_lll_xxx"); String lovTrueValueByDisplayValue1 = LOVUtil.getInstance().getLOVValueByDisplayValue(property.getLOV(), "组内"); LOVUtil.getInstance().setStringTCLOVProperty(property,lovTrueValueByDisplayValue1);
public String getLOVValueByDisplayValue(TCComponentListOfValues lov, Object object) { if (lov == null) { return ""; } try { TCComponentListOfValues[] childs = lov.getListOfFilters(); for (int i = 0; i < childs.length; i++) { try { if (childs[i] == null) { continue; } String tmp = getLOVValueByDisplayValue(childs[i], object); if (StringUtils.isNotEmpty(tmp)) { return tmp; } } catch (Exception e) { e.printStackTrace(); } } // 取LOV所有值与属性 ListOfValuesInfo valuesInfo = lov.getListOfValues(true); Object[] values = valuesInfo.getListOfValues(); // String[] descriptions = valuesInfo.getDescriptions(); // 取值对应的属性 for (int i = 0; i < values.length; i++) { if (valuesInfo.getDisplayableValue(values[i]).equals(object)) { return values[i].toString(); } } } catch (Exception tce) { tce.printStackTrace(); return ""; } return ""; }
public void setStringTCLOVProperty(TCProperty property,String value) { try { if(property.getLOV() != null) { int type = property.getPropertyType(); String lovTrueValueByDisplayValue = LOVUtil.getInstance().getLOVValueByDisplayValue(property.getLOV(), value); // if(lovTrueValueByDisplayValue != null) { if(TCProperty.PROP_int == type) { if(lovTrueValueByDisplayValue.trim().length() > 0){ int intValue = Integer.parseInt(lovTrueValueByDisplayValue); property.setIntValue(intValue); }else { property.setNullVerdict(true); } }else if(TCProperty.PROP_double == type) { if(lovTrueValueByDisplayValue.trim().length() > 0){ double doubleValue = Double.parseDouble(lovTrueValueByDisplayValue); property.setDoubleValue(doubleValue); }else { property.setNullVerdict(true); } }else if(TCProperty.PROP_string == type) { property.setStringValue(value); }else { property.setStringValue(value); } } } }catch (TCException e) { e.printStackTrace(); } }