I applied pagination with Dispalytags in struts2. Now I want to add Two more columns to my table like "EDIT" and "DELETE". Here how can I pass the my ID value. I did something but it throws NumberFormatException. Below is my code:
Register.jsp
<s:form action="addUser">
<s:hidden name="user.id" />
<s:textfield key="user.name" />
<s:password key="user.password" />
------------
------
</s:form>
List.jsp
<display:table id="id" name="userList" pagesize="5" cellpadding="5px;"
cellspacing="5px;" style="margin-left:50px;margin-top:20px;" requestURI="">
<display:column property="name" title="name"/>
---------
<display:column title="Edit"><s:url id="editURL" action="editUser">
<s:param name="id" value="%{userList.id}"></s:param></s:url>
<s:a href="%{editURL}">Edit</s:a></display:column>
</display:table>
Here When I clicked on edit link it throws Number Format Exception
Exception is below
java.lang.NumberFormatException: null
in edit method
id value==null --->here I am not getting Id value
at java.lang.Long.parseLong(Long.java:404)
Below is Edit Action:
public String edit() {
System.out.println("in edit");
HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
System.out.println("id=="+request.getParameter("id"));
user = userDAO.listUserById(Long.parseLong(request.getParameter("id")));
return SUCCESS;
}
You can use two way.
You can put the edit option on the username. That is username you can make as link to edit the user and another column to delete.
Or you can add one more column extra for edit.
In your action class create a Long field called id
And in your method you can just pass the values.
edit method