0

I have some weird problem in my app.

I need to do the following and I achieved by using ajax events

1.add a tab dynamically ( using tab change event.when we click on + tab ,it will create new tab )

<p:ajax event="tabChange" listener="#{userBookBean.onBookTabChange}" update ="booksTabview"/>

2.remove a tab (using tab close event)

<p:ajax event="tabClose" listener="#{userBookBean.onBookTabClose}" update="booksTabview" />

3.Each tab have 5 input fields( Title, Author, Publisher, Rating (good, very good, excellent, must read), and Review ) all the input fields have its own ajax blur event call to submit its value.other wise all values are clear when switch the tab.

4.tab title can update by using one of the input field ( blur event )

<p:tab id="bookTab" title="#{book.title}">
   <p:inputText value=#{book.title}">
     <p:ajax event="blur" update="bookTab">
   </p:inputText>

all above are working fine.

Except when I submit the form using commandButton, After edit those fields.Need to click twice the button first click send the ajax request with edited field value second one submit the whole form.

<p:commandButton value="Submit" actionListener="#{bookBean.submit}"  update=":booksform :breadcrumpform :successgrowl :errorgrowl :exceptionDialog" />

Is there any way to solve this problem? or what was wrong in my code?

Rajesh Sampath
  • 518
  • 3
  • 7
  • Is the `javax.faces.ViewState` parameter present in the HTTP request payload of the first submit attempt? (press F12 in browser to verify one and other) If not, then your question duplicates http://stackoverflow.com/q/11408130 – BalusC Jul 28 '15 at 21:38
  • Thanks BalusC.. I have checked the payload for first submit.here I pasted the values. javax.faces.ViewState -2334264824240230761:542619731354417806 javax.faces.behavior.event. blur javax.faces.partial.ajax true javax.faces.partial.event blur – Rajesh Sampath Jul 29 '15 at 07:11
  • possible duplicate of [ won't submit form on first click if field uses ](http://stackoverflow.com/questions/26043025/pcommandbutton-wont-submit-form-on-first-click-if-pinputtext-field-uses) – Vsevolod Golovanov Jul 29 '15 at 10:15
  • I didn't use outputPanel and Also I can't use keyup event instead of blur. because I don't want to submit the value for each key up. – Rajesh Sampath Jul 29 '15 at 10:39
  • If we put p:tabview inside the jsf template which is build by using p:layout,we can reproduce the problem.but If we use css template or table templete it will send two request (ajax and form submit) in single click. – Rajesh Sampath Jul 29 '15 at 16:22

1 Answers1

0

When we click on Command Button,It will trigger the two following event

1.mousedown 2.mouseup

If we click the button after editing ajax enabled input fields,Ajax status model dialog will appear in between these events

so second one won't reach to server.

solution :

<p:commandButton value="save" onfocus="PF('statusDialog').hide();" actionListener="#{reportInfoBean.submit}"/>

Please suggest if you have any other way

Rajesh Sampath
  • 518
  • 3
  • 7