The MVStringEditor (mved) widget provides an editor control that can store multiple values. It provides the following benefits:
Allows single source for a multivalue string edit (mved) control
Customizes the control for the browser used
Automatically detects the browser and sets the appropriate mode
Allows the mode to be overridden
The mved supports the following Web browsers:
Firefox* 1.5.x and later
Internet Explorer 6 and later
Include the required mved JavaScript file.
Add the mved on the page.
Load values into the control.
Get values from the control.
For example:
01:<%@ page pageEncoding="utf-8" contentType="text/html;charset=utf-8" %> 02:<%@ taglib uri="/WEB-INF/iman.tld" prefix="iman" %> 03:<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %> 04:
05:<HTML> 06:<HEAD> 07: <LINK rel="stylesheet" href="<c:out value="${ContextPath}" />/portal/modules/dev/css/hf_style.css"> 08: <iman:mvedScripts/> 09: <iman:eMFrameScripts/> 10:
11: <SCRIPT> 12: function onInit() 13: { 14: mvLoadFromPack("mved1", "<c:out value="${myData}"/>"); 15: } 16: 17: function onExit() 18: { 19: document.form.mvedData.value = mvGetValuesAsPack("mved1"); 20: } 21: </SCRIPT> 22:</HEAD> 23: 24:<BODY onLoad="onInit();"> 25:<FORM name="form" method="post" action="webacc" onSubmit="return onExit();"> 26: <iman:mved name="mved1" width="150"/> 27: <input type=”hidden” name=”mvedData”/> 28:</FORM> 29:</BODY> 30:</HTML>
Of particular interest in the above example are the following:
To pass values to the control with Java:
String values = ...;
request.setAttribute("myItems", values);
To get values from the control with Java:
String pack = request.getParameter("mved1_packValues");
String[] items = eMFrameUtils.unpack(pack, taskContext);
When including the mved, you must decide on a mode. If you do not set a mode, it chooses a mode for you based on the current device.
Table 6-6 MVStringEditor modes
Table 6-7 MVStringEditor parameters
The following JavaScript methods allow you to interact with the MVStringEditor:
mvLoadFromPack (String name, String packedString) The name parameter must be the same as the MVStringEditor_name used for MVStringEditor_inc.
mvGetValuesAsPack (String name) : String (packed) The name parameter must be the same name as the MVStringEditor_name used for MVStringEditor_inc. The return value is a packed string, safe to be posted.
mvGetValuesAsXml (String name) : String (xml content) The name parameter must be the same as the MVStringEditor_name used for MVStringEditor_inc. The return value is XML in string format.
mvLoadFromXml (String name, String xml) The name parameter must be the same as the MVStringEditor_name used for MVStringEditor_inc.
mvEnable (String name)
mvDisable (String name)
The JavaScript methods mvLoadFromPack and mvGetValuesAsPack interact with packed Strings. An empty string is not a valid packed string. If you want an empty packed string, call pack(new Array()). There are methods in eMFrameScripts (JavaScript) and eMFrameUtils (Java) to pack and unpack these strings.
Following are some MVStringEditor examples::
In JavaScript header:
oninit : mvLoadFromPack ("myControl", "<c:out value="${data}"/>"); onexit: document.form.data.value = mvGetValuesAsPack ("myControl")
In HTML body:
<iman:mved name=”myControl” ignoreCase=”true” enforceUnique=”true”/>
In JavaScript header:
oninit: mvLoadFromXml("mycontrol", "<root><value>...</value></root>"); onexit: hiddenField = mvGetValuesAsXml("mycontrol");
In XML:
<root> <value>test1</value> <value>test2</value> <value>test3</value> </root>