Author: mbrohl
Date: Sun Oct 22 13:58:51 2017 New Revision: 1812918 URL: http://svn.apache.org/viewvc?rev=1812918&view=rev Log: Improved: Fixing defects reported by FindBugs, package org.apache.ofbiz.widget.model. (OFBIZ-9710) Thanks Dennis Balkir for reporting and providing the patch. Modified: ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/AbstractModelAction.java ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/AbstractModelCondition.java ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/CommonWidgetModels.java ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/HtmlWidget.java ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/IterateSectionWidget.java ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelForm.java ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelFormAction.java ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelFormField.java ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelFormFieldBuilder.java ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelMenu.java ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelMenuAction.java ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelMenuItem.java ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelScreen.java ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelScreenCondition.java ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelScreenWidget.java ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelTree.java ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelTreeAction.java ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelWidgetCondition.java Modified: ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/AbstractModelAction.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/AbstractModelAction.java?rev=1812918&r1=1812917&r2=1812918&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/AbstractModelAction.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/AbstractModelAction.java Sun Oct 22 13:58:51 2017 @@ -118,7 +118,7 @@ public abstract class AbstractModelActio public static List<ModelAction> readSubActions(ModelWidget modelWidget, Element parentElement) { List<? extends Element> actionElementList = UtilXml.childElementList(parentElement); - List<ModelAction> actions = new ArrayList<ModelAction>(actionElementList.size()); + List<ModelAction> actions = new ArrayList<>(actionElementList.size()); for (Element actionElement : actionElementList) { actions.add(newInstance(modelWidget, actionElement)); } @@ -618,7 +618,7 @@ public abstract class AbstractModelActio @Override public void runAction(Map<String, Object> context) throws GeneralException { if (location.endsWith(".xml")) { - Map<String, Object> localContext = new HashMap<String, Object>(); + Map<String, Object> localContext = new HashMap<>(); localContext.putAll(context); DispatchContext ctx = WidgetWorker.getDispatcher(context).getDispatchContext(); MethodContext methodContext = new MethodContext(ctx, localContext, null); @@ -682,7 +682,7 @@ public abstract class AbstractModelActio if ("true".equals(autoFieldMapString)) { DispatchContext dc = WidgetWorker.getDispatcher(context).getDispatchContext(); // try a map called "parameters", try it first so values from here are overriden by values in the main context - Map<String, Object> combinedMap = new HashMap<String, Object>(); + Map<String, Object> combinedMap = new HashMap<>(); Map<String, Object> parametersObj = UtilGenerics.toMap(context.get("parameters")); if (parametersObj != null) { combinedMap.putAll(parametersObj); @@ -698,7 +698,7 @@ public abstract class AbstractModelActio } } if (serviceContext == null) { - serviceContext = new HashMap<String, Object>(); + serviceContext = new HashMap<>(); } if (this.fieldMap != null) { EntityFinderUtil.expandFieldMapToContext(this.fieldMap, context, serviceContext); @@ -769,7 +769,7 @@ public abstract class AbstractModelActio Object newValue = null; String originalName = this.fromField.getOriginalName(); List<String> currentWidgetTrail = UtilGenerics.toList(context.get("_WIDGETTRAIL_")); - List<String> trailList = new ArrayList<String>(); + List<String> trailList = new ArrayList<>(); if (currentWidgetTrail != null) { trailList.addAll(currentWidgetTrail); } Modified: ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/AbstractModelCondition.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/AbstractModelCondition.java?rev=1812918&r1=1812917&r2=1812918&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/AbstractModelCondition.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/AbstractModelCondition.java Sun Oct 22 13:58:51 2017 @@ -78,7 +78,7 @@ public abstract class AbstractModelCondi public static List<ModelCondition> readSubConditions(ModelConditionFactory factory, ModelWidget modelWidget, Element conditionElement) { List<? extends Element> subElementList = UtilXml.childElementList(conditionElement); - List<ModelCondition> condList = new ArrayList<ModelCondition>(subElementList.size()); + List<ModelCondition> condList = new ArrayList<>(subElementList.size()); for (Element subElement : subElementList) { condList.add(factory.newInstance(modelWidget, subElement)); } @@ -248,7 +248,7 @@ public abstract class AbstractModelCondi if (fieldVal == null) { fieldVal = ""; } - List<Object> messages = new LinkedList<Object>(); + List<Object> messages = new LinkedList<>(); Boolean resultBool = BaseCompare.doRealCompare(fieldVal, value, operator, type, format, messages, null, null, true); if (messages.size() > 0) { messages.add(0, "Error with comparison in if-compare between field [" + fieldAcsr.toString() + "] with value [" @@ -326,7 +326,7 @@ public abstract class AbstractModelCondi if (fieldVal == null) { fieldVal = ""; } - List<Object> messages = new LinkedList<Object>(); + List<Object> messages = new LinkedList<>(); Boolean resultBool = BaseCompare.doRealCompare(fieldVal, toFieldVal, operator, type, format, messages, null, null, false); if (messages.size() > 0) { @@ -595,29 +595,28 @@ public abstract class AbstractModelCondi Debug.logError(e, module); return false; } - if (permService != null) { - // build the context - Map<String, Object> svcCtx = permService.makeValid(serviceContext, ModelService.IN_PARAM); - svcCtx.put("resourceDescription", resource); - if (UtilValidate.isNotEmpty(mainAction)) { - svcCtx.put("mainAction", mainAction); - } - // invoke the service - Map<String, Object> resp; - try { - resp = dispatcher.runSync(permService.name, svcCtx, 300, true); - } catch (GenericServiceException e) { - Debug.logError(e, module); - return false; - } - if (ServiceUtil.isError(resp) || ServiceUtil.isFailure(resp)) { - Debug.logError(ServiceUtil.getErrorMessage(resp), module); - return false; - } - Boolean hasPermission = (Boolean) resp.get("hasPermission"); - if (hasPermission != null) { - return hasPermission.booleanValue(); - } + // build the context + Map<String, Object> svcCtx = permService.makeValid(serviceContext, ModelService.IN_PARAM); + svcCtx.put("resourceDescription", resource); + if (UtilValidate.isNotEmpty(mainAction)) { + svcCtx.put("mainAction", mainAction); + } + // invoke the service + Map<String, Object> resp; + try { + resp = dispatcher.runSync(permService.name, svcCtx, 300, true); + } + catch (GenericServiceException e) { + Debug.logError(e, module); + return false; + } + if (ServiceUtil.isError(resp) || ServiceUtil.isFailure(resp)) { + Debug.logError(ServiceUtil.getErrorMessage(resp), module); + return false; + } + Boolean hasPermission = (Boolean) resp.get("hasPermission"); + if (hasPermission != null) { + return hasPermission.booleanValue(); } } return false; @@ -812,9 +811,8 @@ public abstract class AbstractModelCondi if (foundOneTrue) { // now found two true, so return false return false; - } else { - foundOneTrue = true; } + foundOneTrue = true; } } return foundOneTrue; Modified: ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/CommonWidgetModels.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/CommonWidgetModels.java?rev=1812918&r1=1812917&r2=1812918&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/CommonWidgetModels.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/CommonWidgetModels.java Sun Oct 22 13:58:51 2017 @@ -59,7 +59,7 @@ public final class CommonWidgetModels { public static class AutoEntityParameters { private String entityName; - List<String> excludeList = new ArrayList<String>(); + List<String> excludeList = new ArrayList<>(); boolean includeNonPk; boolean includePk; private String includeType; @@ -83,7 +83,7 @@ public final class CommonWidgetModels { @SuppressWarnings("unchecked") public Map<String, String> getParametersMap(Map<String, Object> context, String defaultEntityName) { - Map<String, String> autEntityParams = new HashMap<String, String>(); + Map<String, String> autEntityParams = new HashMap<>(); Delegator delegator = (Delegator) context.get("delegator"); if (delegator == null) { Debug.logError( @@ -102,21 +102,19 @@ public final class CommonWidgetModels { } Iterator<ModelField> fieldsIter = entity.getFieldsIterator(); - if (fieldsIter != null) { - while (fieldsIter.hasNext()) { - ModelField field = fieldsIter.next(); - String fieldName = field.getName(); - FlexibleMapAccessor<Object> fma = FlexibleMapAccessor.getInstance(fieldName); - boolean shouldExclude = excludeList.contains(fieldName); - if ((!shouldExclude) && (!field.getIsAutoCreatedInternal()) - && ((field.getIsPk() && includePk) || (!field.getIsPk() && includeNonPk))) { - Object flexibleValue = fma.get(context); - if (UtilValidate.isEmpty(flexibleValue) && context.containsKey("parameters")) { - flexibleValue = fma.get((Map<String, Object>) context.get("parameters")); - } - if (UtilValidate.isNotEmpty(flexibleValue) || sendIfEmpty) { - autEntityParams.put(fieldName, String.valueOf(flexibleValue)); - } + while (fieldsIter.hasNext()) { + ModelField field = fieldsIter.next(); + String fieldName = field.getName(); + FlexibleMapAccessor<Object> fma = FlexibleMapAccessor.getInstance(fieldName); + boolean shouldExclude = excludeList.contains(fieldName); + if ((!shouldExclude) && (!field.getIsAutoCreatedInternal()) + && ((field.getIsPk() && includePk) || (!field.getIsPk() && includeNonPk))) { + Object flexibleValue = fma.get(context); + if (UtilValidate.isEmpty(flexibleValue) && context.containsKey("parameters")) { + flexibleValue = fma.get((Map<String, Object>) context.get("parameters")); + } + if (UtilValidate.isNotEmpty(flexibleValue) || sendIfEmpty) { + autEntityParams.put(fieldName, String.valueOf(flexibleValue)); } } } @@ -125,9 +123,7 @@ public final class CommonWidgetModels { } public static class AutoServiceParameters { - List<String> excludeList = new ArrayList<String>(); - boolean includeNonPk; - boolean includePk; + List<String> excludeList = new ArrayList<>(); boolean sendIfEmpty; private String serviceName; @@ -146,7 +142,7 @@ public final class CommonWidgetModels { @SuppressWarnings("unchecked") public Map<String, String> getParametersMap(Map<String, Object> context, String defaultServiceName) { - Map<String, String> autServiceParams = new HashMap<String, String>(); + Map<String, String> autServiceParams = new HashMap<>(); LocalDispatcher dispatcher = (LocalDispatcher) context.get("dispatcher"); if (dispatcher == null) { Debug.logError( @@ -365,7 +361,7 @@ public final class CommonWidgetModels { if (parameterElementList.isEmpty()) { this.parameterList = Collections.emptyList(); } else { - List<Parameter> parameterList = new ArrayList<Parameter>( + List<Parameter> parameterList = new ArrayList<>( parameterElementList.size()); for (Element parameterElement : parameterElementList) { parameterList.add(new Parameter(parameterElement)); @@ -482,7 +478,7 @@ public final class CommonWidgetModels { } public Map<String, String> getParameterMap(Map<String, Object> context, String defaultEntityName, String defaultServiceName) { - Map<String, String> fullParameterMap = new HashMap<String, String>(); + Map<String, String> fullParameterMap = new HashMap<>(); for (Parameter parameter : this.parameterList) { fullParameterMap.put(parameter.getName(), parameter.getValue(context)); } @@ -496,7 +492,7 @@ public final class CommonWidgetModels { } public Map<String, String> getParameterMap(Map<String, Object> context) { - Map<String, String> fullParameterMap = new HashMap<String, String>(); + Map<String, String> fullParameterMap = new HashMap<>(); for (Parameter parameter : this.parameterList) { fullParameterMap.put(parameter.getName(), parameter.getValue(context)); } @@ -655,9 +651,8 @@ public final class CommonWidgetModels { returnValue = retVal.toString(); } return returnValue; - } else { - return null; } + return null; } } } Modified: ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/HtmlWidget.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/HtmlWidget.java?rev=1812918&r1=1812917&r2=1812918&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/HtmlWidget.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/HtmlWidget.java Sun Oct 22 13:58:51 2017 @@ -60,7 +60,7 @@ public class HtmlWidget extends ModelScr public static final String module = HtmlWidget.class.getName(); private static final UtilCache<String, Template> specialTemplateCache = UtilCache.createUtilCache("widget.screen.template.ftl.general", 0, 0, false); - protected static Configuration specialConfig = FreeMarkerWorker.makeConfiguration(new ExtendedWrapper(FreeMarkerWorker.version)); + protected static final Configuration specialConfig = FreeMarkerWorker.makeConfiguration(new ExtendedWrapper(FreeMarkerWorker.version)); // not sure if this is the best way to get FTL to use my fancy MapModel derivative, but should work at least... public static class ExtendedWrapper extends BeansWrapper { @@ -115,7 +115,7 @@ public class HtmlWidget extends ModelScr if (childElementList.isEmpty()) { this.subWidgets = Collections.emptyList(); } else { - List<ModelScreenWidget> subWidgets = new ArrayList<ModelScreenWidget>(childElementList.size()); + List<ModelScreenWidget> subWidgets = new ArrayList<>(childElementList.size()); for (Element childElement : childElementList) { if ("html-template".equals(childElement.getNodeName())) { subWidgets.add(new HtmlTemplate(modelScreen, childElement)); @@ -227,7 +227,7 @@ public class HtmlWidget extends ModelScr public static class HtmlTemplateDecorator extends ModelScreenWidget { protected FlexibleStringExpander locationExdr; - protected Map<String, ModelScreenWidget> sectionMap = new HashMap<String, ModelScreenWidget>(); + protected Map<String, ModelScreenWidget> sectionMap = new HashMap<>(); public HtmlTemplateDecorator(ModelScreen modelScreen, Element htmlTemplateDecoratorElement) { super(modelScreen, htmlTemplateDecoratorElement); Modified: ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/IterateSectionWidget.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/IterateSectionWidget.java?rev=1812918&r1=1812917&r2=1812918&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/IterateSectionWidget.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/IterateSectionWidget.java Sun Oct 22 13:58:51 2017 @@ -56,8 +56,8 @@ import org.w3c.dom.Element; public class IterateSectionWidget extends ModelScreenWidget { public static final String module = IterateSectionWidget.class.getName(); - public static int DEFAULT_PAGE_SIZE = 5; - public static int MAX_PAGE_SIZE = 10000; + public static final int DEFAULT_PAGE_SIZE = 5; + public static final int MAX_PAGE_SIZE = 10000; private final List<ModelScreenWidget.Section> sectionList; private final FlexibleMapAccessor<Object> listNameExdr; @@ -96,7 +96,7 @@ public class IterateSectionWidget extend if (childElementList.isEmpty()) { this.sectionList = Collections.emptyList(); } else { - List<ModelScreenWidget.Section> sectionList = new ArrayList<ModelScreenWidget.Section>(childElementList.size()); + List<ModelScreenWidget.Section> sectionList = new ArrayList<>(childElementList.size()); for (Element sectionElement: childElementList) { ModelScreenWidget.Section section = new ModelScreenWidget.Section(modelScreen, sectionElement, false); sectionList.add(section); @@ -112,7 +112,7 @@ public class IterateSectionWidget extend @Override public void renderWidgetString(Appendable writer, Map<String, Object> context, ScreenStringRenderer screenStringRenderer) throws GeneralException, IOException { int viewIndex = 0; - int viewSize = this.viewSize; + int locViewSize = this.viewSize; int lowIndex = -1; int highIndex = -1; int listSize = 0; @@ -151,7 +151,9 @@ public class IterateSectionWidget extend String viewIndexString = params.get("VIEW_INDEX" + "_" + WidgetWorker.getPaginatorNumber(context)); String viewSizeString = params.get("VIEW_SIZE" + "_" + WidgetWorker.getPaginatorNumber(context)); viewIndex = Integer.parseInt(viewIndexString); - viewSize = Integer.parseInt(viewSizeString); + locViewSize = Integer.parseInt(viewSizeString); + } catch (RuntimeException e) { + throw e; } catch (Exception e) { try { viewIndex = ((Integer) context.get("viewIndex")).intValue(); @@ -160,11 +162,11 @@ public class IterateSectionWidget extend } } context.put("viewIndex", Integer.valueOf(viewIndex)); - lowIndex = viewIndex * viewSize; - highIndex = (viewIndex + 1) * viewSize; + lowIndex = viewIndex * locViewSize; + highIndex = (viewIndex + 1) * locViewSize; } else { viewIndex = 0; - viewSize = MAX_PAGE_SIZE; + locViewSize = MAX_PAGE_SIZE; lowIndex = 0; highIndex = MAX_PAGE_SIZE; } @@ -231,9 +233,8 @@ public class IterateSectionWidget extend public boolean getPaginate(Map<String, Object> context) { if (!this.paginate.isEmpty() && UtilValidate.isNotEmpty(this.paginate.expandString(context))) { return Boolean.valueOf(this.paginate.expandString(context)).booleanValue(); - } else { - return true; } + return true; } public int getViewSize() { Modified: ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelForm.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelForm.java?rev=1812918&r1=1812917&r2=1812918&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelForm.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelForm.java Sun Oct 22 13:58:51 2017 @@ -83,19 +83,19 @@ public abstract class ModelForm extends public static final String module = ModelForm.class.getName(); public static final String DEFAULT_FORM_RESULT_LIST_NAME = "defaultFormResultList"; /** Pagination settings and defaults. */ - public static int DEFAULT_PAGE_SIZE = 10; - public static int MAX_PAGE_SIZE = 10000; - public static String DEFAULT_PAG_INDEX_FIELD = "viewIndex"; - public static String DEFAULT_PAG_SIZE_FIELD = "viewSize"; - public static String DEFAULT_PAG_STYLE = "nav-pager"; - public static String DEFAULT_PAG_FIRST_STYLE = "nav-first"; - public static String DEFAULT_PAG_PREV_STYLE = "nav-previous"; - public static String DEFAULT_PAG_NEXT_STYLE = "nav-next"; - public static String DEFAULT_PAG_LAST_STYLE = "nav-last"; + public static final int DEFAULT_PAGE_SIZE = 10; + public static final int MAX_PAGE_SIZE = 10000; + public static final String DEFAULT_PAG_INDEX_FIELD = "viewIndex"; + public static final String DEFAULT_PAG_SIZE_FIELD = "viewSize"; + public static final String DEFAULT_PAG_STYLE = "nav-pager"; + public static final String DEFAULT_PAG_FIRST_STYLE = "nav-first"; + public static final String DEFAULT_PAG_PREV_STYLE = "nav-previous"; + public static final String DEFAULT_PAG_NEXT_STYLE = "nav-next"; + public static final String DEFAULT_PAG_LAST_STYLE = "nav-last"; /** Sort field default styles. */ - public static String DEFAULT_SORT_FIELD_STYLE = "sort-order"; - public static String DEFAULT_SORT_FIELD_ASC_STYLE = "sort-order-asc"; - public static String DEFAULT_SORT_FIELD_DESC_STYLE = "sort-order-desc"; + public static final String DEFAULT_SORT_FIELD_STYLE = "sort-order"; + public static final String DEFAULT_SORT_FIELD_ASC_STYLE = "sort-order-asc"; + public static final String DEFAULT_SORT_FIELD_DESC_STYLE = "sort-order-desc"; private final List<ModelAction> actions; private final List<AltRowStyle> altRowStyles; private final List<AltTarget> altTargets; @@ -126,11 +126,11 @@ public abstract class ModelForm extends /** This is a list of FieldGroups in the order they were created. * Can also include Banner objects. */ - private final List<FieldGroupBase> fieldGroupList; + protected final List<FieldGroupBase> fieldGroupList; /** This Map is keyed with the field name and has a FieldGroup for the value. * Can also include Banner objects. */ - private final Map<String, FieldGroupBase> fieldGroupMap; + protected final Map<String, FieldGroupBase> fieldGroupMap; /** This List will contain one copy of each field for each field name in the order * they were encountered in the service, entity, or form definition; field definitions * with constraints will also be in this list but may appear multiple times for the same @@ -140,7 +140,7 @@ public abstract class ModelForm extends * necessary to use the Map. The Map is used when loading the form definition to keep the * list clean and implement the override features for field definitions. */ - private final List<ModelFormField> fieldList; + protected final List<ModelFormField> fieldList; private final String focusFieldName; private final String formLocation; private final String formTitleAreaStyle; @@ -207,7 +207,7 @@ public abstract class ModelForm extends } } else { try { - defaultViewSizeInt = Integer.valueOf(viewSize); + defaultViewSizeInt = Integer.parseInt(viewSize); } catch (NumberFormatException e) { } } @@ -375,7 +375,7 @@ public abstract class ModelForm extends paginateTarget = parentModel.paginateTarget; } this.paginateTarget = paginateTarget; - ArrayList<AltTarget> altTargets = new ArrayList<AltTarget>(); + ArrayList<AltTarget> altTargets = new ArrayList<>(); for (Element altTargetElement : UtilXml.childElementList(formElement, "alt-target")) { altTargets.add(new AltTarget(altTargetElement)); } @@ -384,7 +384,7 @@ public abstract class ModelForm extends } altTargets.trimToSize(); this.altTargets = Collections.unmodifiableList(altTargets); - ArrayList<ModelAction> actions = new ArrayList<ModelAction>(); + ArrayList<ModelAction> actions = new ArrayList<>(); if (parentModel != null) { actions.addAll(parentModel.actions); } @@ -394,7 +394,7 @@ public abstract class ModelForm extends } actions.trimToSize(); this.actions = Collections.unmodifiableList(actions); - ArrayList<ModelAction> rowActions = new ArrayList<ModelAction>(); + ArrayList<ModelAction> rowActions = new ArrayList<>(); if (parentModel != null) { rowActions.addAll(parentModel.rowActions); } @@ -404,9 +404,9 @@ public abstract class ModelForm extends } rowActions.trimToSize(); this.rowActions = Collections.unmodifiableList(rowActions); - ArrayList<UpdateArea> onPaginateUpdateAreas = new ArrayList<UpdateArea>(); - ArrayList<UpdateArea> onSubmitUpdateAreas = new ArrayList<UpdateArea>(); - ArrayList<UpdateArea> onSortColumnUpdateAreas = new ArrayList<UpdateArea>(); + ArrayList<UpdateArea> onPaginateUpdateAreas = new ArrayList<>(); + ArrayList<UpdateArea> onSubmitUpdateAreas = new ArrayList<>(); + ArrayList<UpdateArea> onSortColumnUpdateAreas = new ArrayList<>(); if (parentModel != null) { onPaginateUpdateAreas.addAll(parentModel.onPaginateUpdateAreas); onSubmitUpdateAreas.addAll(parentModel.onSubmitUpdateAreas); @@ -453,7 +453,7 @@ public abstract class ModelForm extends this.onSubmitUpdateAreas = Collections.unmodifiableList(onSubmitUpdateAreas); onSortColumnUpdateAreas.trimToSize(); this.onSortColumnUpdateAreas = Collections.unmodifiableList(onSortColumnUpdateAreas); - ArrayList<AltRowStyle> altRowStyles = new ArrayList<AltRowStyle>(); + ArrayList<AltRowStyle> altRowStyles = new ArrayList<>(); if (parentModel != null) { altRowStyles.addAll(parentModel.altRowStyles); } @@ -463,12 +463,12 @@ public abstract class ModelForm extends } altRowStyles.trimToSize(); this.altRowStyles = Collections.unmodifiableList(altRowStyles); - Set<String> useWhenFields = new HashSet<String>(); + Set<String> useWhenFields = new HashSet<>(); if (parentModel != null) { useWhenFields.addAll(parentModel.useWhenFields); } - List<ModelFormFieldBuilder> fieldBuilderList = new ArrayList<ModelFormFieldBuilder>(); - Map<String, ModelFormFieldBuilder> fieldBuilderMap = new HashMap<String, ModelFormFieldBuilder>(); + List<ModelFormFieldBuilder> fieldBuilderList = new ArrayList<>(); + Map<String, ModelFormFieldBuilder> fieldBuilderMap = new HashMap<>(); if (parentModel != null) { // Create this fieldList/Map from clones of parentModel's for (ModelFormField parentChildField : parentModel.fieldList) { @@ -478,15 +478,15 @@ public abstract class ModelForm extends fieldBuilderMap.put(builder.getName(), builder); } } - Map<String, FieldGroupBase> fieldGroupMap = new HashMap<String, FieldGroupBase>(); + Map<String, FieldGroupBase> fieldGroupMap = new HashMap<>(); if (parentModel != null) { fieldGroupMap.putAll(parentModel.fieldGroupMap); } - ArrayList<FieldGroupBase> fieldGroupList = new ArrayList<FieldGroupBase>(); + ArrayList<FieldGroupBase> fieldGroupList = new ArrayList<>(); if (parentModel != null) { fieldGroupList.addAll(parentModel.fieldGroupList); } - ArrayList<String> lastOrderFields = new ArrayList<String>(); + ArrayList<String> lastOrderFields = new ArrayList<>(); if (parentModel != null) { lastOrderFields.addAll(parentModel.lastOrderFields); } @@ -605,15 +605,11 @@ public abstract class ModelForm extends } else { this.useRowSubmit = "true".equals(useRowSubmit); } - FlexibleStringExpander rowCountExdr = FlexibleStringExpander.getInstance(formElement.getAttribute("row-count")); - if (rowCountExdr.isEmpty() && parentModel != null) { - rowCountExdr = parentModel.rowCountExdr; - } this.rowCountExdr = paginate; - List<ModelFormFieldBuilder> multiSubmitBuilders = new ArrayList<ModelFormFieldBuilder>(); - ArrayList<AutoFieldsService> autoFieldsServices = new ArrayList<AutoFieldsService>(); - ArrayList<AutoFieldsEntity> autoFieldsEntities = new ArrayList<AutoFieldsEntity>(); - ArrayList<SortField> sortOrderFields = new ArrayList<SortField>(); + List<ModelFormFieldBuilder> multiSubmitBuilders = new ArrayList<>(); + ArrayList<AutoFieldsService> autoFieldsServices = new ArrayList<>(); + ArrayList<AutoFieldsEntity> autoFieldsEntities = new ArrayList<>(); + ArrayList<SortField> sortOrderFields = new ArrayList<>(); this.defaultFieldGroup = new FieldGroup(null, this, sortOrderFields, fieldGroupMap); for (Element autoFieldsServiceElement : UtilXml.childElementList(formElement, "auto-fields-service")) { AutoFieldsService autoFieldsService = new AutoFieldsService(autoFieldsServiceElement); @@ -666,7 +662,7 @@ public abstract class ModelForm extends } } if (sortOrderFields.size() > 0) { - List<ModelFormFieldBuilder> sortedFields = new ArrayList<ModelFormFieldBuilder>(); + List<ModelFormFieldBuilder> sortedFields = new ArrayList<>(); for (SortField sortField : sortOrderFields) { String fieldName = sortField.getFieldName(); if (UtilValidate.isEmpty(fieldName)) { @@ -692,7 +688,7 @@ public abstract class ModelForm extends fieldBuilderList = sortedFields; } if (UtilValidate.isNotEmpty(lastOrderFields)) { - List<ModelFormFieldBuilder> lastedFields = new LinkedList<ModelFormFieldBuilder>(); + List<ModelFormFieldBuilder> lastedFields = new LinkedList<>(); for (String fieldName : lastOrderFields) { if (UtilValidate.isEmpty(fieldName)) { continue; @@ -711,12 +707,12 @@ public abstract class ModelForm extends //now put all lastedFields at the field list end fieldBuilderList.addAll(lastedFields); } - List<ModelFormField> fieldList = new ArrayList<ModelFormField>(fieldBuilderList.size()); + List<ModelFormField> fieldList = new ArrayList<>(fieldBuilderList.size()); for (ModelFormFieldBuilder builder : fieldBuilderList) { fieldList.add(builder.build()); } this.fieldList = Collections.unmodifiableList(fieldList); - List<ModelFormField> multiSubmitFields = new ArrayList<ModelFormField>(multiSubmitBuilders.size()); + List<ModelFormField> multiSubmitFields = new ArrayList<>(multiSubmitBuilders.size()); for (ModelFormFieldBuilder builder : multiSubmitBuilders) { multiSubmitFields.add(builder.build()); } @@ -797,24 +793,22 @@ public abstract class ModelForm extends ModelEntity modelEntity; try { modelEntity = entityModelReader.getModelEntity(modelParam.entityName); - if (modelEntity != null) { - ModelField modelField = modelEntity.getField(modelParam.fieldName); - if (modelField != null) { - // okay, populate using the entity field info... - ModelFormFieldBuilder builder = new ModelFormFieldBuilder(); - builder.setModelForm(this); - builder.setName(modelField.getName()); - builder.setEntityName(modelEntity.getEntityName()); - builder.setFieldName(modelField.getName()); - builder.induceFieldInfoFromEntityField(modelEntity, modelField, autoFieldsService.defaultFieldType); - if (UtilValidate.isNotEmpty(autoFieldsService.mapName)) { - builder.setMapName(autoFieldsService.mapName); - } - builder.setRequiredField(!modelParam.optional); - addUpdateField(builder, useWhenFields, fieldBuilderList, fieldBuilderMap); - // continue to skip creating based on service param - continue; + ModelField modelField = modelEntity.getField(modelParam.fieldName); + if (modelField != null) { + // okay, populate using the entity field info... + ModelFormFieldBuilder builder = new ModelFormFieldBuilder(); + builder.setModelForm(this); + builder.setName(modelField.getName()); + builder.setEntityName(modelEntity.getEntityName()); + builder.setFieldName(modelField.getName()); + builder.induceFieldInfoFromEntityField(modelEntity, modelField, autoFieldsService.defaultFieldType); + if (UtilValidate.isNotEmpty(autoFieldsService.mapName)) { + builder.setMapName(autoFieldsService.mapName); } + builder.setRequiredField(!modelParam.optional); + addUpdateField(builder, useWhenFields, fieldBuilderList, fieldBuilderMap); + // continue to skip creating based on service param + continue; } } catch (GenericEntityException e) { Debug.logError(e, module); @@ -856,17 +850,16 @@ public abstract class ModelForm extends fieldBuilderList.add(builder); } return; + } + // not a conditional field, see if a named field exists in Map + ModelFormFieldBuilder existingField = fieldBuilderMap.get(builder.getName()); + if (existingField != null) { + // does exist, update the field by doing a merge/override + existingField.mergeOverrideModelFormField(builder); } else { - // not a conditional field, see if a named field exists in Map - ModelFormFieldBuilder existingField = fieldBuilderMap.get(builder.getName()); - if (existingField != null) { - // does exist, update the field by doing a merge/override - existingField.mergeOverrideModelFormField(builder); - } else { - // does not exist, add to List and Map - fieldBuilderList.add(builder); - fieldBuilderMap.put(builder.getName(), builder); - } + // does not exist, add to List and Map + fieldBuilderList.add(builder); + fieldBuilderMap.put(builder.getName(), builder); } } @@ -903,9 +896,8 @@ public abstract class ModelForm extends // use the name if there is no id if (UtilValidate.isNotEmpty(this.containerId)) { return this.containerId; - } else { - return this.getName(); } + return this.getName(); } public String getContainerStyle() { @@ -1019,9 +1011,8 @@ public abstract class ModelForm extends public String getItemIndexSeparator() { if (UtilValidate.isNotEmpty(this.itemIndexSeparator)) { return this.itemIndexSeparator; - } else { - return "_o_"; } + return "_o_"; } public List<String> getLastOrderFields() { @@ -1106,9 +1097,8 @@ public abstract class ModelForm extends String paginate = this.paginate.expandString(context); if (!paginate.isEmpty()) { return Boolean.valueOf(paginate).booleanValue(); - } else { - return true; } + return true; } public String getPaginateFirstLabel() { @@ -1455,7 +1445,7 @@ public abstract class ModelForm extends int position = 1; try { if (UtilValidate.isNotEmpty(positionStr)) { - position = Integer.valueOf(positionStr); + position = Integer.parseInt(positionStr); } } catch (Exception e) { Debug.logError(e, "Could not convert position attribute of the field element to an integer: [" + positionStr @@ -1479,7 +1469,7 @@ public abstract class ModelForm extends int position = 1; try { if (UtilValidate.isNotEmpty(positionStr)) { - position = Integer.valueOf(positionStr); + position = Integer.parseInt(positionStr); } } catch (Exception e) { Debug.logError(e, "Could not convert position attribute of the field element to an integer: [" + positionStr @@ -1664,7 +1654,8 @@ public abstract class ModelForm extends Integer posParam = null; try { posParam = Integer.valueOf(position); - } catch (Exception e) {/* just ignore the exception*/ + } catch (Exception e) { + Debug.logInfo("The class SortField caused an exception", module); } this.position = posParam; } else { @@ -1712,7 +1703,7 @@ public abstract class ModelForm extends if (parameterElementList.isEmpty()) { this.parameterList = Collections.emptyList(); } else { - List<CommonWidgetModels.Parameter> parameterList = new ArrayList<CommonWidgetModels.Parameter>(parameterElementList.size()); + List<CommonWidgetModels.Parameter> parameterList = new ArrayList<>(parameterElementList.size()); for (Element parameterElement : parameterElementList) { parameterList.add(new CommonWidgetModels.Parameter(parameterElement)); } @@ -1765,7 +1756,7 @@ public abstract class ModelForm extends } public Map<String, String> getParameterMap(Map<String, Object> context) { - Map<String, String> fullParameterMap = new HashMap<String, String>(); + Map<String, String> fullParameterMap = new HashMap<>(); if (autoServiceParameters != null) { fullParameterMap.putAll(autoServiceParameters.getParametersMap(context, defaultServiceName)); } Modified: ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelFormAction.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelFormAction.java?rev=1812918&r1=1812917&r2=1812918&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelFormAction.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelFormAction.java Sun Oct 22 13:58:51 2017 @@ -46,7 +46,7 @@ public abstract class ModelFormAction { public static List<ModelAction> readSubActions(ModelForm modelForm, Element parentElement) { List<? extends Element> actionElementList = UtilXml.childElementList(parentElement); - List<ModelAction> actions = new ArrayList<ModelAction>(actionElementList.size()); + List<ModelAction> actions = new ArrayList<>(actionElementList.size()); for (Element actionElement : UtilXml.childElementList(parentElement)) { if ("service".equals(actionElement.getNodeName())) { actions.add(new Service(modelForm, actionElement)); @@ -138,7 +138,7 @@ public abstract class ModelFormAction { this.serviceNameExdr = FlexibleStringExpander.getInstance(serviceElement.getAttribute("service-name")); this.resultMapNameAcsr = FlexibleMapAccessor.getInstance(serviceElement.getAttribute("result-map")); this.autoFieldMapExdr = FlexibleStringExpander.getInstance(serviceElement.getAttribute("auto-field-map")); - FlexibleStringExpander resultMapListNameExdr = FlexibleStringExpander.getInstance(""); + FlexibleStringExpander resultMapListNameExdr; if (UtilValidate.isEmpty(serviceElement.getAttribute("result-map-list")) && UtilValidate.isEmpty(serviceElement.getAttribute("result-map-list-name"))) { if (UtilValidate.isEmpty(serviceElement.getAttribute("result-map-list-iterator")) @@ -196,7 +196,7 @@ public abstract class ModelFormAction { .makeValidContext(serviceNameExpanded, ModelService.IN_PARAM, context); } } else { - serviceContext = new HashMap<String, Object>(); + serviceContext = new HashMap<>(); } if (this.fieldMap != null) { EntityFinderUtil.expandFieldMapToContext(this.fieldMap, context, serviceContext); Modified: ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelFormField.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelFormField.java?rev=1812918&r1=1812917&r2=1812918&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelFormField.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelFormField.java Sun Oct 22 13:58:51 2017 @@ -112,16 +112,16 @@ public class ModelFormField { private final FlexibleMapAccessor<Object> entryAcsr; private final String event; private final FieldInfo fieldInfo; - private final String fieldName; + protected final String fieldName; private final String headerLink; private final String headerLinkStyle; private final String idName; private final FlexibleMapAccessor<Map<String, ? extends Object>> mapAcsr; - private final ModelForm modelForm; - private final String name; + protected final ModelForm modelForm; + protected final String name; private final List<UpdateArea> onChangeUpdateAreas; private final List<UpdateArea> onClickUpdateAreas; - private final String parameterName; + protected final String parameterName; private final Integer position; private final String redWhen; private final Boolean requiredField; @@ -167,12 +167,12 @@ public class ModelFormField { if (builder.getOnChangeUpdateAreas().isEmpty()) { this.onChangeUpdateAreas = Collections.emptyList(); } else { - this.onChangeUpdateAreas = Collections.unmodifiableList(new ArrayList<UpdateArea>(builder.getOnChangeUpdateAreas())); + this.onChangeUpdateAreas = Collections.unmodifiableList(new ArrayList<>(builder.getOnChangeUpdateAreas())); } if (builder.getOnClickUpdateAreas().isEmpty()) { this.onClickUpdateAreas = Collections.emptyList(); } else { - this.onClickUpdateAreas = Collections.unmodifiableList(new ArrayList<UpdateArea>(builder.getOnClickUpdateAreas())); + this.onClickUpdateAreas = Collections.unmodifiableList(new ArrayList<>(builder.getOnClickUpdateAreas())); } this.parameterName = builder.getParameterName(); this.position = builder.getPosition(); @@ -355,7 +355,7 @@ public class ModelFormField { } else if (retVal instanceof Collection) { Collection<Object> col = UtilGenerics.checkCollection(retVal); Iterator<Object> iter = col.iterator(); - List<Object> newCol = new ArrayList<Object>(col.size()); + List<Object> newCol = new ArrayList<>(col.size()); while (iter.hasNext()) { Object item = iter.next(); if (item == null) { @@ -433,9 +433,8 @@ public class ModelFormField { String parentFormName = this.getParentFormName(); if (UtilValidate.isNotEmpty(parentFormName)) { return parentFormName + "_" + this.getFieldName(); - } else { - return this.modelForm.getName() + "_" + this.getFieldName(); } + return this.modelForm.getName() + "_" + this.getFieldName(); } public String getTabindex() { @@ -513,9 +512,8 @@ public class ModelFormField { Integer itemIndex = (Integer) context.get("itemIndex"); if (itemIndex != null && "multi".equals(this.modelForm.getType())) { return baseName + this.modelForm.getItemIndexSeparator() + itemIndex.intValue(); - } else { - return baseName; } + return baseName; } public int getPosition() { @@ -974,8 +972,7 @@ public class ModelFormField { String allCheckedStr = this.allChecked.expandString(context); if (!allCheckedStr.isEmpty()) return Boolean.valueOf("true".equals(allCheckedStr)); - else - return null; + return null; } @Override @@ -1211,9 +1208,8 @@ public class ModelFormField { public String getDefaultValue(Map<String, Object> context) { if (this.defaultValue != null) { return this.defaultValue.expandString(context); - } else { - return ""; } + return ""; } public String getInputMethod() { @@ -1481,9 +1477,8 @@ public class ModelFormField { public String getDefaultValue(Map<String, Object> context) { if (this.defaultValue != null) { return this.defaultValue.expandString(context); - } else { - return ""; } + return ""; } public FlexibleStringExpander getDescription() { @@ -1784,9 +1779,8 @@ public class ModelFormField { Integer itemIndex = (Integer) context.get("itemIndex"); if (itemIndex != null && "multi".equals(getModelFormField().modelForm.getType())) { return baseName + getModelFormField().modelForm.getItemIndexSeparator() + itemIndex.intValue(); - } else { - return baseName; } + return baseName; } public String getSize() { @@ -1835,7 +1829,7 @@ public class ModelFormField { this.cache = !"false".equals(entityOptionsElement.getAttribute("cache")); List<? extends Element> constraintElements = UtilXml.childElementList(entityOptionsElement, "entity-constraint"); if (!constraintElements.isEmpty()) { - List<EntityFinderUtil.ConditionExpr> constraintList = new ArrayList<EntityFinderUtil.ConditionExpr>( + List<EntityFinderUtil.ConditionExpr> constraintList = new ArrayList<>( constraintElements.size()); for (Element constraintElement : constraintElements) { constraintList.add(new EntityFinderUtil.ConditionExpr(constraintElement)); @@ -1850,7 +1844,7 @@ public class ModelFormField { this.keyFieldName = entityOptionsElement.getAttribute("key-field-name"); List<? extends Element> orderByElements = UtilXml.childElementList(entityOptionsElement, "entity-order-by"); if (!orderByElements.isEmpty()) { - List<String> orderByList = new ArrayList<String>(orderByElements.size()); + List<String> orderByList = new ArrayList<>(orderByElements.size()); for (Element orderByElement : orderByElements) { orderByList.add(orderByElement.getAttribute("field-name")); } @@ -1887,7 +1881,7 @@ public class ModelFormField { // first expand any conditions that need expanding based on the current context EntityCondition findCondition = null; if (UtilValidate.isNotEmpty(this.constraintList)) { - List<EntityCondition> expandedConditionList = new LinkedList<EntityCondition>(); + List<EntityCondition> expandedConditionList = new LinkedList<>(); for (EntityFinderUtil.Condition condition : constraintList) { ModelEntity modelEntity = delegator.getModelEntity(this.entityName); if (modelEntity == null) { @@ -2016,7 +2010,7 @@ public class ModelFormField { super(element, modelFormField); this.noCurrentSelectedKey = FlexibleStringExpander.getInstance(element.getAttribute("no-current-selected-key")); // read all option and entity-options sub-elements, maintaining order - ArrayList<OptionSource> optionSources = new ArrayList<OptionSource>(); + ArrayList<OptionSource> optionSources = new ArrayList<>(); List<? extends Element> childElements = UtilXml.childElementList(element); if (childElements.size() > 0) { for (Element childElement : childElements) { @@ -2043,7 +2037,7 @@ public class ModelFormField { if (original.optionSources.isEmpty()) { this.optionSources = original.optionSources; } else { - List<OptionSource> optionSources = new ArrayList<OptionSource>(original.optionSources.size()); + List<OptionSource> optionSources = new ArrayList<>(original.optionSources.size()); for (OptionSource source : original.optionSources) { optionSources.add(source.copy(modelFormField)); } @@ -2054,7 +2048,7 @@ public class ModelFormField { protected FieldInfoWithOptions(int fieldSource, int fieldType, List<OptionSource> optionSources) { super(fieldSource, fieldType, null); this.noCurrentSelectedKey = FlexibleStringExpander.getInstance(""); - this.optionSources = Collections.unmodifiableList(new ArrayList<OptionSource>(optionSources)); + this.optionSources = Collections.unmodifiableList(new ArrayList<>(optionSources)); } public FieldInfoWithOptions(int fieldSource, int fieldType, ModelFormField modelFormField) { @@ -2064,7 +2058,7 @@ public class ModelFormField { } public List<OptionValue> getAllOptionValues(Map<String, Object> context, Delegator delegator) { - List<OptionValue> optionValues = new LinkedList<OptionValue>(); + List<OptionValue> optionValues = new LinkedList<>(); for (OptionSource optionSource : this.optionSources) { optionSource.addOptionValues(optionValues, context, delegator); } @@ -2190,6 +2184,8 @@ public class ModelFormField { org.apache.ofbiz.entity.model.ModelReader entityModelReader = ((org.apache.ofbiz.entity.Delegator)context.get("delegator")).getModelReader(); org.apache.ofbiz.service.DispatchContext dispatchContext = ((org.apache.ofbiz.service.LocalDispatcher)context.get("dispatcher")).getDispatchContext(); modelForm = FormFactory.getFormFromLocation(location, name, entityModelReader, dispatchContext); + } catch (RuntimeException e) { + throw e; } catch (Exception e) { String errMsg = "Error rendering form named [" + name + "] at location [" + location + "]: "; Debug.logError(e, errMsg, module); @@ -2269,6 +2265,8 @@ public class ModelFormField { org.apache.ofbiz.entity.model.ModelReader entityModelReader = ((org.apache.ofbiz.entity.Delegator)context.get("delegator")).getModelReader(); org.apache.ofbiz.service.DispatchContext dispatchContext = ((org.apache.ofbiz.service.LocalDispatcher)context.get("dispatcher")).getDispatchContext(); modelForm = GridFactory.getGridFromLocation(location, name, entityModelReader, dispatchContext); + } catch (RuntimeException e) { + throw e; } catch (Exception e) { String errMsg = "Error rendering grid named [" + name + "] at location [" + location + "]: "; Debug.logError(e, errMsg, module); @@ -2328,9 +2326,8 @@ public class ModelFormField { valueEnc = simpleEncoder.encode(valueEnc); } return valueEnc; - } else { - return getModelFormField().getEntry(context); } + return getModelFormField().getEntry(context); } @Override @@ -2684,9 +2681,8 @@ public class ModelFormField { public String getDefaultValue(Map<String, Object> context) { if (this.defaultValue != null) { return this.defaultValue.expandString(context); - } else { - return ""; } + return ""; } public FlexibleStringExpander getDescription() { @@ -2817,7 +2813,7 @@ public class ModelFormField { } public Map<String, Object> getFieldMap(Map<String, Object> context) { - Map<String, Object> inPlaceEditorContext = new HashMap<String, Object>(); + Map<String, Object> inPlaceEditorContext = new HashMap<>(); EntityFinderUtil.expandFieldMapToContext(this.fieldMap, context, inPlaceEditorContext); return inPlaceEditorContext; } @@ -2905,9 +2901,8 @@ public class ModelFormField { public String getUrl(Map<String, Object> context) { if (this.url != null) { return this.url.expandString(context); - } else { - return ""; } + return ""; } } @@ -2952,7 +2947,7 @@ public class ModelFormField { List<? extends Object> dataList = UtilGenerics.checkList(this.listAcsr.get(context)); if (dataList != null && dataList.size() != 0) { for (Object data : dataList) { - Map<String, Object> localContext = new HashMap<String, Object>(); + Map<String, Object> localContext = new HashMap<>(); localContext.putAll(context); if (UtilValidate.isNotEmpty(this.listEntryName)) { localContext.put(this.listEntryName, data); @@ -3115,7 +3110,7 @@ public class ModelFormField { } public List<String> getTargetParameterList() { - List<String> paramList = new LinkedList<String>(); + List<String> paramList = new LinkedList<>(); if (UtilValidate.isNotEmpty(this.targetParameter)) { StringTokenizer stk = new StringTokenizer(this.targetParameter, ", "); while (stk.hasMoreTokens()) { @@ -3469,6 +3464,8 @@ public class ModelFormField { ScreenRenderer subRenderer = new ScreenRenderer(writer, mapStack, renderer.getScreenStringRenderer()); writer.append(subRenderer.render(location, name)); } + } catch (RuntimeException e) { + throw e; } catch (Exception e) { String errMsg = "Error rendering included screen named [" + name + "] at location [" + location + "]: " + e.toString(); Debug.logError(e, errMsg, module); @@ -3948,9 +3945,8 @@ public class ModelFormField { public String getDefaultValue(Map<String, Object> context) { if (this.defaultValue != null) { return this.defaultValue.expandString(context); - } else { - return ""; } + return ""; } public int getRows() { return rows; } @@ -4121,9 +4117,8 @@ public class ModelFormField { public String getDefaultValue(Map<String, Object> context) { if (this.defaultValue != null) { return this.defaultValue.expandString(context); - } else { - return ""; } + return ""; } public boolean getDisabled() { @@ -4260,7 +4255,7 @@ public class ModelFormField { if (UtilValidate.isNotEmpty(parameters)) { String fieldName = this.getModelFormField().getName(); if (parameters.containsKey(fieldName)) { - ignoreCase = "Y".equals((String) parameters.get(fieldName.concat("_ic"))); + ignoreCase = "Y".equals(parameters.get(fieldName.concat("_ic"))); } } return ignoreCase; Modified: ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelFormFieldBuilder.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelFormFieldBuilder.java?rev=1812918&r1=1812917&r2=1812918&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelFormFieldBuilder.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelFormFieldBuilder.java Sun Oct 22 13:58:51 2017 @@ -86,8 +86,8 @@ public class ModelFormFieldBuilder { private FlexibleMapAccessor<Map<String, ? extends Object>> mapAcsr = null; private ModelForm modelForm = null; private String name = ""; - private List<UpdateArea> onChangeUpdateAreas = new ArrayList<UpdateArea>(); - private List<UpdateArea> onClickUpdateAreas = new ArrayList<UpdateArea>(); + private List<UpdateArea> onChangeUpdateAreas = new ArrayList<>(); + private List<UpdateArea> onClickUpdateAreas = new ArrayList<>(); private String parameterName = ""; private Integer position = null; private String redWhen = ""; @@ -568,7 +568,7 @@ public class ModelFormFieldBuilder { Integer.valueOf(250), null); this.setFieldInfo(textField); } else if ("indicator".equals(modelField.getType())) { - List<OptionSource> optionSources = new ArrayList<OptionSource>(); + List<OptionSource> optionSources = new ArrayList<>(); optionSources.add(new ModelFormField.SingleOption("Y", null, null)); optionSources.add(new ModelFormField.SingleOption("N", null, null)); ModelFormField.DropDownField dropDownField = new ModelFormField.DropDownField(FieldInfo.SOURCE_AUTO_ENTITY, @@ -616,13 +616,11 @@ public class ModelFormFieldBuilder { return false; try { ModelEntity modelEntity = entityModelReader.getModelEntity(this.getEntityName()); - if (modelEntity != null) { - ModelField modelField = modelEntity.getField(this.getFieldName()); - if (modelField != null) { - // okay, populate using the entity field info... - this.induceFieldInfoFromEntityField(modelEntity, modelField, defaultFieldType); - return true; - } + ModelField modelField = modelEntity.getField(this.getFieldName()); + if (modelField != null) { + // okay, populate using the entity field info... + this.induceFieldInfoFromEntityField(modelEntity, modelField, defaultFieldType); + return true; } } catch (GenericEntityException e) { Debug.logError(e, module); @@ -692,20 +690,18 @@ public class ModelFormFieldBuilder { return false; try { ModelService modelService = dispatchContext.getModelService(this.getServiceName()); - if (modelService != null) { - ModelParam modelParam = modelService.getParam(this.getAttributeName()); - if (modelParam != null) { - if (UtilValidate.isNotEmpty(modelParam.entityName) && UtilValidate.isNotEmpty(modelParam.fieldName)) { - this.entityName = modelParam.entityName; - this.fieldName = modelParam.fieldName; - if (this.induceFieldInfoFromEntityField(defaultFieldType, entityModelReader)) { - return true; - } + ModelParam modelParam = modelService.getParam(this.getAttributeName()); + if (modelParam != null) { + if (UtilValidate.isNotEmpty(modelParam.entityName) && UtilValidate.isNotEmpty(modelParam.fieldName)) { + this.entityName = modelParam.entityName; + this.fieldName = modelParam.fieldName; + if (this.induceFieldInfoFromEntityField(defaultFieldType, entityModelReader)) { + return true; } - - this.induceFieldInfoFromServiceParam(modelService, modelParam, defaultFieldType); - return true; } + + this.induceFieldInfoFromServiceParam(modelService, modelParam, defaultFieldType); + return true; } } catch (GenericServiceException e) { Debug.logError(e, Modified: ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelMenu.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelMenu.java?rev=1812918&r1=1812917&r2=1812918&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelMenu.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelMenu.java Sun Oct 22 13:58:51 2017 @@ -104,7 +104,7 @@ public class ModelMenu extends ModelWidg /** XML Constructor */ public ModelMenu(Element menuElement, String menuLocation) { super(menuElement); - ArrayList<ModelAction> actions = new ArrayList<ModelAction>(); + ArrayList<ModelAction> actions = new ArrayList<>(); String defaultAlign = ""; String defaultAlignStyle = ""; FlexibleStringExpander defaultAssociatedContentId = FlexibleStringExpander.getInstance(""); @@ -123,8 +123,8 @@ public class ModelMenu extends ModelWidg String fillStyle = ""; String id = ""; FlexibleStringExpander menuContainerStyleExdr = FlexibleStringExpander.getInstance(""); - ArrayList<ModelMenuItem> menuItemList = new ArrayList<ModelMenuItem>(); - Map<String, ModelMenuItem> menuItemMap = new HashMap<String, ModelMenuItem>(); + ArrayList<ModelMenuItem> menuItemList = new ArrayList<>(); + Map<String, ModelMenuItem> menuItemMap = new HashMap<>(); String menuWidth = ""; String orientation = "horizontal"; FlexibleMapAccessor<String> selectedMenuItemContextFieldName = FlexibleMapAccessor.getInstance(""); Modified: ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelMenuAction.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelMenuAction.java?rev=1812918&r1=1812917&r2=1812918&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelMenuAction.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelMenuAction.java Sun Oct 22 13:58:51 2017 @@ -49,7 +49,7 @@ public abstract class ModelMenuAction { public static List<ModelAction> readSubActions(ModelMenu modelMenu, Element parentElement) { List<? extends Element> actionElementList = UtilXml.childElementList(parentElement); - List<ModelAction> actions = new ArrayList<ModelAction>(actionElementList.size()); + List<ModelAction> actions = new ArrayList<>(actionElementList.size()); for (Element actionElement : actionElementList) { if ("set".equals(actionElement.getNodeName())) { actions.add(new SetField(modelMenu, actionElement)); Modified: ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelMenuItem.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelMenuItem.java?rev=1812918&r1=1812917&r2=1812918&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelMenuItem.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelMenuItem.java Sun Oct 22 13:58:51 2017 @@ -74,7 +74,7 @@ public class ModelMenuItem extends Model private final String disableIfEmpty; private final String entityName; private final Boolean hideIfSelected; - private final MenuLink link; + protected final MenuLink link; private final List<ModelMenuItem> menuItemList; private final ModelMenu modelMenu; private final String overrideName; @@ -143,8 +143,8 @@ public class ModelMenuItem extends Model // read in add item defs, add/override one by one using the menuItemList and menuItemMap List<? extends Element> itemElements = UtilXml.childElementList(menuItemElement, "menu-item"); if (!itemElements.isEmpty()) { - ArrayList<ModelMenuItem> menuItemList = new ArrayList<ModelMenuItem>(); - Map<String, ModelMenuItem> menuItemMap = new HashMap<String, ModelMenuItem>(); + ArrayList<ModelMenuItem> menuItemList = new ArrayList<>(); + Map<String, ModelMenuItem> menuItemMap = new HashMap<>(); for (Element itemElement : itemElements) { ModelMenuItem modelMenuItem = new ModelMenuItem(itemElement, modelMenu, this); addUpdateMenuItem(modelMenuItem, menuItemList, menuItemMap); @@ -320,7 +320,7 @@ public class ModelMenuItem extends Model if (this.associatedContentId != null) { retStr = associatedContentId.expandString(context); } - if (retStr.isEmpty()) { + if (retStr == null || retStr.isEmpty()) { retStr = this.modelMenu.getDefaultAssociatedContentId(context); } return retStr; @@ -329,9 +329,8 @@ public class ModelMenuItem extends Model public String getCellWidth() { if (!this.cellWidth.isEmpty()) { return this.cellWidth; - } else { - return this.modelMenu.getDefaultCellWidth(); } + return this.modelMenu.getDefaultCellWidth(); } public ModelMenuCondition getCondition() { @@ -365,9 +364,8 @@ public class ModelMenuItem extends Model public Boolean getHideIfSelected() { if (hideIfSelected != null) { return this.hideIfSelected; - } else { - return this.modelMenu.getDefaultHideIfSelected(); } + return this.modelMenu.getDefaultHideIfSelected(); } public MenuLink getLink() { @@ -409,9 +407,8 @@ public class ModelMenuItem extends Model public int getPosition() { if (this.position == null) { return 1; - } else { - return position.intValue(); } + return position.intValue(); } public String getSelectedStyle() { @@ -453,9 +450,8 @@ public class ModelMenuItem extends Model public String getTooltip(Map<String, Object> context) { if (UtilValidate.isNotEmpty(tooltip)) { return tooltip.expandString(context); - } else { - return ""; } + return ""; } public String getTooltipStyle() { @@ -529,7 +525,7 @@ public class ModelMenuItem extends Model public MenuLink(GenericValue portalPage, ModelMenuItem parentMenuItem, Locale locale) { this.linkMenuItem = parentMenuItem; - List<Parameter> parameterList = new ArrayList<Parameter>(); + List<Parameter> parameterList = new ArrayList<>(); if (parentMenuItem.link != null) { parameterList.addAll(parentMenuItem.link.getParameterList()); } Modified: ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelScreen.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelScreen.java?rev=1812918&r1=1812917&r2=1812918&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelScreen.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelScreen.java Sun Oct 22 13:58:51 2017 @@ -163,6 +163,8 @@ public class ModelScreen extends ModelWi // render the screen, starting with the top-level section this.section.renderWidgetString(writer, context, screenStringRenderer); TransactionUtil.commit(beganTransaction); + } catch (RuntimeException e) { + throw e; } catch (Exception e) { String errMsg = "Error rendering screen [" + this.sourceLocation + "#" + getName() + "]: " + e.toString(); Debug.logError(errMsg + ". Rolling back transaction.", module); Modified: ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelScreenCondition.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelScreenCondition.java?rev=1812918&r1=1812917&r2=1812918&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelScreenCondition.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelScreenCondition.java Sun Oct 22 13:58:51 2017 @@ -83,9 +83,8 @@ public final class ModelScreenCondition } if ("if-empty-section".equals(conditionElement.getNodeName())) { return new IfEmptySection(this, modelWidget, conditionElement); - } else { - return super.newInstance(this, modelWidget,conditionElement); } + return super.newInstance(this, modelWidget,conditionElement); } } } Modified: ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelScreenWidget.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelScreenWidget.java?rev=1812918&r1=1812917&r2=1812918&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelScreenWidget.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelScreenWidget.java Sun Oct 22 13:58:51 2017 @@ -80,7 +80,7 @@ public abstract class ModelScreenWidget if (subElementList.isEmpty()) { return Collections.emptyList(); } - List<ModelScreenWidget> subWidgets = new ArrayList<ModelScreenWidget>(subElementList.size()); + List<ModelScreenWidget> subWidgets = new ArrayList<>(subElementList.size()); for (Element subElement: subElementList) { subWidgets.add(WidgetFactory.getModelScreenWidget(modelScreen, subElement)); } @@ -111,7 +111,7 @@ public abstract class ModelScreenWidget public SectionsRenderer(Map<String, ModelScreenWidget> sectionMap, Map<String, Object> context, Appendable writer, ScreenStringRenderer screenStringRenderer) { - Map<String, ModelScreenWidget> localMap = new HashMap<String, ModelScreenWidget>(); + Map<String, ModelScreenWidget> localMap = new HashMap<>(); localMap.putAll(sectionMap); this.sectionMap = Collections.unmodifiableMap(localMap); this.context = context; @@ -307,9 +307,8 @@ public abstract class ModelScreenWidget public String getBoundaryCommentName() { if (isMainSection) { return getModelScreen().getSourceLocation() + "#" + getModelScreen().getName(); - } else { - return getName(); } + return getName(); } public List<ModelAction> getActions() { @@ -344,7 +343,7 @@ public abstract class ModelScreenWidget this.idExdr = FlexibleStringExpander.getInstance(containerElement.getAttribute("id")); this.styleExdr = FlexibleStringExpander.getInstance(containerElement.getAttribute("style")); List<? extends Element> subElementList = UtilXml.childElementList(containerElement, "column"); - List<Column> columns = new ArrayList<Column>(subElementList.size()); + List<Column> columns = new ArrayList<>(subElementList.size()); for (Element element : subElementList) { columns.add(new Column(modelScreen, element)); } @@ -540,7 +539,7 @@ public abstract class ModelScreenWidget this.titleExdr = FlexibleStringExpander.getInstance(screenletElement.getAttribute("title")); List<? extends Element> subElementList = UtilXml.childElementList(screenletElement); // Make a copy of the unmodifiable List so we can modify it. - List<ModelScreenWidget> subWidgets = new ArrayList<ModelScreenWidget>(ModelScreenWidget.readSubWidgets(getModelScreen(), subElementList)); + List<ModelScreenWidget> subWidgets = new ArrayList<>(ModelScreenWidget.readSubWidgets(getModelScreen(), subElementList)); Menu navigationMenu = null; String navMenuName = screenletElement.getAttribute("navigation-menu-name"); if (!navMenuName.isEmpty()) { @@ -760,7 +759,7 @@ public abstract class ModelScreenWidget // build the widgetpath List<String> widgetTrail = UtilGenerics.toList(context.get("_WIDGETTRAIL_")); if (widgetTrail == null) { - widgetTrail = new LinkedList<String>(); + widgetTrail = new LinkedList<>(); } String thisName = nameExdr.expandString(context); @@ -826,7 +825,7 @@ public abstract class ModelScreenWidget super(modelScreen, decoratorScreenElement); this.nameExdr = FlexibleStringExpander.getInstance(decoratorScreenElement.getAttribute("name")); this.locationExdr = FlexibleStringExpander.getInstance(decoratorScreenElement.getAttribute("location")); - Map<String, ModelScreenWidget> sectionMap = new HashMap<String, ModelScreenWidget>(); + Map<String, ModelScreenWidget> sectionMap = new HashMap<>(); List<? extends Element> decoratorSectionElementList = UtilXml.childElementList(decoratorScreenElement, "decorator-section"); for (Element decoratorSectionElement: decoratorSectionElementList) { DecoratorSection decoratorSection = new DecoratorSection(modelScreen, decoratorSectionElement); @@ -1153,6 +1152,8 @@ public abstract class ModelScreenWidget String location = this.getLocation(context); try { modelForm = GridFactory.getGridFromLocation(location, name, getModelScreen().getDelegator(context).getModelReader(), getModelScreen().getDispatcher(context).getDispatchContext()); + } catch (RuntimeException e) { + throw e; } catch (Exception e) { String errMsg = "Error rendering included form named [" + name + "] at location [" + location + "]: "; Debug.logError(e, errMsg, module); @@ -1284,7 +1285,7 @@ public abstract class ModelScreenWidget public PlatformSpecific(ModelScreen modelScreen, Element platformSpecificElement) { super(modelScreen, platformSpecificElement); - Map<String, ModelScreenWidget> subWidgets = new HashMap<String, ModelScreenWidget>(); + Map<String, ModelScreenWidget> subWidgets = new HashMap<>(); List<? extends Element> childElements = UtilXml.childElementList(platformSpecificElement); if (childElements != null) { for (Element childElement: childElements) { |
Free forum by Nabble | Edit this page |