• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Display table row value in another form

 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nitin Belaram wrote: itis not working



What do you mean by not working?. please post your errors or exception
 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry; It should be request.getParameterValues("Empid");
 
Albareto McKenzie
Ranch Hand
Posts: 312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just as Mohamed has told you xDD
 
Nitin Belaram
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You mean the other attributes of user?
 
Nitin Belaram
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Albareto McKenzie wrote:You mean the other attributes of user?



yes the other attribute releted to emp id
 
Albareto McKenzie
Ranch Hand
Posts: 312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But do you receive the New_USER?
 
Nitin Belaram
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, I though you wanted to show in a table just the selected. Mohamed has given you a good solution
reply
    Bookmark Topic Watch Topic
  • New Topic