How to create JSF form with AJAX data validation

后端 未结 2 1683
抹茶落季
抹茶落季 2021-01-13 19:50

I\'m working on a JSF form prototype for inserting data into database table using AJAX data validation This is the JSF page:



        
2条回答
  •  没有蜡笔的小新
    2021-01-13 20:21

    Just add listener in your tag h:inputText:

    
    

    So you can check the entered value on the server side. When a user tabs out of the input field, JSF makes an ajax-call to the server and runs the name input component through the execute portion of the life cycle. This means that JSF will invoke the name input's value-change listener specified in attribute valueChangeListener during the validations process phase of the life cycle.

    And I would suggest to implement this method:

    public void validateSessionid(ValueChangeEvent e) {
        UIInput nameInput = e.getComponent()
        String sessionid = nameInput.getValue()
    
        //do SQL query
    }
    

    After the ajax-call returns JSF renders the h:outputText id="sessionidvalidate".

提交回复
热议问题