wood burning stoves 2.0*
The moose likes Servlets and the fly likes Display table row value in another form Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Display table row value in another form" Watch "Display table row value in another form" New topic
Author

Display table row value in another form

Nitin Belaram
Ranch Hand

Joined: Mar 24, 2009
Posts: 67
I am displaying values in a table.
I want on selecting a check box the value in the row should be available in new form ,for which i am defining a array but itis not working



New_USER method


Please suggest how to get row value in the form
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Nitin Belaram wrote: itis not working


What do you mean by not working?. please post your errors or exception
Mohamed Inayath
Ranch Hand

Joined: Nov 22, 2004
Posts: 124
When you submit the page, what is the value for checkbox - request.getParameter("checkbox"); are you getting?

If you have got the empid then it will be enough to display the details in the next page.
Albareto McKenzie
Ranch Hand

Joined: Apr 08, 2009
Posts: 298
Hi!

I think you have missed the </form> tag if I am not wrong.

All that is a jsp or is two?
What do you have in Display.jsp?
Nitin Belaram
Ranch Hand

Joined: Mar 24, 2009
Posts: 67
Mohamed Inayath wrote:When you submit the page, what is the value for checkbox - request.getParameter("checkbox"); are you getting?

If you have got the empid then it will be enough to display the details in the next page.



I am not getting value for the checkbox,please check if my code is correct for getting value ,i am getting null value.
I am getting display.jsp only with header
Mohamed Inayath
Ranch Hand

Joined: Nov 22, 2004
Posts: 124
Nitin Belaram wrote:
I am not getting value for the checkbox,please check if my code is correct for getting value ,i am getting null value.
I am getting display.jsp only with header


Does Display.jsp exist?

You are retrieving the the selected checkbox values in the same JSP why are you doing that?
Nitin Belaram
Ranch Hand

Joined: Mar 24, 2009
Posts: 67
Mohamed Inayath wrote:
Nitin Belaram wrote:
I am not getting value for the checkbox,please check if my code is correct for getting value ,i am getting null value.
I am getting display.jsp only with header


Does Display.jsp exist?

You are retrieving the the selected checkbox values in the same JSP why are you doing that?


Display.jsp is the same page in which i had defined code ,
And i am not getting
String str=request.getParameter("value");
System.out.println(" Str" + str);
it is giving null value.

Do i need to have new jsp for selected record
Mohamed Inayath
Ranch Hand

Joined: Nov 22, 2004
Posts: 124
Nitin Belaram wrote:
Display.jsp is the same page in which i had defined code ,
And i am not getting
String str=request.getParameter("value");
System.out.println(" Str" + str);
it is giving null value.

Do i need to have new jsp for selected record



String str=request.getParameter("value");
From where did you get value parameter.

I believe you need to do something like String[] empValues = request.getParameter("Empid");

If you are expecting only one user selection then why are you using checkbox.
Try using radio button.
Nitin Belaram
Ranch Hand

Joined: Mar 24, 2009
Posts: 67
Mohamed Inayath wrote:
Nitin Belaram wrote:
Display.jsp is the same page in which i had defined code ,
And i am not getting
String str=request.getParameter("value");
System.out.println(" Str" + str);
it is giving null value.

Do i need to have new jsp for selected record



String str=request.getParameter("value");
From where did you get value parameter.

I believe you need to do something like String[] empValues = request.getParameter("Empid");

If you are expecting only one user selection then why are you using checkbox.
Try using radio button.

]


When using

String[] empValues = request.getParameter("Empid");

it is giving error cannot convert from String to String[]


There can be more then one selection
Mohamed Inayath
Ranch Hand

Joined: Nov 22, 2004
Posts: 124
Sorry; It should be request.getParameterValues("Empid");
Albareto McKenzie
Ranch Hand

Joined: Apr 08, 2009
Posts: 298
Ok, if you recive more than one value (or you expect that) you should use a method that allows you to store them all, such as request.getParameterValues(String param);
Then you have to stored that elements on a String[] and iterate over it to display the values.
Albareto McKenzie
Ranch Hand

Joined: Apr 08, 2009
Posts: 298
Just as Mohamed has told you xDD
Nitin Belaram
Ranch Hand

Joined: Mar 24, 2009
Posts: 67
Mohamed Inayath wrote:Sorry; It should be request.getParameterValues("Empid");


