Java 如何使用display标记从struts2中的jsp将要删除/编辑的行中的值传递给action类?
我想用struts2在显示标签中创建编辑、删除链接。这是我的jsp代码Java 如何使用display标记从struts2中的jsp将要删除/编辑的行中的值传递给action类?,java,struts2,displaytag,Java,Struts2,Displaytag,我想用struts2在显示标签中创建编辑、删除链接。这是我的jsp代码 <%@ page contentType="text/html; charset=UTF-8"%> <%@ taglib prefix="s" uri="/struts-tags"%> <%@taglib uri="http://displaytag.sf.net" prefix="display" %> <html> <head> <title&g
<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@taglib uri="http://displaytag.sf.net" prefix="display" %>
<html>
<head>
<title>Contact Manager - display tag Example</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<display:table name="contactList" requestURI="" pagesize="10" export="true" cellpadding="1" uid="sr" cellspacing="1" size="50"
defaultorder="ascending" sort="list" style="width:850"
id="row">
<display:column property="id" title="serial no" sortable="true" />
<display:column property="lastName" title="TV Show" sortable="true" />
<display:column property="firstName" title="User Name" sortable="true" />
<display:column property="emailId" title="Email Id" sortable="true" />
<display:column media="html"
title="Delete"
style="text-align:center">
<s:url id="deleteUrl" action="deleteLink">
<s:param name="id1" value="#attr.row.id" />
</s:url>
<s:a href="%{deleteUrl}">
Delete
</s:a>
</display:column>
<display:column media="html"
title="edit"
style="text-align:center">
<a href="deleteLink?id=<s:property value="id"/>">edit</a>
</display:column>
<display:setProperty name="export.excel.filename" value="ActorDetails.xls"/>
<display:setProperty name="export.pdf.filename" value="ActorDetails.pdf"/>
<display:setProperty name="export.pdf" value="true" />
</display:table>
</body>
</html>
给出一个输出:ID为null
请提出一些解决办法
谢谢
这是联系人bean
package net.viralpatel.contact.model;
import java.io.Serializable;
import java.sql.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name="Contacts")
public class Contact implements Serializable{
private static final long serialVersionUID = -8767337896773261247L;
private Long id;
private String firstName;
private String lastName;
private String emailId;
private String cellNo;
private Date birthDate;
private String website;
private Date created;
@Id
@GeneratedValue
@Column(name="id")
public Long getId() {
return id;
}
@Column(name="firstname")
public String getFirstName() {
return firstName;
}
@Column(name="lastname")
public String getLastName() {
return lastName;
}
@Column(name="email_id")
public String getEmailId() {
return emailId;
}
@Column(name="cell_no")
public String getCellNo() {
return cellNo;
}
@Column(name="birthdate")
public Date getBirthDate() {
return birthDate;
}
@Column(name="website")
public String getWebsite() {
return website;
}
@Column(name="created")
public Date getCreated() {
return created;
}
public void setId(Long id) {
this.id = id;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public void setEmailId(String emailId) {
this.emailId = emailId;
}
public void setCellNo(String cellNo) {
this.cellNo = cellNo;
}
public void setBirthDate(Date birthDate) {
this.birthDate = birthDate;
}
public void setCreated(Date created) {
this.created = created;
}
public void setWebsite(String website) {
this.website = website;
}
}
下面是关于display:table标记的说明:
id:参见“uid”
uid:用于标识此表的唯一id表示当前行的对象也被添加到此名称下的pageContext中,以便您可以使用${uid}在列正文中引用它。您还可以使用uid_rowNum引用当前行号。同一页中的两个表不能具有相同的id(分页和排序将同时影响这两个表)。如果未指定“htmlId”,则生成表的html id将使用相同的值
(强调矿山)
因此,在标记中选择id
和uid
(并且在指定id时不要重复两次),而不是同时使用这两个选项,然后(假设您保留uid),使用${sr}引用当前元素:
<s:param name="id1" value="${sr.id}" />
这里是答案,我们可以使用
实例化bean类,然后
充当setter方法,其值可以使用bean类联系人的getter方法在action类中检索
<display:column media="html"
title="Delete"
style="text-align:center">
<s:url id="deleteUrl" action="deleteLink">
<s:bean name="net.viralpatel.contact.model.Contact"></s:bean>
<s:param name="id" value="#attr.row.id"></s:param>
<s:param name="firstName" value="#attr.row.firstName"></s:param>
</s:url>
<s:a href="%{deleteUrl}">
Delete
</s:a>
</display:column>
删除
您可以使用
#attr.uidOfYourTable.property
就你而言
<display:column media="html" title="edit" style="text-align:center">
<a href="deleteLink?id=<s:property value="#attr.sr.id"/>">edit</a>
</display:column>
(忽略编辑链接指向DeleteLink操作的事实:o)您可以这样编写:
<display:column property="status" title="Status" sortable="true" paramId="aid" paramProperty="aid" href="/MsgSystem/adminread" />
org.apache.jasper.jaspereException:根据标记文件中的TLD或属性指令,属性值不接受任何表达式您可能需要传递OGNL表达式,但我不掌握OGNL语法。这里可能有类似于#sr.id
的答案,我们可以使用来实例化bean类,然后充当setter方法,可以使用bean类Contact Delete的getter方法在action类中检索其值
<display:column media="html" title="edit" style="text-align:center">
<a href="deleteLink?id=<s:property value="#attr.sr.id"/>">edit</a>
</display:column>
<display:column property="status" title="Status" sortable="true" paramId="aid" paramProperty="aid" href="/MsgSystem/adminread" />