Anchors in DataTable

Hi all,

I did quite a bit of research on this.

I have a datatable, with a valuechange field in each row. the datable has 50 rows on the page.

So if the user enters 37th row, the valueChangeListener refreshes the page and brings it to the top of the page again.

To overcome this, i tried to set focus on the element that caused this valuechangelistener even to fire up. and i did it successfully, BUT, after the focus is set, the page keeps on refreshing for some reason.

Then i tried to defined anchors for each row using <h:outputText> and when the page loads i am

using :

<script>

function setFocus(){

var fieldname ="";

fieldname ="form2:payments:23:dYear";// this is just to test the anchor.

document.location.href="#"+fieldname;

}

setFocus();

</script>

again, this works, i am able to set focus on to that row, but again it refreshes the page and brings it to the top.

any ideas?

[1169 byte] By [Seshu_Varanasia] at [2007-11-26 17:48:31]
# 1

Nothing works.

I tried in all possible ways. the entire HTML of the JSP looks fine.

[code]

<a name='f23'></a>

<script>

function setFocus(){

var fieldname = "";

fieldname = "f23"; // this is just to test the anchor.

document.location.href="#"+fieldname;

}

setFocus();

</script>

It takes me to that row, but then again goes back to the top of the page. this thing is eating me.

Seshu_Varanasia at 2007-7-9 5:00:53 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
Does anyone has some idea why is it doing that way?
Seshu_Varanasia at 2007-7-9 5:00:53 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
Is this script called at the end of the HTML? Right next before the closing body tag.Otherwise you might try to add a setTimeout() with 100ms or so.
BalusCa at 2007-7-9 5:00:53 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
Yes BalusC,Whatever i do, it goes to that anchor for a bit and then again comes back to the top of the page.this is driving me nuts.
Seshu_Varanasia at 2007-7-9 5:00:53 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
Doesn't setTimeout() work then?
BalusCa at 2007-7-9 5:00:54 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
Nope.As i told you, even without the timeout, the page goes to that row and immediately coms back to the top.
Seshu_Varanasia at 2007-7-9 5:00:54 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7
Did you face this situation anytime?this is a must required feature for us now. i have experimented quite a few things. all in vain
Seshu_Varanasia at 2007-7-9 5:00:54 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8

> even without the timeout

No .. You have to try to use it with setTimeout().

<f:verbatim>

<script>

setTimeout("setFocusAnchor()", 100);

</script>

</f:verbatim>

</body>

Just give the page some time to finish rendering. Try 100ms, 50ms or even 10ms.

BalusCa at 2007-7-9 5:00:54 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 9

Ok.

i tried even with 500ms.no luck. were you able to go to the anchor successfully?

let me show you what i did.

i defined anchor using <h:outputText>

and it shows up in the end html as :

<span id="form2:emps:23:anchor"><a name='f23'></a></span>

and in the setFocus function:

function setFocus(){

location.href="#"+fieldname;

}

and i used what you gave me:

</TABLE>

<f:verbatim>

<script>

setTimeout("setFocus()", 500);

</script>

</f:verbatim>

</BODY>

am i doing anything wrong here?

the anchor i showed you was for one particular row.

Seshu_Varanasia at 2007-7-9 5:00:54 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 10

function setFocus()

{

location.href="#" + fieldname;

}

<script>setTimeout("setFocus()", 500);</script>

The parameter fieldname is missing. Try

function setFocus(fieldname)

{

location.href="#" + fieldname;

}

<script>setTimeout('setFocus(\'nameofmyancor\')', 500);</script>

(I didn't investigate your problem, have never used DataTable and don't know, if this is the solution. I saw just the missing parameter.)

You probably have to create the script dynamically due to the needed name of the ancor.

In javascript the parameter can be omitted in the signature of the function but it must be passed through the call.

Ingmara at 2007-7-9 5:00:54 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 11
Oops...that was a typo...the actual code is:function setFocus(){location.href="# f23";}
Seshu_Varanasia at 2007-7-9 5:00:54 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 12
function setFocus(){location.href="#f23";}
Seshu_Varanasia at 2007-7-9 5:00:54 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 13
any more ideas?
Seshu_Varanasia at 2007-7-9 5:00:54 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 14
Hi guys,BalusC, you were right. I set the timeout value to 1500 and it worked. Sorry i did not try it before..
Seshu_Varanasia at 2007-7-9 5:00:54 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...