开发者

Focus disappears when a4j:support is used

开发者 https://www.devze.com 2023-03-25 08:12 出处:网络
I use JSF and I have 2 input texts on the page. <h:inputText id=\"xxx\" value=\"#{file.xxx}\" maxlength=\"12\" >

I use JSF and I have 2 input texts on the page.

<h:inputText id="xxx" value="#{file.xxx}" maxlength="12" >
    <a4j:support event="onchange" reRender="datePanel1" 
      onchange="validateXXX();"  
      oncomplete="process();"
        />
</h:inputText> 

<h:inputText id="yyy" value="#{file.yyy}" maxlength="12" >
    <a4j:support event="onchange" reRender="datePanel1" 
      onchange="validateYYY();"  
      oncomplete="process();"开发者_StackOverflow中文版
        />
</h:inputText> 

When any value is changed, the pair of values should be validated. If validation fails the other value for input text can be updated automatically. Oncomplete event is used for outputting status messages on the page and can not be removed. The problem is when I TAB from the first input text to the second one and the value of the second input text is changed after "validation" of the first input text, focus disappears form the second input text. How can I prevent from focus disappearing, but still using a4j:support?


Try using javascript to refocus the element on the oncomplete

e.g.

<h:inputText id="xxx" value="#{file.xxx}" maxlength="12" >
    <a4j:support event="onchange" reRender="datePanel1" 
      onchange="validateXXX();"  
      oncomplete="process();document.getElementById('xxx').focus();"
        />
</h:inputText> 

<h:inputText id="yyy" value="#{file.yyy}" maxlength="12" >
    <a4j:support event="onchange" reRender="datePanel1" 
      onchange="validateYYY();"  
      oncomplete="process();document.getElementById('yyy').focus();"
        />
</h:inputText> 

This should hopefully refocus the elements when the oncomplete handler is called.....

0

精彩评论

暂无评论...
验证码 换一张
取 消