I am getting empid value when i use out.println, But i am not getting all the column value corresponding to empid value.
Albareto McKenzie
Ranch Hand

Joined: Apr 08, 2009
Posts: 298
You mean the other attributes of user?
Nitin Belaram
Ranch Hand

Joined: Mar 24, 2009
Posts: 67
Albareto McKenzie wrote:You mean the other attributes of user?


yes the other attribute releted to emp id
Albareto McKenzie
Ranch Hand

Joined: Apr 08, 2009
Posts: 298
That's because when you submit the value of your checkbox is user.getEmpid(), you should put user in the value, so all the user goes to the next page, then you have to cast it and so on...
Nitin Belaram
Ranch Hand

Joined: Mar 24, 2009
Posts: 67
Albareto McKenzie wrote:That's because when you submit the value of your checkbox is user.getEmpid(), you should put user in the value, so all the user goes to the next page, then you have to cast it and so on...


Please explain how to do that
Albareto McKenzie
Ranch Hand

Joined: Apr 08, 2009
Posts: 298
Let's see, now you are setting a String as the value of the field "Empid" by doing



but you don't want the id but all the object, so you can use it in the next page, so you can do:



and then in the next page:



I think this will work.
Nitin Belaram
Ranch Hand

Joined: Mar 24, 2009
Posts: 67
Albareto McKenzie wrote:Let's see, now you are setting a String as the value of the field "Empid" by doing



but you don't want the id but all the object, so you can use it in the next page, so you can do:



and then in the next page:



I think this will work.


how to display on next page and when i am using



it is giving error User cant be resolved
Albareto McKenzie
Ranch Hand

Joined: Apr 08, 2009
Posts: 298
Well, you have to use your own class, that is New_USER, I put just User for answering you faster :P
Nitin Belaram
Ranch Hand

Joined: Mar 24, 2009
Posts: 67
Albareto McKenzie wrote:Well, you have to use your own class, that is New_USER, I put just User for answering you faster :P


how to display in next page
Albareto McKenzie
Ranch Hand

Joined: Apr 08, 2009
Posts: 298
But do you receive the New_USER?
Nitin Belaram
Ranch Hand

Joined: Mar 24, 2009
Posts: 67
Albareto McKenzie wrote:But do you receive the New_USER?


No i cant understand how to proceed further

my jsp code is[code]
<%@page import="java.util.*"%>
<%@page import="mydao.New_USER;"%>
<html>
<head>

<title>Insert title here</title>
<script language="java script" type="text/javascript">
</script>
<script type="text/javascript">

function doDeleteSelect(objThis,value)
{
//alert( objThis.checked);
//alert( document.all.item("deletelist").value);
//alert(document.getElementById('Delete').value);
var temp=document.all.item("deletelist").value;
if (objThis.checked)
{
temp=temp + ",'" + value + "'"
}
else
{
temp=temp.replace(",'" + value + "'","");
}
document.all.item("deletelist").value=temp;
//alert( document.all.item("deletelist").value);
}
</script>

</head>
<body>
<form id="form1" name="form1" >

<%


// for(int i = 0; i <= empfname.size();i++)
//{


%>
<CENTER>
<TABLE CELLSPACING="1" CELLPADDING="4" BORDER="3">
<TR>
<TH>Select</TH><TH>Empid</TH><TH>EmpFName</TH><TH>EmpLName</TH><TH>Department</TH><TH>Designation</TH><TH>Email</TH><TH>Address</TH><TH>Project</TH><TH>Manager</TH>
</TR>

<%



ArrayList p = new ArrayList ();
ArrayList rows = new ArrayList (p);

if (request.getAttribute("AttributeUser") != null) {

rows = (ArrayList ) request.getAttribute("AttributeUser");

for(int i=0; i< rows.size(); i++) {
New_USER user = (New_USER) rows.get(i);
%>
<tr>
<td><input type="checkbox" name="Empid" value= "<%=user%>" /></td>
<td> <%= user.getEmpid()%></td>
<td> <%= user.getEmpfname()%> </td>
<td> <%= user.getEmplname()%> </td>
<td> <%= user.getDepartment()%> </td>
<td> <%= user.getDesignation()%> </td>
<td> <%= user.getEmail()%> </td>
<td> <%= user.getAddress()%> </td>
<td> <%= user.getProject()%> </td>
<td> <%= user.getManager()%> </td>

</tr>

<%}}%>

