0

I am using display tag for showing a list of data in table it is working fine but right now, I want to add three more functionality(Add, Edit and Delete) similarly like this http://raibledesigns.com/display-edit/index.jsp on this table please check the code below and suggest me what modification I need to do

<%
List listOfOffice = (List) request.getAttribute("listOfOffice");
if(listOfOffice != null)
{
session.setAttribute("listOfOffice ", listOfOffice );
}
%>

/*

  some code here

*/

<%
if(session.getAttribute("listOfOffice ") != null)
{
%>

<table align="center"  width="600" border="1" cellpadding="1" cellspacing="1">
<tr>    
<td valign="top" class="border" height="200">
<display:table id="tableId" name="sessionScope.listOfROOffice" cellspacing="2"   cellpadding="1" pagesize="5" requestURI="addnewrooffice.do" export="false">
<display:column title="Sr. No." style="width:5%">              
<c:out value="${tableId_rowNum}"/>
</display:column>  
<display:column property="roOfficeId" title="RO Office Id" style="width:5%"/>
<display:column property="roOfficeName" title="RO Office Name" style="width:15%"/>
</display:table>
</td>
</tr>
</table>

<%

}

%>
Sergey K.
  • 24,894
  • 13
  • 106
  • 174
zakir hussain
  • 11
  • 1
  • 4

3 Answers3

1

Put your <table> inside a <form> plus add the three buttons inside. Make sure that they have same name attributes.

<input type="submit" name="btn" value="Add" />
<input type="submit" name="btn" value="Edit" />
<input type="submit" name="btn" value="Delete" />

Then you can perform condition statements in your java file once the form has been submitted:

if("Add".equals(request.getParameter("btn"))){
 //do something
}else if("Edit".equals(request.getParameter("btn"))){
 //do something
}else{
 //do something
}
Russell Gutierrez
  • 1,372
  • 8
  • 19
0

Just add <form> with submit buttons Add/Edit/Delete.

Alex
  • 11,451
  • 6
  • 37
  • 52
0

You can use javascript function for opening dialog box on click of Add & Edit button. And confirm box for delete.

<display:table id="tableId" name="sessionScope.listOfROOffice" cellspacing="2"   cellpadding="1" pagesize="5" requestURI="addnewrooffice.do" export="false">
    <display:column title="Sr. No." style="width:5%">              
        <c:out value="${tableId_rowNum}"/>
    </display:column>  
    <display:column property="roOfficeId" title="RO Office Id" style="width:5%"/>
    <display:column property="roOfficeName" title="RO Office Name" style="width:15%"/>
    <display:column title="Edit">
        <a href="#" onclick="editData('${tableId.rowNum}', '${tableId.roOfficeId}', '${tableId.roOfficeName}')">Edit</a>
    </display:column>
    <display:column title="Delete">
        <a href="#" onclick="deleteData('${tableId.rowNum}')">Edit</a>
    </display:column>
</display:table>

Here i use editData and deleteData javascript function. editData function open a dialog box and set data into it and deleteData function open html confirm box and on OK button it send id to action or servlet class.

You can also open dialog box for adding data on Add button.

Using this methods you can Add, Edit, Delete data using single page. Here you not required form action and also not required to send data to another page for Add and Edit.

Parth Patel
  • 799
  • 1
  • 13
  • 20