Get your CodeRanch badge!*
The moose likes JSP and the fly likes need help with a logic Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "need help with a logic" Watch "need help with a logic" New topic
Author

need help with a logic

Aman Singh
Ranch Hand

Joined: Oct 30, 2008
Posts: 57
Hi Experts,

I need your help in figuring out a solution for a problem.
I have a table on jsp (Snapshot), According to a new requirement:

All the cells where value is less than 100%, those numbers should be an HTML link. I guess
I can figure out a way to do this, the problem I am facing is, on clicking any of these links,
the control needs to be directed to a specific page related to that cells application (First Column)

now how do I know figure out a way to know what cell user actually clicked. one way I could think
is is passing parameters along with the link, but then again, how do I assign these parameters to every cell.?



[Thumbnail for Table.PNG]

Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
I don't know how you generate your table, but I guess you have 2 loops. loop 1 writes the rows, and loop 2 the cells.

So, when you enter loop 1, set a flag which application you're at right now. Upon looping the cells, you can pick up on it.


JDBCSupport - An easy to use, light-weight JDBC framework -
Aman Singh
Ranch Hand

Joined: Oct 30, 2008
Posts: 57
Thanks for the reply Sebastian

I am fairly new to this. Could you please tell me how do I set a flag? This is the code I am using to generate the table.

Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183


rs.getString(1) holds the current application, store it right after that so you can pick it up in the other loop.

Also, are you sure you don't want to move your java code into a servlet instead? This looks horrid.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60057
    
  65

Doing JDBC in a JSP? In 2009?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ranveer K Kumar
Ranch Hand

Joined: Sep 13, 2009
Posts: 64
When you creating dynamic table that time you can generate link with the value (here i am asuming pk) and by that pk on link you can do your rest of logic.

something like this

[url][/url]

when you will click on link you can get value (pk) on new page and by that keyvalue you can do rest of your logic.
Aman Singh
Ranch Hand

Joined: Oct 30, 2008
Posts: 57
Hi Sebastian,

Thanks for the reply, though it went over my head, i will try my best to mess with it :-)

I know that JSP looks horrible, but I am not sure, how I will write all that code in a Servlet and then use in my JSP
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60057
    
  65

Your JDBC should not even be done in a servlet. Rather a model-layer class should gather the data, put it into a normal Java collection, and pass it onto the servlet controller to be passed to the JSP.

There, use the JSTL and EL to render the table.

You might find this article on properly structuring web applications helpful.
Aman Singh
Ranch Hand

Joined: Oct 30, 2008
Posts: 57
@ Bear,

very very new to this trying my level best to learn as much as I can from people like you.

@ Ranveer,

Did you try to put any code? if yes, then I cant see anything
Ranveer K Kumar
Ranch Hand

Joined: Sep 13, 2009
Posts: 64
Bear Bibeault wrote:Doing JDBC in a JSP? In 2009?


May be they doing very small project or just for learning purpose
Aman Singh
Ranch Hand

Joined: Oct 30, 2008
Posts: 57
yes Ranveer,

Its a very small project.
Ranveer K Kumar
Ranch Hand

Joined: Sep 13, 2009
Posts: 64
@ Ranveer,

Did you try to put any code? if yes, then I cant see anything


yes but link is truncated so again i edited with ahref instead of a href you can understand
Aman Singh
Ranch Hand

Joined: Oct 30, 2008
Posts: 57
Thanks for the help folks

Ranveer now its making sense to me :-) sorry for acting so dumb.

But this dynamic value would be the same for complete row right?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60057
    
  65

Ranveer K Kumar wrote:May be they doing very small project or just for learning purpose

That's no excuse. Learning bad habits, even for a small project is not a great idea. And learning bad habits is not a good "learning purpose".

Besides, small projects have a habit of becoming big projects, and then you're stuck with the mistakes you made at the outset.

My advice is to use good practices always.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60057
    
  65

Aman Singh wrote:trying my level best to learn as much as I can from people like you.

Then my advice, like I said, is to develop good habits and good practices right off the bat.

Never put Java code into a JSP. That's a practice that was discredited over 6 years ago with advent of JSP 2.0.

And learn how to properly construct web applications and always follow that structure. Even for very small projects. It's a good learning experience, and if the project turns out to grow, you've already got a good base to build upon.
Aman Singh
Ranch Hand

Joined: Oct 30, 2008
Posts: 57
Thanks Bear, Ranveer, Sabsatian,

I will surely start reading more on Servlets and jsps. Will bug you guys more with my doubts :-)
Ranveer K Kumar
Ranch Hand

Joined: Sep 13, 2009
Posts: 64
Bear Bibeault wrote:
That's no excuse. Learning bad habits, even for a small project is not a great idea. And learning bad habits is not a good "learning purpose".
Besides, small projects have a habit of becoming big projects, and then you're stuck with the mistakes you made at the outset.
My advice is to use good practices always.


@ Bear
Yes I am completely agree with you..
Ranveer K Kumar
Ranch Hand

Joined: Sep 13, 2009
Posts: 64
Aman Singh wrote:Thanks for the help folks

Ranveer now its making sense to me :-) sorry for acting so dumb.

But this dynamic value would be the same for complete row right?


It depends on requirement. But as every column has unique data so you can implement this on column base..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: need help with a logic
 
Similar Threads
Need to cleat the doubt about websphre Profile,Cell,Node and Servers
cell model and table display
Map text file to a 2 dimensional array.
JTextArea in JTable
DataGrid: update cell without refreshing page