📄 modelformaction.java
字号:
List argList = (List) argListAcsr.get(context); if (argList != null && argList.size() > 0) { value = MessageFormat.format(value, argList.toArray()); } } fieldAcsr.put(context, value); } } public static class Script extends ModelFormAction { protected String location; public Script(ModelForm modelForm, Element scriptElement) { super (modelForm, scriptElement); this.location = scriptElement.getAttribute("location"); } public void runAction(Map context) { if (location.endsWith(".bsh")) { try { BshUtil.runBshAtLocation(location, context); } catch (GeneralException e) { String errMsg = "Error running BSH script at location [" + location + "]: " + e.toString(); Debug.logError(e, errMsg, module); throw new IllegalArgumentException(errMsg); } } else { throw new IllegalArgumentException("For screen script actions the script type is not yet support for location:" + location); } } } public static class Service extends ModelFormAction { protected FlexibleStringExpander serviceNameExdr; protected FlexibleMapAccessor resultMapNameAcsr; protected FlexibleStringExpander autoFieldMapExdr; protected FlexibleStringExpander resultMapListIteratorNameExdr; protected FlexibleStringExpander resultMapListNameExdr; protected Map fieldMap; public Service(ModelForm modelForm, Element serviceElement) { super (modelForm, serviceElement); this.serviceNameExdr = new FlexibleStringExpander(serviceElement.getAttribute("service-name")); this.resultMapNameAcsr = UtilValidate.isNotEmpty(serviceElement.getAttribute("result-map-name")) ? new FlexibleMapAccessor(serviceElement.getAttribute("result-map-name")) : null; this.autoFieldMapExdr = new FlexibleStringExpander(serviceElement.getAttribute("auto-field-map")); if (UtilValidate.isEmpty(serviceElement.getAttribute("result-map-list-name"))) { String lstNm = modelForm.getListName(); if (UtilValidate.isEmpty(lstNm)) { lstNm = ModelForm.DEFAULT_FORM_RESULT_LIST_NAME; } this.resultMapListNameExdr = new FlexibleStringExpander(lstNm); } else { this.resultMapListNameExdr = new FlexibleStringExpander(serviceElement.getAttribute("result-map-list-name")); } if (UtilValidate.isEmpty(serviceElement.getAttribute("result-map-list-iterator-name"))) { String lstNm = modelForm.getListIteratorName(); if (UtilValidate.isEmpty(lstNm)) { lstNm = ModelForm.DEFAULT_FORM_RESULT_LIST_NAME; } this.resultMapListIteratorNameExdr = new FlexibleStringExpander(lstNm); } else { this.resultMapListIteratorNameExdr = new FlexibleStringExpander(serviceElement.getAttribute("result-map-list-iterator-name")); } this.fieldMap = EntityFinderUtil.makeFieldMap(serviceElement); } public void runAction(Map context) { String serviceNameExpanded = this.serviceNameExdr.expandString(context); if (UtilValidate.isEmpty(serviceNameExpanded)) { throw new IllegalArgumentException("Service name was empty, expanded from: " + this.serviceNameExdr.getOriginal()); } String autoFieldMapString = this.autoFieldMapExdr.expandString(context); boolean autoFieldMapBool = !"false".equals(autoFieldMapString); try { Map serviceContext = null; if (autoFieldMapBool) { serviceContext = this.modelForm.getDispatcher(context).getDispatchContext().makeValidContext(serviceNameExpanded, ModelService.IN_PARAM, context); } else { serviceContext = new HashMap(); } if (this.fieldMap != null) { EntityFinderUtil.expandFieldMapToContext(this.fieldMap, context, serviceContext); } Map result = this.modelForm.getDispatcher(context).runSync(serviceNameExpanded, serviceContext); if (this.resultMapNameAcsr != null) { this.resultMapNameAcsr.put(context, result); String queryString = (String)result.get("queryString"); context.put("queryString", queryString); context.put("queryStringMap", result.get("queryStringMap")); if (UtilValidate.isNotEmpty(queryString)){ try { String queryStringEncoded = queryString.replaceAll("&", "%26"); context.put("queryStringEncoded", queryStringEncoded); } catch (PatternSyntaxException e) { } } } else { context.putAll(result); } String resultMapListIteratorName = resultMapListIteratorNameExdr.expandString(context); Object obj = result.get(resultMapListIteratorName); String formListIteratorName = modelForm.getListIteratorName(); if (obj != null && obj instanceof EntityListIterator) { context.put("listIteratorName", formListIteratorName); context.put(formListIteratorName, obj); } String listName = resultMapListNameExdr.expandString(context); Object listObj = result.get(listName); if (listObj != null) { if (!(listObj instanceof List)) { throw new IllegalArgumentException("Error in form [" + this.modelForm.getName() + "] calling service with name [" + serviceNameExpanded + "]: the result that is supposed to be a list is not a List. You may need to use list-iterator-name isntead of list-name, or something like that."); } List lst = (List) listObj; context.put("listName", listName); context.put(listName, lst); } } catch (GenericServiceException e) { String errMsg = "Error in form [" + this.modelForm.getName() + "] calling service with name [" + serviceNameExpanded + "]: " + e.toString(); Debug.logError(e, errMsg, module); throw new IllegalArgumentException(errMsg); } } } public static class EntityOne extends ModelFormAction { protected PrimaryKeyFinder finder; public EntityOne(ModelForm modelForm, Element entityOneElement) { super (modelForm, entityOneElement); finder = new PrimaryKeyFinder(entityOneElement); } public void runAction(Map context) { try { finder.runFind(context, this.modelForm.getDelegator(context)); } catch (GeneralException e) { String errMsg = "Error doing entity query by condition: " + e.toString(); Debug.logError(e, errMsg, module); throw new IllegalArgumentException(errMsg); } } } public static class EntityAnd extends ModelFormAction { protected ByAndFinder finder; String actualListName; public EntityAnd(ModelForm modelForm, Element entityAndElement) { super (modelForm, entityAndElement); //don't want to default to the iterator, should be specified explicitly, not the default // Document ownerDoc = entityAndElement.getOwnerDocument(); // boolean useCache = "true".equalsIgnoreCase(entityAndElement.getAttribute("use-cache")); // if (!useCache) UtilXml.addChildElement(entityAndElement, "use-iterator", ownerDoc); // make list-name optional if (UtilValidate.isEmpty(entityAndElement.getAttribute("list-name"))) { String lstNm = modelForm.getListName(); if (UtilValidate.isEmpty(lstNm)) { lstNm = modelForm.getListIteratorName(); } if (UtilValidate.isEmpty(lstNm)) { lstNm = ModelForm.DEFAULT_FORM_RESULT_LIST_NAME; } entityAndElement.setAttribute("list-name", lstNm); } this.actualListName = entityAndElement.getAttribute("list-name"); finder = new ByAndFinder(entityAndElement); } public void runAction(Map context) { try { // don't want to do this: context.put("defaultFormResultList", null); finder.runFind(context, this.modelForm.getDelegator(context)); Object obj = context.get(this.actualListName); if (obj != null && (obj instanceof EntityListIterator)) { String modelFormIteratorName = modelForm.getListIteratorName(); context.put(modelFormIteratorName, obj); } else if (obj != null && obj instanceof List) { String modelFormListName = modelForm.getListName(); context.put(modelFormListName, obj); } } catch (GeneralException e) { String errMsg = "Error doing entity query by condition: " + e.toString(); Debug.logError(e, errMsg, module); throw new IllegalArgumentException(errMsg); } } } public static class EntityCondition extends ModelFormAction { ByConditionFinder finder; String actualListName; public EntityCondition(ModelForm modelForm, Element entityConditionElement) { super (modelForm, entityConditionElement); //don't want to default to the iterator, should be specified explicitly, not the default // Document ownerDoc = entityConditionElement.getOwnerDocument(); // boolean useCache = "true".equalsIgnoreCase(entityConditionElement.getAttribute("use-cache")); // if (!useCache) UtilXml.addChildElement(entityConditionElement, "use-iterator", ownerDoc); // make list-name optional if (UtilValidate.isEmpty(entityConditionElement.getAttribute("list-name"))) { String lstNm = modelForm.getListName(); if (UtilValidate.isEmpty(lstNm)) { lstNm = modelForm.getListIteratorName(); } if (UtilValidate.isEmpty(lstNm)) { lstNm = ModelForm.DEFAULT_FORM_RESULT_LIST_NAME; } entityConditionElement.setAttribute("list-name", lstNm); } this.actualListName = entityConditionElement.getAttribute("list-name"); finder = new ByConditionFinder(entityConditionElement); } public void runAction(Map context) { try { // don't want to do this: context.put("defaultFormResultList", null); finder.runFind(context, this.modelForm.getDelegator(context)); Object obj = context.get(this.actualListName); if (obj != null && (obj instanceof EntityListIterator)) { String modelFormIteratorName = modelForm.getListIteratorName(); context.put(modelFormIteratorName, obj); } else if (obj != null && obj instanceof List) { String modelFormListName = modelForm.getListName(); context.put(modelFormListName, obj); } } catch (GeneralException e) { String errMsg = "Error doing entity query by condition: " + e.toString(); Debug.logError(e, errMsg, module); throw new IllegalArgumentException(errMsg); } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -