I'm testing this displaytag that uses jstl in order to edit the fields, but it does not work... can anybody help me please...


<%@ page language='java' contentType="text/html"
info='Testing Displaytag'
import='java.util.*'
import='java.sql.*'
import= 'org.apache.taglibs.display.TableDecorator'
%>

<%@ taglib uri="http://displaytag.sourceforge.net/"; prefix="display" %>
<%@ taglib uri="http://java.sun.com/jstl/core"; prefix="c" %>




<% String method = request.getParameter("method");

if (method == null) {
List testData = new ArrayList();
Map map1 = new TreeMap();
map1.put("id","1");
map1.put("firstName","Bill");
map1.put("lastName","Gates");
testData.add(map1);
Map map2 = new TreeMap();
map2.put("id","2");
map2.put("firstName","Scott");
map2.put("lastName","McNealy");
testData.add(map2);
Map map3 = new TreeMap();
map3.put("id","3");
map3.put("firstName","Bill");
map3.put("lastName","Joy");
testData.add(map3);
session.setAttribute( "test", testData);
%>
<c:set var="browser" value="${header['User-Agent']}"/>
<c:out value="${browser}"/>

<c:set var="dummy" value="jstl works!"/>
<c:out value="${dummy}"/>

<%



} else {
// grap the testDate from the session
List testData = (List) session.getAttribute("test");
String useMe = request.getParameter("id");
if (useMe != null && method.equals("Delete")) {
// figure out which object it is and delete it
for (int i=0; i < testData.size(); i++) {
Map m = (TreeMap) testData.get(i);
String id = m.get("id").toString();
if (useMe.equals(id)) {
testData.remove(m);
%><div class="message">Delete succeeded!</div><%
break;
}
}
} else if (method.equals("Save")) {
// figure out which object it is and update it
for (int i=0; i < testData.size(); i++) {
Map m = (TreeMap) testData.get(i);
String id = m.get("id").toString();
if (useMe.equals(id)) {
m.put("firstName", request.getParameter("firstName"));
m.put("lastName", request.getParameter("lastName"));
testData.set(i, m);
%><div class="message">
<b><c:out value="${param.firstName} ${param.lastName}"/></b> updated successfully!
</div></h2><%
break;
}
}
} else if (method.equals("Add")) {
Map map4 = new TreeMap();
// generate a random number
Random generator = new Random();
String id = String.valueOf(generator.nextInt());
pageContext.setAttribute("id", id);
map4.put("id", id);
map4.put("firstName", "");
map4.put("lastName", "");
testData.add(map4);
%><c:redirect url="users-edit.jsp">
<c:param name="id" value="${id}"/>
<c:param name="method" value="Edit"/>
</c:redirect>
<%
}
session.setAttribute( "test", testData);
}
%>


<c:set var="checkAll">
<input type="checkbox" name="allbox" onclick="checkAll(this.form)" style="margin: 0 0 0 4px" />
</c:set>
<form name="editForm" action="users-edit.jsp">
<c:if test="${not empty param.method}">
<input type="button" onclick="location.href='users-edit.jsp'" class="button"
value="Reset List" />
</c:if>
<c:if test="${param.method == 'Edit'}">
<input type="submit" name="method" value="Save" class="button" />
</c:if>
<input type="submit" name="method" value="Edit" class="button"/>
<input type="button" name="method" value="Add" class="button" onclick="location.href='?method=Add'" />
<input type="submit" name="method" value="Delete" class="button" />
<br /><br />
<display:table name="${test}" id="test" class="list">
<display:column width="5" title="${checkAll}">
<input type="checkbox" name="id" value="<c:out value="${test.id}"/>" <c:if test="${param.id == test.id and param.method != 'Save'}">checked="checked"</c:if>
style="margin: 0 0 0 4px" onclick="radio(this)" />
</display:column>
<display:column title="First Name">
<c:choose>
<c:when test="${param.method == 'Edit' and param.id == test.id}">
<input type="text" name="firstName" style="padding: 0"
value="<c:out value="${test.firstName}"/>" />
</c:when>
<c:otherwise><c:out value="${test.firstName}"/></c:otherwise>
</c:choose>
</display:column>
<display:column title="Last Name">
<c:choose>
<c:when test="${param.method == 'Edit' and param.id == test.id}">
<input type="text" name="lastName" style="padding: 0"
value="<c:out value="${test.lastName}"/>" />
</c:when>
<c:otherwise><c:out value="${test.lastName}"/></c:otherwise>
</c:choose>
</display:column>
</display:table>
</form>



------------------------------------------------------- SF.Net email is sponsored by Shop4tech.com-Lowest price on Blank Media 100pk Sonic DVD-R 4x for only $29 -100pk Sonic DVD+R for only $33 Save 50% off Retail on Ink & Toner - Free Shipping and Free Gift. http://www.shop4tech.com/z/Inkjet_Cartridges/9_108_r285 _______________________________________________ displaytag-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/displaytag-user

Reply via email to