Author: jonesde
Date: Wed Jul 21 07:30:37 2010 New Revision: 966123 URL: http://svn.apache.org/viewvc?rev=966123&view=rev Log: Added support for parameters-map for menu widget link elements Modified: ofbiz/trunk/framework/widget/dtd/widget-menu.xsd ofbiz/trunk/framework/widget/src/org/ofbiz/widget/WidgetWorker.java ofbiz/trunk/framework/widget/src/org/ofbiz/widget/menu/ModelMenuItem.java Modified: ofbiz/trunk/framework/widget/dtd/widget-menu.xsd URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/dtd/widget-menu.xsd?rev=966123&r1=966122&r2=966123&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/dtd/widget-menu.xsd (original) +++ ofbiz/trunk/framework/widget/dtd/widget-menu.xsd Wed Jul 21 07:30:37 2010 @@ -220,6 +220,7 @@ under the License. </xs:simpleType> </xs:attribute> <xs:attribute name="confirmation-message" type="xs:string"><xs:annotation><xs:documentation>The message displayed when request-confirm is set to true</xs:documentation></xs:annotation></xs:attribute> + <xs:attribute name="parameters-map" type="xs:string"/> </xs:attributeGroup> <xs:element name="parameter"> <xs:complexType> Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/WidgetWorker.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/WidgetWorker.java?rev=966123&r1=966122&r2=966123&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/WidgetWorker.java (original) +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/WidgetWorker.java Wed Jul 21 07:30:37 2010 @@ -29,6 +29,7 @@ import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.StringUtil; import org.ofbiz.base.util.UtilDateTime; import org.ofbiz.base.util.UtilGenerics; @@ -98,6 +99,22 @@ public class WidgetWorker { } for (Map.Entry<String, String> parameter: parameterMap.entrySet()) { + String parameterValue = null; + if (!(parameter.getValue() instanceof String)) { + // it's probably a String[], just get the first value + Object parameterObject = parameter.getValue(); + if (parameterObject instanceof String[]) { + String[] parameterArray = (String[]) parameterObject; + parameterValue = parameterArray[0]; + Debug.logInfo("Found String array value for parameter [" + parameter.getKey() + "], using first value: " + parameterValue, module); + } else { + // not a String, and not a String[], just use toString + parameterValue = parameterObject.toString(); + } + } else { + parameterValue = parameter.getValue(); + } + if (needsAmp) { externalWriter.append("&"); } else { @@ -107,9 +124,9 @@ public class WidgetWorker { externalWriter.append('='); StringUtil.SimpleEncoder simpleEncoder = (StringUtil.SimpleEncoder) context.get("simpleEncoder"); if (simpleEncoder != null) { - externalWriter.append(simpleEncoder.encode(parameter.getValue())); + externalWriter.append(simpleEncoder.encode(parameterValue)); } else { - externalWriter.append(parameter.getValue()); + externalWriter.append(parameterValue); } } } else { Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/menu/ModelMenuItem.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/menu/ModelMenuItem.java?rev=966123&r1=966122&r2=966123&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/menu/ModelMenuItem.java (original) +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/menu/ModelMenuItem.java Wed Jul 21 07:30:37 2010 @@ -37,6 +37,7 @@ import org.ofbiz.base.util.UtilMisc; import org.ofbiz.base.util.UtilProperties; import org.ofbiz.base.util.UtilValidate; import org.ofbiz.base.util.UtilXml; +import org.ofbiz.base.util.collections.FlexibleMapAccessor; import org.ofbiz.base.util.string.FlexibleStringExpander; import org.ofbiz.entity.Delegator; import org.ofbiz.entity.GenericEntityException; @@ -622,6 +623,7 @@ public class ModelMenuItem { protected boolean secure = false; protected boolean encode = false; protected String linkType; + protected FlexibleMapAccessor<Map<String, String>> parametersMapAcsr; protected List<WidgetWorker.Parameter> parameterList = FastList.newInstance(); protected boolean requestConfirmation = false; protected FlexibleStringExpander confirmationMsgExdr; @@ -645,6 +647,7 @@ public class ModelMenuItem { } this.linkType = linkElement.getAttribute("link-type"); + this.parametersMapAcsr = FlexibleMapAccessor.getInstance(linkElement.getAttribute("parameters-map")); List<? extends Element> parameterElementList = UtilXml.childElementList(linkElement, "parameter"); for (Element parameterElement: parameterElementList) { this.parameterList.add(new WidgetWorker.Parameter(parameterElement)); @@ -748,12 +751,10 @@ public class ModelMenuItem { public Map<String, String> getParameterMap(Map<String, Object> context) { Map<String, String> fullParameterMap = FastMap.newInstance(); - /* leaving this here... may want to add it at some point like the hyperlink element: Map<String, String> addlParamMap = this.parametersMapAcsr.get(context); if (addlParamMap != null) { fullParameterMap.putAll(addlParamMap); } - */ for (WidgetWorker.Parameter parameter: this.parameterList) { fullParameterMap.put(parameter.getName(), parameter.getValue(context)); |
Free forum by Nabble | Edit this page |