• Post Reply Bookmark Topic Watch Topic
  • New Topic

Included JSP always at top of the page  RSS feed

 
Richard Le
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good night!

I have a problem including a jsp inside another jsp. I have a jsp with some fields and i'm trying to include it inside another one using ajax.
This is the code of my main jsp:


When the "jobId" select changes, the "jspToChange" is updated with the following function:



The problem is that when the "jobId" select changes, the included jsp displays at the top of the page and not in the position where the "jspToChange" div is.

I hope that you understand my question.
Thanks in advance for your help.






 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66148
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are you returning as the response? A full HTML page? If so, don't. It should just be a fragment.

Also, why a POST?
 
Richard Le
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bear!

Thank you for your response. What I'm returning is a JSP which has some textfields. I've used that function before and it worked; however, the difference was that i used a table to separate all the elements. For example:



Then, when i called the ajax function the jsp was updated where the div tag ("jspToChange") was and everything was perfect. However, now that i'm not using this table, when i call the ajax function, the jsp always appears at the top of the page and not where the div is (after the "select"). The thing is that i think that using this table is not good at all because i should use css instead. What i tried was using css and setting the "jspTochange" position to absolute, but it didn work.

Any suggestions?
Thanks.

 
Richard Le
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to show you my problem to see if you can help me.

What i have is this:



The red square is the jsp that i need to update, and the blue one is my main jsp (it has a menu, a submenu and some images). If I use a table to separate the elements, when the select value changes this is what happens:



As you can see, it is updated correctly. But, as I said before, I think that using a table is not correct. Then, if I don use a table i get this:



As you can see, whitout the table, it doesn't update the JSP in the correct way. Is there a different method to do this?
Thanks in advance.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66148
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use the debugger in the browser to inspect the DOM. It will show you where the elements actually are in the structure. When not using the table, what do you return?
 
Richard Le
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi bear!

I used the debugger and i noticed that when the "select" changes, a new table with the updated elements is created, and it's placed at the top, not inside the div tag. But, if I use the table, when the "select" changes, the new table with the updated elements is placed inside the div tag. I return the same JSP in both cases, the only difference is that I use the table to separate the elements in the example that works correctly. The thing is that i don't like using this table, i'd prefer to solve my problem using css.

Is there a way to do what I want without using this table?
Thanks in advance!
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66148
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:When not using the table, what do you return?
 
Paul Clapham
Sheriff
Posts: 22374
42
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps I'm missing something, but what I see is this:

You start with a div whose id is "jspToChange". Then you execute an AJAX request which replaces that div with something else -- maybe a table, maybe something which isn't a table but we don't know what it is. But at any rate now you don't have anything in your DOM whose id is "jspToChange", so the next time you execute that AJAX request its result would be put into some default location. That could be at the start of the page, I suppose, I don't remember what happens when you use a nonexistent id value there.
 
Richard Le
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bear!

In both cases a return a JSP which is like this:



It has some other textfields, but in both cases it's the same JSP. The problem seems to be in the main JSP.
Thanks!
 
Richard Le
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:Perhaps I'm missing something, but what I see is this:

You start with a div whose id is "jspToChange". Then you execute an AJAX request which replaces that div with something else -- maybe a table, maybe something which isn't a table but we don't know what it is. But at any rate now you don't have anything in your DOM whose id is "jspToChange", so the next time you execute that AJAX request its result would be put into some default location. That could be at the start of the page, I suppose, I don't remember what happens when you use a nonexistent id value there.


Yes, you are right. Actually, it puts the result JSP inside a table ("wwformtable"). What i don't understand is why if I use a table to separate the elements in the main JSP it works correctly?
Thanks!
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66148
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Richard Le wrote:Hi Bear!

In both cases a return a JSP which is like this:




The JSP gets returned unprocessed? Or is that actually not what's being returned?
 
Richard Le
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
These are the details of what I'm returning:

First, the ajax request:



And this is part of my struts configuration file. As you can see, what I do in the ajax request is to call this action to update the JSP that is inside the "jspToChange" div.



Thanks!
 
Dave Tolls
Ranch Hand
Posts: 2835
30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:Perhaps I'm missing something, but what I see is this:

You start with a div whose id is "jspToChange". Then you execute an AJAX request which replaces that div with something else -- maybe a table, maybe something which isn't a table but we don't know what it is. But at any rate now you don't have anything in your DOM whose id is "jspToChange", so the next time you execute that AJAX request its result would be put into some default location. That could be at the start of the page, I suppose, I don't remember what happens when you use a nonexistent id value there.


The html(<some html>) JQuery method replaces the html content of the matched element(s), not the matched element itself.
Here's the api page.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!