You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Mike Kienenberger <mk...@gmail.com> on 2011/02/19 00:01:43 UTC
Failure to refocus on a field after a richfaces IE ajax submit
I realize that this is a little off-topic, but I don't have any more
ideas on debugging or solving it.
I have a form with an input text (with an a4j:support to submit on
blur), a backup button (change number) with an a4j:support to submit
on click, and a second button (add) with another a4j:support to submit
on click.
When the second button is clicked, after the ajax submit, the focus
needs to go back to the input text field.
oncomplete="#{rich:element('newNumberInput')}.focus() "
That works fine in Firefox. The inputText gets focus.
In Internet Explorer (6, 7, 8), the first button is semi-highlighted
(but not focused), leaving the page with no component focused.
Obviously an ie bug, but any ideas on a workaround?
I'm posting a simplified example which demonstrates the problem,
although the problem seems clear enough.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<body>
<!-- Text above this line is ignored -->
<ui:composition
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:jstl="http://java.sun.com/jsp/jstl/functions"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich">
<ui:param name="page" value="#{testBeanRefocusAfterAjaxSubmitBean}"/>
<h:form id="myForm">
<h:panelGroup id="entirePage">
<a4j:region id="changeNumberForm">
<h:inputText id="newNumberInput"
required="true"
value="#{page.newNumber}">
<a4j:support id="newNumberInputA4J"
event="onblur"
onsubmit="if (#{rich:element('newNumberInput')}.value == '')
return false"
actionListener="#{page.changeNumber}"
disableDefault="true"
/>
</h:inputText>
<h:commandButton id="changeNumberButton"
tabindex="-1"
value="Change Number">
<a4j:support id="changeNumberButtonA4J"
event="onclick"
actionListener="#{page.changeNumber}"
disableDefault="true"
/>
</h:commandButton>
</a4j:region>
<h:commandButton id="addButton"
value="Add">
<a4j:support id="addButtonA4J"
event="onclick"
oncomplete="#{rich:element('newNumberInput')}.focus() "
actionListener="#{page.add}"
disableDefault="true"
reRender="entirePage" />
</h:commandButton>
</h:panelGroup>
</h:form>
</ui:composition>
<!-- Text below this line is ignored -->
</body>
</html>
import javax.faces.event.ActionEvent;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class TestBeanRefocusAfterAjaxSubmit {
protected static final Log log =
LogFactory.getLog(TestBeanRefocusAfterAjaxSubmit.class);
transient private String newNumber;
public String getNewNumber() {
return newNumber;
}
public void setNewNumber(String newNumber) {
this.newNumber = newNumber;
}
// ActionListeners
public void changeNumber(ActionEvent event) {
log.info("changeNumber");
}
public void add(ActionEvent event) {
log.info("add");
}
}