Search code examples
jakarta-eejsf-2icefacesicefaces-2

programmatic partial submit


my form consists of following elements:

  1. icefaces text field to enter search criteria.
  2. icefaces command button (find) to make partial submit and populate a div with new list of matched users.
  3. other two icefaces text fields, when submitting whole form i need their values.

Requirement: i want when user press enter in the text input field, that find button gets clicked (when the button gets clicked by mouse it makes partial submit automatically)

so here's what i tried:

<ice:inputText id="recipient" value="#{myBean.searchValue}" size="60" 
                     onkeydown="handleEnter(event,this.form);" >
                </ice:inputText>

                <ice:commandButton id="find" value="Find"  action="#{myBean.findEmployees}" partialSubmit="true"
                     >
                    <f:ajax execute="@this" render="employees" />
                </ice:commandButton> 
  • the JS method:

    function handleEnter(event,form){
    
       if (event.keyCode == 13){
        document.getElementById(form.name+':find').click(); 
       }
    }
    
  • the generated ice command button:

     <input type="submit" value="Find" style="width: 60px;"     onfocus="setFocus(this.id);"     onclick="iceSubmitPartial(form, this, event);return false;" onblur="setFocus('');" name="myForm:find" id="myForm:find" class="iceCmdBtn findButton">
    

ISSUE: what happens is the when user press enter, find button is invoked, but whole form gets submitted, so a required validation error appears for the other two text fields.

please advise why whole form is getting submitted, and how to handle such issue.


Solution

  • to get the enter button working fine with partial submit, i have to remove the 'required=true' tag from the inputs and make the validation with JS.