wood burning stoves 2.0*
The moose likes HTML, CSS and JavaScript and the fly likes JQuery table manipulation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "JQuery table manipulation" Watch "JQuery table manipulation" New topic
Author

JQuery table manipulation

Brandon Potter
Greenhorn

Joined: Jul 22, 2011
Posts: 14
Hi,

I am working on a program, where I have a table in my webpage, which will be autofilled. More specifically, what I want to do, is input a value, and then have the user click a button to check the name against the database, and if it is in there, return a table of filled fields if not, return an empty table to be filled in.

I have the verification code done, however my problem is getting the table to load from the other page in an ajax style (ie no refresh)

here is what I have, could you guys lemme know what I might be doing? thanks.
Tarun Bolla
Ranch Hand

Joined: Jun 20, 2011
Posts: 89
Brandon Potter wrote: $("#entityTable").load("validateEntity.jsp?name=" + value + " #entityTable");

That name parameter you are sending to the jsp has a space in it...I think it might be the culprit. Dont use spaces in params..you can send that as a different parameter... and see how you can encode your url...
Brandon Potter
Greenhorn

Joined: Jul 22, 2011
Posts: 14
http://api.jquery.com/load

loading fragments section

The space is there on purpose.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60774
    
  65

You haven't explicitly specified what the problem is. Also, please UseCodeTags to preserve the formatting of the code -- hard to read unformatted code.

One thing I do see is that the remove() before the load() is going to trip you up. You're removing the very thing you want to reference next. Oops.

If your response is returning a table, you should be loading into a <div> (or other container), that will house the table, not the table itself.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Brandon Potter
Greenhorn

Joined: Jul 22, 2011
Posts: 14
What I am looking to do is this:

I have a jsp page with a table.

I have a button on the page that when the user clicks check, I want the computer to do an ajax style update to that table and then from a different page, load up another (identically named table) which may or may not contain data (if data is found etc) . The reason I have the remove code there is so that if someone hits check twice in the same session, it wont merely append a second copy of the table, but will instead remove the orignal, and then add in the new.

At this point, I am having the table removed, however it is not loading up the table from the other page.


Xen
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60774
    
  65

I'm not sure what you mean by "other page"? Is it the "page" that is generated by the Ajax response? if so, why generate the full page? Why not just generate the table itself as an HTML fragment?

And as I already pointed out, the remove() is a problem. It is removing the very thing you are referencing next. It's like removing the manhole cover and then being surprised when you fall into the manhole.

The remove() is not necessary if you use load() correctly..
Brandon Potter
Greenhorn

Joined: Jul 22, 2011
Posts: 14
Brandon Potter
Greenhorn

Joined: Jul 22, 2011
Posts: 14
That is the page that is generating the code fragment.
Brandon Potter
Greenhorn

Joined: Jul 22, 2011
Posts: 14
THANKS A TON!!!


so the load command overwrite the code fragment I am looking for! it does not append it in!

THANKS A TON GUYS!!!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60774
    
  65

oi! (so many problems with that JSP)

But again, stepping back a moment, why generate a whole page just to get a table? I'd just have a JSP (one written using modern standards) that just generates the table. The rest is noise.

Brandon Potter
Greenhorn

Joined: Jul 22, 2011
Posts: 14
Feel free to let me know any problems you can see, this is a very rough just get the ideas down and running then code clean after draft.
Brandon Potter
Greenhorn

Joined: Jul 22, 2011
Posts: 14
And for the record, once I get some of the other pages done, and used as examples to our internal client their will be alot of cleaning in that code done, got a list of some of it, but I just copied a bunch of code from my old school work and from there updated it to make it work for now.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60774
    
  65

Problems I see right off the bat:
  • Java scriptlets in a JSP. Considered a poor practice for almost 10 years now.
  • Doing DB access in the view. Horrible, horrible practice.
  • Usin out.print to emit HTML built up in strings. The whole purpose of JSP is to avoid horribleness like that.


  • I could go on, but those problems are egregious enough for the moment.

    Brandon Potter
    Greenhorn

    Joined: Jul 22, 2011
    Posts: 14
    The DB access in the view I know is a horrible thing, threw it in just to test the page, got a proper back end login for it that will be applied when I finish the page (just my way of working from the way I was taught, bad I know).

    I am obviously still new to this, building a basic interface for a database for someone, however, if it would be possible I would be very appreciative if you were to expound on the comment "Java scriptlets in a JSP. Considered a poor practice for almost 10 years now." I was taught this way at school, and since I am self learning alot more since, and constructive ctritcism is always welcome.

    Thanks
    Paul Clapham
    Bartender

    Joined: Oct 14, 2005
    Posts: 18541
        
        8

    There's also the error of building up an SQL query with string concatenation, which leaves you open to SQL injection attacks even after you manage to get your quotes right. Use PreparedStatement instead.

    And I'm wondering (after hacking through the maze of extra quotes and backslashes necessary to output this data via Java instead of JSP) why the "eStateRow" ID is associated with the row titled "City" if there's data and the row titled "Province/State" if there isn't data.

    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 60774
        
      65

    Java scriptlets have been discredited since 2002 when JSP 2 introduced the EL into core JSP. SInce then, scriptlets are out and JSTL and EL are in.

    You might find this article this article helpful.
    Brandon Potter
    Greenhorn

    Joined: Jul 22, 2011
    Posts: 14
    @ paul the ID there was from something old that I had been trying with AJAX that has henceforth been edited out.
    The string concatenation is definitely a possible worry, however since I new to prepared statements still, and this is an internal only database, which is to be passed along to a higher power and remade from mySQL into an Oracle database to meet the workplaces standards ( client needs a roughed in version working yesterday, since this project got dropped by someone and not picked up and it is mandatory to his research) so until the "proper" db is built and designed I have about 3 weeks to build a hacked together one for him to use in the meantime. I am using this as a learning experience.

    @ Bear - that article is REALLY helpful, as I am new to web programming with my only experience from school where my proff obviously taught us outdated methods, such articles as that are GREAT.
     
    Don't get me started about those stupid light bulbs.
     
    subject: JQuery table manipulation
     
    Similar Threads
    Requested Resource Not Found Error
    <jsp:setProperty> sets null values in the bean
    jsp insert program not working
    hide email and password on contactus jsp
    values undefined in arrays