开发者

JSF text field onchange submit tabbing

开发者 https://www.devze.com 2023-02-01 15:27 出处:网络
I have multiple text fields that each have onChange=\"submit();\" in order to save the data immediately. The problem I have is that tabbing to the next field won\'t work because it will submit and the

I have multiple text fields that each have onChange="submit();" in order to save the data immediately. The problem I have is that tabbing to the next field won't work because it will submit and then loses focus on the field due to the page submition. Also, if the user is to click the next text field they want to edit it will lose focus and he will have to click it a second time due to the page submition. Is there anyway to fix this so that after the 开发者_开发问答page submits it will set the focus to the intended text field?

Background:

I have a dynamic table that is being populated via these multiple fields. The user will select a value from a dropdown list and then click "New" button and then all the fields corresponding with the selected value will appear. I decided to have each text field submit onChange instead of a submit button in order to reduce the clutter on the page due to the complexity of all the input data. Plus it just seems cooler that the table and everything else gets updated automatically.

Thanks.


The problem I have is that tabbing to the next field won't work because it will submit and then loses focus on the field due to the page submition.

Yes, any time you trigger the onchange event your form is submited and when the JSF life Cycle ends your page is rendered again and you lose the focus.

It sounds to me like you have several input test and you want to rerender a table dynamically. Why you don't try another approach with ajax ? First process your input fields with ajax and then rerender your table dynamically.

Example:

<h:inputText id="input" value="#{mybean.input}" >
    <a4j:support 
        event="onchange"
        ajaxSingle="true"
        action="#{mybean.doSomething()}" 
        reRender="myTable" />
</h:inputText>
0

精彩评论

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