I have a h:inputText which has an onBlur event which rerender a panelGroup with a4j:repeat which will have number of h:inputText entered in the first inputText. The inputText fields are geting created but the focus is not on the first field in the a4j:repet because the focus is been set before the panelGroup is been re-rendered once the rerender happen the focus is lost.
XHTML code
<a4j:outputPanel id="PageARoot">
<a4j:keepAlive beanName="simpleBean" />
<h:outputText value="Infants:" />
<h:inputText id="text" value="#{simpleBean.size}">
<a4j:support event="onblur" action="#{simpleBean.action}"
reRender="MyContent" />
</h:inputText>
<h:panelGroup id="MyContent">
<a4j:repeat id="list" value="#{simpleBean.list}" var="item" rowKeyVar="rowIndex">
<h:inputText name="test#{rowIndex}" id="test" value="#{rowIndex}" />
</a4j:repeat>
</h:panelGroup>
</a4j:outputPanel>
Bean
public class SimpleStringBean {
private List list;
public List getList() {
return list;
}
public void setList(List list) {
this.list = list;
}
private int size;
public int getSize() {
return size;
}
public void setSize(int size) {
this.size = size;
}
@PostConstruct
public void initialize(){
System.out.println("Initalize");
list = new ArrayList();
list.add(new Long(0));
size = 1;
}
private String text;
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public void action(){
System.out.println("Action: " + text);
list = new ArrayList();
for(int i = 0; i < size; i++){
list.add(new Integer(0));
}
}
}
there's a focus attribute on the a4j:support component. It takes the id of the element to set focus to after the request is completed. So if you know what the id of the input text is going to be you can set it here