Reputation: 17
I am developing JSF1.2 application. When user make changes in input components, such as h:selectOneMenu, the JSF “value change event” will be called. when it called page is submitting the form and the page is reloaded and the cursor is at top of the page. i want cursor stay at previous position. below is the code for h:selectOneMenu.
<h:selectOneMenu value="#{bean.value}" onchange="this.form.submit()"
valueChangeListener="#{bean.valueChangeMethod}">
<f:selectItems value="#{bean.values}" />
</h:selectOneMenu>
how can i solve it? i haven't given any scripting in XHTML file. please guide me on this.
Upvotes: 1
Views: 1904
Reputation: 1297
This flickering problem can be solved by ajax. For Ajax add the following jars to lib folder:
Add following code in web.xml file
<filter>
<display-name>Ajax4jsf Filter</display-name>
<filter-name>ajax4jsf</filter-name>
<filter-class>org.ajax4jsf.Filter</filter-class>
</filter>
<filter-mapping>
<filter-name>ajax4jsf</filter-name>
<url-pattern>*.jsf</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>
And add following line to your .jsp page:
<%@ taglib prefix="a4j" uri="https://ajax4jsf.dev.java.net/ajax"%>
Upvotes: 0
Reputation: 1845
Since you didn't specify JSF version, here's a JSF2 solution:
If you make it an AJAX call, the scroll of the page will remain the same. Here's an example:
<h:selectOneMenu value="#{bean.value}">
<f:selectItems value="#{bean.values}" />
<f:ajax listener="#{...}" render="id1 id2 id3 ..." />
</h:selectOneMenu>
id1 id2 id3 ...
are the components' ids you want to rerender after the AJAX call. You can put @all
to refresh the whole page or @form
to refresh the current form.
You can learn more about <f:ajax />
here.
Upvotes: 1
Reputation: 4584
If what you seek is to get the mouse position on page refresh, this is impossible to do.
For now anyway. you can however capture the onmousemove
event which will tell you where the cursor is on the screen and save that location, but you cannot manipulate the mouse to move on it's own.
However if there is a textfield that you want focussed you could always use JS focus();
method onpageload.
EDIT
As for the OP's general question.
This is not possible, it's browser dependand. Usually your cursor stays where it is in any normal modern browser. With older browsers or IE the behaviour will be abit different.
The reason for this not being possible is because the mouse position will be unknown on page refresh, thus you cannot relocate it even if it was possible.
Hope this helps
‐ Sid
Upvotes: 0