</Table>


<%
ArrayList items=new ArrayList();
ArrayList items1=new ArrayList();
String[] itemselected;
String itemname;
// itemselected=request.getParameterValues("Empid");
itemselected=request.getParameterValues("Empfname");
if(itemselected!=null){
for(int i=0;i<itemselected.length;i++){
itemname=itemselected[i];
out.println(itemname);
items.add(itemname);
// items1.addAll(items);
}

}

Iterator iterator=items.iterator();



%>
<%

mydao.New_USER user = mydao("New_USER")request.getParameter("Empid");
%>


<input type="submit" name="button" value = delete onclick= " Display.jsp"/>

</CENTER></form>

</body>

</html>
[code]

i want on selection of check box to display the row in the same page from where it can be deleted.
Albareto McKenzie
Ranch Hand

Joined: Apr 08, 2009
Posts: 298
Edit: Please close the code tag in your message

Let's see...

If you want to use the same page you should know that the information has been sent, so you can use the given information, I would do something like that:


So you have the users, and then you just iterate the array to print in the screen...
Albareto McKenzie
Ranch Hand

Joined: Apr 08, 2009
Posts: 298
I think you should have a look to jsp and servlets tutorial
jsp tutorial > http://www.jsptut.com/
servlet tutorial > http://www.jsptube.com/
Nitin Belaram
Ranch Hand

Joined: Mar 24, 2009
Posts: 67
Albareto McKenzie wrote:Edit: Please close the code tag in your message

Let's see...

If you want to use the same page you should know that the information has been sent, so you can use the given information, I would do something like that:


So you have the users, and then you just iterate the array to print in the screen...


Please suggest
where to put this code in my jsp and array rows has been declare above so it is giving duplicate rows error
Albareto McKenzie
Ranch Hand

Joined: Apr 08, 2009
Posts: 298
Of course! You have to delete this:

ArrayList p = new ArrayList ();
ArrayList rows = new ArrayList (p);

and implement the other solution.

I repeat:

Albareto McKenzie wrote:I think you should have a look to jsp and servlets tutorial
jsp tutorial > http://www.jsptut.com/
servlet tutorial > http://www.jsptube.com/
Nitin Belaram
Ranch Hand

Joined: Mar 24, 2009
Posts: 67
Albareto McKenzie wrote:Of course! You have to delete this:

ArrayList p = new ArrayList ();
ArrayList rows = new ArrayList (p);

and implement the other solution.

I repeat:

Albareto McKenzie wrote:I think you should have a look to jsp and servlets tutorial
jsp tutorial > http://www.jsptut.com/
servlet tutorial > http://www.jsptube.com/



but i am using these array to display my record in the table which i am getting from my database and from that table i want on selection of checkbox the corresponding rows to be displayed for deletion
Albareto McKenzie
Ranch Hand

Joined: Apr 08, 2009
Posts: 298
Let me see if I have understood... you want to have the table of users from the db and then in the same page the users that have been selected before?
Mohamed Inayath
Ranch Hand

Joined: Nov 22, 2004
Posts: 124
Hey,
When you retrieve the user details add them to as Map with key as Emp id and value as New User object(Object containing the user details).
Set the Map into session.
Add check to find whether Empid exists or not(request.getParameterValues("Empid")).
If this is NULL then Iterate the Keys from the Map available in the session and display the Emp ids on the screen.
If not then User has selected the Emp id, retreive the details for the selected Emp id from the Map again available in the session.

This is what you have to do.

Try this out.

Nitin Belaram
Ranch Hand

Joined: Mar 24, 2009
Posts: 67
Albareto McKenzie wrote:Let me see if I have understood... you want to have the table of users from the db and then in the same page the users that have been selected before?


Yes want to have the table of users from the db and then select from that table which i got from db and on basic of selection display on the same page for deletion
Albareto McKenzie
Ranch Hand

Joined: Apr 08, 2009
Posts: 298
Ok, I though you wanted to show in a table just the selected. Mohamed has given you a good solution
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Display table row value in another form
 
Similar Threads
how to delete the row on click of a checkbox instantly ?
update record for selection of id
Sending checkbox value to two different servlet page
not getting value in doget method of servlet
how to get value in drop down while doing update