jsf - Log the number of submit button clicks though the form is invalid -


i trying log number of button clicks. 1. should log number of clicks though form invalid. field value1 in form integer. so, shall consider conversion errors. 2. action done @ backing bean

i have tried listener on ajax.

<h:form id="form">       <h:inputtext id="in" name="in" value="#{listenbean.value1}" autocomplete="off">              </h:inputtext>       <h:commandbutton value="click me" action="#{listenbean.save}">             <f:ajax execute="@form" render="@form message eventcount" />       </h:commandbutton>        <h:message for="in"/>       button clicks: <h:outputtext id="eventcount" value="#{listenbean.eventcount}"/> </h:form> 

bean

public void eventcount(ajaxbehaviorevent event) {     //increment counter }  public void save() {     //save } 

issues: listener method not called when conversion errors on input field binded integer @ bean. enter value "some text". during thsi time listener not called.

version: mojaraa 2.2.8

is correct way of doing. doing mistake.

can 1 me.

the <h:outputtext value> doesn't represent method expression should reference bean (listener) method. represents value expression should reference bean property outputted (escaped) text response.

your best bet hook on prerenderview event of component , check if current request represents postback request.

<h:form id="form">     <h:commandbutton ...>         <f:ajax execute="@form" render="@form" />     </h:commandbutton>      button clicks:      <h:outputtext id="eventcount" value="#{listenbean.eventcount}">         <f:event type="prerenderview" listener="#{listenbean.incrementeventcount}" />     </h:outputtext> </h:form> 
private int eventcount;  public void incrementeventcount(componentsystemevent event) {     if (facescontext.getcurrentinstance().ispostback()) {         eventcount++;     } }  public int geteventcount() {     return eventcount; } 

note render="@form" covers entire form already, there's no need of specifying individual components inside same form. in case you've ajax action inside same form you'd not count event, make sure render="..." specific enough doesn't cover eventcount component.


Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -