This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JSP and the fly likes JSP column name hyperlink help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "JSP column name hyperlink help" Watch "JSP column name hyperlink help" New topic
Author

JSP column name hyperlink help

Benjamin Calderon
Greenhorn

Joined: Aug 09, 2011
Posts: 10
i have a question. i need to figure out how to make all fields called ord_ID in a table hyperlinks to a different JSP page with the value of the ord_ID as a parameter as a query string(value) to the receiving JSP page. this is what i have so far:


this code does not work with the hyper link, how can i change it?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Since you're already using JSTL, it will be easier to use the <c:url> element to set up a URL with parameters.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60766
    
  65

Benjamin Calderon wrote:i need to figure out how to make all fields

Fields? What elements are you referring to?

I'm also seeing some syntax errors that are sure to be holding you back (lines 30 and 34).

And yes, a to <c:url>.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Benjamin Calderon
Greenhorn

Joined: Aug 09, 2011
Posts: 10
Bear Bibeault wrote:
Benjamin Calderon wrote:i need to figure out how to make all fields

Fields? What elements are you referring to?

I'm also seeing some syntax errors that are sure to be holding you back (lines 30 and 34).

the fields i am referring to are the ORD_ID fields in the table once it goes to a we page. an i know about the syntax, that was just a sample of something that I tried to do.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60766
    
  65

Benjamin Calderon wrote:the fields i am referring to are the ORD_ID fields in the table once it goes to a we page.

There are no such elements as "fields" in HTML. Please be precise in identifying which elements you are referring to. It helps eliminate guesswork.

an i know about the syntax, that was just a sample of something that I tried to do.

Well, it needs to be fixed before we can move on.
Benjamin Calderon
Greenhorn

Joined: Aug 09, 2011
Posts: 10
Bear Bibeault wrote:
Benjamin Calderon wrote:the fields i am referring to are the ORD_ID fields in the table once it goes to a we page.

There are no such elements as "fields" in HTML. Please be precise in identifying which elements you are referring to. It helps eliminate guesswork.

an i know about the syntax, that was just a sample of something that I tried to do.

Well, it needs to be fixed before we can move on.

i dont know how to fix it, that is my main question is in that part of the code
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Don't leave half of your EL expression outside the brackets.

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60766
    
  65

Indeed -- the ${} is not some sort of "fetch" operator that is applied to variables; it encompasses the entire EL expression. This is a common misconception.
Benjamin Calderon
Greenhorn

Joined: Aug 09, 2011
Posts: 10
Paul Clapham wrote:Don't leave half of your EL expression outside the brackets.


Thnaks, i did not know that. i thought it was some sort of getVariable thing. So, i changed it to how you said and my code is now:

it does populate the table with all of the correct data, but my links for my Ord_ID fields are still not working, so basically the first <c:if> statement is not doing its job, so maybe the test is put wron?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60766
    
  65

Also be sure to "disable HTML" when posting markup.

So the <a> tag is never appearing when you think that it should? That would mean that columnName never equals "ORD_ID". Are you sure that it does as some point when you expect it to?
Benjamin Calderon
Greenhorn

Joined: Aug 09, 2011
Posts: 10
So, here is still what i have. i know that embedding SQL query directly into JSP pages is not a good idea, but ive done it so that you can see the quer that i am sending. the param.partyID is from a sepreate JSP that inputs a Member ID number in a text fields and sends it as a parameter. so, again. i need those order ID numbers to be links to a page that corresponds to them. it is the t_ord.ORD_ID that i want to be links for every one that is in the database.

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Well, I would say that if the column name was actually "t_ord.ORD_ID" then comparing to "ORD_ID" would not do what you want. But you have something which outputs the actual column names now... it would have been interesting to see what its output was.
Benjamin Calderon
Greenhorn

Joined: Aug 09, 2011
Posts: 10
Paul Clapham wrote:Well, I would say that if the column name was actually "t_ord.ORD_ID" then comparing to "ORD_ID" would not do what you want. But you have something which outputs the actual column names now... it would have been interesting to see what its output was.


the column name isnt "t_ord.ORD_ID", when i run this, it runs as i expected and creates a table with all the column headers i specified as well as all the data i wanted. and the column name is "ORD_ID". I want all of the data that is from "ORD_ID" as links.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Okay. So that's the first column, right? Then just make the first column a link. Or am I missing something that you're trying to ask now?
Benjamin Calderon
Greenhorn

Joined: Aug 09, 2011
Posts: 10
Paul Clapham wrote:Okay. So that's the first column, right? Then just make the first column a link. Or am I missing something that you're trying to ask now?


Im new to this stuff, Im an intern at a company and i was told to do something like this a practice and just to figure it out however i could including forums, google, etc. So im basically in a learning position so im not sure how to make just the first column a link. is there like a column.count thing i could use and if the count is equal to column one that it makes it a link, and if not it is made how it normally is?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Sure there is. The <c:forEach> element has a varStatus attribute which returns an object with "index", "count", "first", and "last" properties. I always have to look this sort of thing up, which is why I have the JSTL Quick Reference sitting on my desk.
Benjamin Calderon
Greenhorn

Joined: Aug 09, 2011
Posts: 10
Swet, i got it to work. I just added that varStatus to the column <c:forEach> tag and added a little more code and it finally works, thanks to everyone that helped :)
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60766
    
  65

Benjamin Calderon
Greenhorn

Joined: Aug 09, 2011
Posts: 10
Bear Bibeault wrote: :thumbup:

Just for learning purposes, is there any thing that i could improve in this code? like to make it better...any ideas are welcome :)
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60766
    
  65

Yup.

For staters, SQL in the JSP: bad, bad practice! At least you are using the JSTL SQL tags (as opposed to putting Java code in the JSP which would be so heinous as to be unmentionable! )

But even the JSTL SQL tags are not considered acceptable for real code.

Rather, database access should be safely ensconced in the model layer. Generally, the user interface should;t know anything about databases, and the model layer should't know anything about the UI.

I usually recommend novices to JSP read the following articles:
  • The Secret Life of JSPs
  • The Front Man

  • Paul Clapham
    Bartender

    Joined: Oct 14, 2005
    Posts: 18541
        
        8

    I would have used a <c:choose> rather that two <c:if> elements with similar but opposite tests. Easier for maintenance: if you have to change the test, you want to avoid having to do it in two different places.

    Also instead of

    Use booleans the way booleans are meant to be used:
     
    It is sorta covered in the JavaRanch Style Guide.
     
    subject: JSP column name hyperlink help
     
    Similar Threads
    Matching two map values : An exception occured trying to convert String "A" to type "java.lang.Long"
    Implementation of google charts in JSP
    Best choice for pagination?
    How to get Browser Variable value in side JSTL
    JSTL Problem