• 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

JQuery table manipulation

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

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
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://api.jquery.com/load

loading fragments section

The space is there on purpose.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Brandon Potter
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Brandon Potter
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That is the page that is generating the code fragment.
 
Brandon Potter
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
    Posts: 14
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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
     
    Marshal
    Posts: 28193
    95
    Eclipse IDE Firefox Browser MySQL Database
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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
    Sheriff
    Posts: 67746
    173
    Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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
    Posts: 14
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    @ 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.
    reply
      Bookmark Topic Watch Topic
    • New Topic