File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes How to display a table data after clicking a button in struts? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to display a table data after clicking a button in struts?" Watch "How to display a table data after clicking a button in struts?" New topic
Author

How to display a table data after clicking a button in struts?

Vidya Gupta
Ranch Hand

Joined: Mar 18, 2012
Posts: 96

Hi,

In my jsp am having 2 buttons like "button1" and "button2". When i click on these buttons i need to display a table to the user.


When i click on the button1 i need to display the table like this,

column1 column2 column3
-------------------------------------
111 222 333
444 555 666




I tried this but it is not displaying the table after clicking button1
jatan bhavsar
Ranch Hand

Joined: Jul 23, 2008
Posts: 296

He y Vidya,

what are you trying to achieve? Its not the struts functioanlity. You can hide the table with the div tag through java script and when ever you press the button ,onclick event you can show the table ..
Struts has nothing to do with this. Let us know if still there is any confusion.

Regards
Jatan
Vidya Gupta
Ranch Hand

Joined: Mar 18, 2012
Posts: 96


Hi Jatan,

Thanks for the reply.. I want to achieve this functionality by using struts.

<input type="button" value="Button1" class="btn" onclick="">

The onclick attribute contains the path to the struts action class.

If you have any idea about this please let me know.. If you know this functionality in javascript please provide me the sample code.

Thanks,
Vidya
jatan bhavsar
Ranch Hand

Joined: Jul 23, 2008
Posts: 296

Hi vidya,

There can be two things 1) you can click the button , onclick event you can submit the form fetch the data display into the pop up page where you can show the data with table.

Java script code is very simple to submit the form.

2) you can keep the table hide with the data once user press button you can just show that table.

These are two ways try implementing and paste the code whatever you have tried so far .. We will help you. but show some effort.

Regards
Jatan
Vidya Gupta
Ranch Hand

Joined: Mar 18, 2012
Posts: 96

Hi jatan,

I tried in javascript like this..







Is this correct? Please let me know if i am wrong..

Thanks,
Vidya
Rajkamal Pillai
Ranch Hand

Joined: Mar 02, 2005
Posts: 443
    
    1

Where do the values inside the table get stored? If they should be fetched from a data store of any sort you will have to use Struts action for this.
If they are available on the page then javascript would suffice.

Inside myfunction() we need a reference to 'displaytable' and not 'displaytable.value'. To my knowledge <table> does not have a value attribute. So I assume it would be undefined.
I suggest the changes below:



And



Note: Please ignore ~ character. I had to use it as the style attribute and its value was not being displayed.

Cheers,
Raj.
jatan bhavsar
Ranch Hand

Joined: Jul 23, 2008
Posts: 296

hi Vidya,

That code didnt work for me but this works fine here.
Script function


This works fine for me.

Regards
Jatan
Vidya Gupta
Ranch Hand

Joined: Mar 18, 2012
Posts: 96
Hi Raj Kamal,

Here am not fetching the data from database. Am just hard coding the table data in jsp and displaying the table to user.




Raj Kamal wrote:Where do the values inside the table get stored? If they should be fetched from a data store of any sort you will have to use Struts action for this.
If they are available on the page then javascript would suffice.

Inside myfunction() we need a reference to 'displaytable' and not 'displaytable.value'. To my knowledge <table> does not have a value attribute. So I assume it would be undefined.
I suggest the changes below:



And



Note: Please ignore ~ character. I had to use it as the style attribute and its value was not being displayed.

Cheers,
Raj.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to display a table data after clicking a button in struts?
 
Similar Threads
How to getParameter value
jsp table
Doubts in jsp
Display a Form on a button click using struts tags
How to display a table data after clicking submit button in struts?