Merge pull request #37 from danwatford/ofbiz-11418-backport18.12
OFBIZ-11418: Backport - Use FlexibleStringExpander in form widget lookup field target parameters
This commit is contained in:
@@ -647,7 +647,13 @@ under the License.
|
||||
</xs:attribute>
|
||||
<xs:attribute type="xs:string" name="parameter-name">
|
||||
<xs:annotation>
|
||||
<xs:documentation>Defaults to the value of the name attribute; is the name of the parameter to use for this field (the request parameter in a web application).</xs:documentation>
|
||||
<xs:documentation>Specifies the parameter name to use for this field - i.e. the name attribute of an
|
||||
HTML input field in a web application.
|
||||
|
||||
Accepts Unified Expression Language (JSR 245) notation, i.e. ${}, to allow use of expressions.
|
||||
|
||||
Defaults to the value of the name attribute.
|
||||
</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute type="xs:string" name="title">
|
||||
@@ -656,7 +662,7 @@ under the License.
|
||||
The name of this field that will be shown to the user.
|
||||
It can use the ${} and foo.bar (dot) syntax to insert values from the context for parameterization or internationalization.
|
||||
|
||||
Be sure a "FormFieldTitle_" labels does not already exist, else it will be overriden.
|
||||
Be sure a "FormFieldTitle_" labels does not already exist, else it will be overridden.
|
||||
</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
@@ -1187,10 +1193,21 @@ under the License.
|
||||
</xs:attribute>
|
||||
<xs:attribute type="xs:string" name="target-parameter">
|
||||
<xs:annotation>
|
||||
<xs:documentation>The name of a field whose value is passed in as a parameter to the lookup target form.
|
||||
Can be a comma separated list. You need to affect it the value using parameters.parmI
|
||||
(where I is the position number in the list, I must begin at 0) in the related lookup screen.
|
||||
See LookupPreferredContactMech as example
|
||||
<xs:documentation>Comma separated list of the parameter-names of the fields whose values are passed
|
||||
as parameters to the lookup target form.
|
||||
|
||||
Accepts Unified Expression Language (JSR 245) notation, i.e. ${}, to allow use of expressions.
|
||||
Expressions are evaluated before splitting at any commas. After splitting, whitespace is trimmed
|
||||
from the beginning and end of the resulting elements.
|
||||
|
||||
The position of a field name in the list corresponds to the parameter name that will be passed
|
||||
to the lookup form. Parameter names follow the naming convention parmN where N is the list
|
||||
position of the field name, starting with 0.
|
||||
|
||||
Example: A form has a text input field with parameter-name alpha and value 42; and text input
|
||||
field with parameter-name bravo and value 107. A lookup field has been created for that form
|
||||
with target-parameter="bravo,alpha". When the lookup is performed the resulting request will
|
||||
include parm0=107 and parm1=42.
|
||||
</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
|
||||
@@ -24,6 +24,7 @@ import java.sql.Timestamp;
|
||||
import java.text.DateFormat;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
@@ -33,8 +34,12 @@ import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.StringTokenizer;
|
||||
import java.util.Optional;
|
||||
import java.util.TimeZone;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.apache.ofbiz.base.conversion.ConversionException;
|
||||
import org.apache.ofbiz.base.conversion.DateTimeConverters;
|
||||
@@ -122,7 +127,7 @@ public class ModelFormField {
|
||||
protected final String name;
|
||||
private final List<UpdateArea> onChangeUpdateAreas;
|
||||
private final List<UpdateArea> onClickUpdateAreas;
|
||||
protected final String parameterName;
|
||||
protected final FlexibleStringExpander parameterName;
|
||||
private final Integer position;
|
||||
private final String redWhen;
|
||||
private final Boolean requiredField;
|
||||
@@ -522,7 +527,7 @@ public class ModelFormField {
|
||||
return onClickUpdateAreas;
|
||||
}
|
||||
|
||||
public String getParameterName() {
|
||||
public FlexibleStringExpander getParameterName() {
|
||||
return parameterName;
|
||||
}
|
||||
|
||||
@@ -535,7 +540,7 @@ public class ModelFormField {
|
||||
public String getParameterName(Map<String, ? extends Object> context) {
|
||||
String baseName;
|
||||
if (UtilValidate.isNotEmpty(this.parameterName)) {
|
||||
baseName = this.parameterName;
|
||||
baseName = this.parameterName.expandString(context);
|
||||
} else {
|
||||
baseName = this.name;
|
||||
}
|
||||
@@ -1853,7 +1858,7 @@ public class ModelFormField {
|
||||
public String getParameterNameOther(Map<String, Object> context) {
|
||||
String baseName;
|
||||
if (UtilValidate.isNotEmpty(getModelFormField().parameterName)) {
|
||||
baseName = getModelFormField().parameterName;
|
||||
baseName = getModelFormField().parameterName.expandString(context);
|
||||
} else {
|
||||
baseName = getModelFormField().name;
|
||||
}
|
||||
@@ -3101,7 +3106,7 @@ public class ModelFormField {
|
||||
private final String lookupPresentation;
|
||||
private final String lookupWidth;
|
||||
private final String showDescription;
|
||||
private final String targetParameter;
|
||||
private final FlexibleStringExpander targetParameter;
|
||||
|
||||
public LookupField(Element element, ModelFormField modelFormField) {
|
||||
super(element, modelFormField);
|
||||
@@ -3114,7 +3119,7 @@ public class ModelFormField {
|
||||
this.lookupPresentation = element.getAttribute("presentation");
|
||||
this.lookupWidth = element.getAttribute("width");
|
||||
this.showDescription = element.getAttribute("show-description");
|
||||
this.targetParameter = element.getAttribute("target-parameter");
|
||||
this.targetParameter = FlexibleStringExpander.getInstance(element.getAttribute("target-parameter"));
|
||||
}
|
||||
|
||||
public LookupField(int fieldSource, ModelFormField modelFormField) {
|
||||
@@ -3128,7 +3133,7 @@ public class ModelFormField {
|
||||
this.lookupPresentation = "";
|
||||
this.lookupWidth = "";
|
||||
this.showDescription = "";
|
||||
this.targetParameter = "";
|
||||
this.targetParameter = FlexibleStringExpander.getInstance("");
|
||||
}
|
||||
|
||||
public LookupField(LookupField original, ModelFormField modelFormField) {
|
||||
@@ -3196,19 +3201,32 @@ public class ModelFormField {
|
||||
return UtilValidate.isEmpty(this.showDescription) ? null : "true".equals(this.showDescription);
|
||||
}
|
||||
|
||||
public String getTargetParameter() {
|
||||
public FlexibleStringExpander getTargetParameter() {
|
||||
return targetParameter;
|
||||
}
|
||||
|
||||
public String getTargetParameter(final Map<String, Object> context) {
|
||||
return targetParameter.expandString(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Target Parameter is potentially a FlexibleStringExpander expression and should therefore be
|
||||
* evaluated within a given context.
|
||||
* <p> Use {@link #getTargetParameter(Map)} instead.</p>
|
||||
*/
|
||||
@Deprecated
|
||||
public List<String> getTargetParameterList() {
|
||||
List<String> paramList = new LinkedList<>();
|
||||
if (UtilValidate.isNotEmpty(this.targetParameter)) {
|
||||
StringTokenizer stk = new StringTokenizer(this.targetParameter, ", ");
|
||||
while (stk.hasMoreTokens()) {
|
||||
paramList.add(stk.nextToken());
|
||||
}
|
||||
}
|
||||
return paramList;
|
||||
// Evaluate target-parameter with a null context, treating it as a plain string.
|
||||
return getTargetParameterList(null);
|
||||
}
|
||||
|
||||
public List<String> getTargetParameterList(final Map<String, Object> context) {
|
||||
return Optional.ofNullable(getTargetParameter(context))
|
||||
.map(x -> x.split(","))
|
||||
.map(Arrays::stream)
|
||||
.orElse(Stream.empty())
|
||||
.map(String::trim)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -4360,4 +4378,4 @@ public class ModelFormField {
|
||||
formStringRenderer.renderTextFindField(writer, context, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -88,7 +88,7 @@ public class ModelFormFieldBuilder {
|
||||
private String name = "";
|
||||
private List<UpdateArea> onChangeUpdateAreas = new ArrayList<>();
|
||||
private List<UpdateArea> onClickUpdateAreas = new ArrayList<>();
|
||||
private String parameterName = "";
|
||||
private FlexibleStringExpander parameterName = FlexibleStringExpander.getInstance("");
|
||||
private Integer position = null;
|
||||
private String redWhen = "";
|
||||
private Boolean requiredField = null;
|
||||
@@ -133,7 +133,7 @@ public class ModelFormFieldBuilder {
|
||||
this.mapAcsr = FlexibleMapAccessor.getInstance(fieldElement.getAttribute("map-name"));
|
||||
this.modelForm = modelForm;
|
||||
this.name = name;
|
||||
this.parameterName = UtilXml.checkEmpty(fieldElement.getAttribute("parameter-name"), name);
|
||||
this.parameterName = FlexibleStringExpander.getInstance(UtilXml.checkEmpty(fieldElement.getAttribute("parameter-name"), name));
|
||||
String positionAtttr = fieldElement.getAttribute("position");
|
||||
Integer position = null;
|
||||
if (!positionAtttr.isEmpty()) {
|
||||
@@ -406,7 +406,7 @@ public class ModelFormFieldBuilder {
|
||||
return onClickUpdateAreas;
|
||||
}
|
||||
|
||||
public String getParameterName() {
|
||||
public FlexibleStringExpander getParameterName() {
|
||||
return parameterName;
|
||||
}
|
||||
|
||||
@@ -905,7 +905,7 @@ public class ModelFormFieldBuilder {
|
||||
}
|
||||
|
||||
public ModelFormFieldBuilder setParameterName(String parameterName) {
|
||||
this.parameterName = parameterName;
|
||||
this.parameterName = FlexibleStringExpander.getInstance(parameterName);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -2190,7 +2190,7 @@ public final class MacroFormRenderer implements FormStringRenderer {
|
||||
StringBuilder targetParameterIter = new StringBuilder();
|
||||
StringBuilder imgSrc = new StringBuilder();
|
||||
// FIXME: refactor using the StringUtils methods
|
||||
List<String> targetParameterList = lookupField.getTargetParameterList();
|
||||
List<String> targetParameterList = lookupField.getTargetParameterList(context);
|
||||
targetParameterIter.append("[");
|
||||
for (String targetParameter : targetParameterList) {
|
||||
if (targetParameterIter.length() > 1) {
|
||||
|
||||
Reference in New Issue
Block a user