This tag evaluates an expression and places the result in the
javax.servlet.jsp.PageContext object, where the data is available to the JSP EL and JSP scriptlet.
This tag can be used to extract data from forms, Controller files, and any data binding context and
make it available to scriptlets.
In the following example, the getData tag gets the value of a property in the page flow and
makes it available to the JSP via the JSP EL implicit object ${pageScope} .
<netui-data:getData resultId="myData" value="${pageFlow.myData}"/>
The following scriptlet extracts the data from the PageContext object and writes it to
the rendered HTML:
${pageScope.myData}
In this first example, the <netui-data:getData> tag loads data into the
javax.servlet.jsp.PageContext 's
attribute map. It can then be accessed using the
javax.servlet.jsp.PageContext.getAttribute(String) method.
<netui:form action="lastNameAction" focus="lastname">
...
<netui-data:getData resultId="first" value="${actionForm.firstname}"/>
...
<%
String firstName = (String)pageContext.getAttribute("first");
System.out.println("First Name = " + firstName);
...
%>
...
</netui:form>
This example shows how to use <netui-data:getData> and the PageContext inside of other
containers, in this case a <netui-data:repeater> tag. The <netui-data:getData> below extracts each
element as the <netui-data:repeater> iterates over the data set and writes it to the Java console:
<netui-data:repeater dataSource="pageFlow.strArr">
...
<netui-data:repeaterItem>
<netui:span value="${container.item}" />
<netui-data:getData resultId="item" value="${container.item}"/>
<%
String currentItem = (String) pageContext.getAttribute("item");
System.out.println(currentItem);
...
%>
</netui-data:repeaterItem>
...
</netui-data:repeater>
javax.servlet.jsp.PageContextjavax.servlet.jsp.PageContextjavax.servlet.jsp.PageContext.getAttribute(String) |