6159

Mixing Ajax and full requests in JSF 2.0

The JSF code which is giving me problems is the following:

<h:panelGrid columns="3"> <!-- Minimum Password Length --> <h:outputText value="#{i18n['xxx']}:" /> <h:inputText id="minLength" value="#{passwordPolicies.minLength.paramValue}" required="true"> <f:validateLongRange minimum="1"/> <f:ajax event="valueChange" render="@this minLengthMessage" listener="passwordPolicies.testListener"/> </h:inputText> <h:message id="minLengthMessage" for="minLength" errorClass="error" tooltip="true"/--> <!-- Many other validation fields --> <h:panelGrid/>

Firstly, I am having a very similar issue as: f:ajax listener never fired . I must combine Ajax and full requests on my JSF page. Jim Driscoll @ java.net says that in order for these 2 to work, an Ajax error listener must be set up? Is this very much diferent than the listener property of the ajax tag?

Now, I know I could try Primefaces p:inputText and p:ajax tags, but these would require me individual listeners for all my fields that are validated. Is there a way to fix the f:ajax error listener, in order to be triggered and dont get the nasty:

<img src="https://i.stack.imgur.com/iOl9X.png" alt="enter image description here">

Thanks for any input!

Answer1:

You need to make your command button to fire an ajax request instead.

<h:commandButton value="Submit" action="#{bean.submit}"> <f:ajax execute="@form" render="@form" /> </h:commandButton>

Those <f:ajax> listeners are not mandatory. They were just used as an example in Jim's article to illustrate the race condition. Which get invoked first? Obviously you'd like to invoke the listeners first.

A practical example of almost the same kind of form can be found in this chapter of this tutorial. Only blur is been used instead of valueChange, because the valueChange won't be invoked when you blur a required="true" field which is kept empty which causes that the "Value is required" message will never show up on such a field.

Answer2:

Just recording this here for posterity, but creating an error handler in JavaScript and then referencing it from the f:ajax tag will suppress the error alert and cause your error handler to be called with the error message instead. This behavior is described in the article by Jim Driscoll mentioned in the question but not specifically demonstrated. I've verified that it works:

function onAjaxError( error ) { console.log( error.description ); }

<f:ajax onerror="onAjaxError" ...>

Answer3:

if you want to add some monitor this is how :

<h:commandButton value="Submit" action="#{yourBean.YourAction}" render="thisIsWhereYouWantToDisplay"> <f:ajax onevent="monitor" execute="@form" render="@form" /> </h:commandButton>

Recommend

  • Using custom CSS with jQuery validation? [closed]
  • CKEDITOR validation in JQuery
  • Creating mysql table from dynamic list python
  • Django 1.8, syncdb not working, throwing a foreign key constraint error
  • While loop won't end when I tell it in JavaScript
  • Extjs, handling success or failure when doing a standard submit in a form
  • Generating random numbers directly inside a .htaccess file
  • How to replace TouchesBegan with UIGestureRecognizer
  • Fire callback when selection was made with select2 4.0, and retrieve the value of last selection
  • Counting problem C#
  • Google OAuth: can't get refresh token with authorization code
  • File extension of zlib zipped html page?
  • Change Checkbox value without raising event
  • KnockoutObservableArray with typed elements in TypeScript
  • R Split data.frame using a column that represents and on/off switch
  • IE11 throwing “SCRIPT1014: invalid character” where all other browsers work
  • Adjust width of select element according to selected option's width
  • how to avoid repetitive constructor in children
  • print() is showing quotation marks in results
  • Make VS2015 use angular-cli ng at build time in a .NET project
  • Combining SpatialPolygonsDataFrame of two neighbour countries
  • Django rest serializer Breaks when data exists
  • Spark fat jar to run multiple versions on YARN
  • Android fill_parent issue
  • Display issues when we change from one jquery mobile page to another in firefox
  • Different response to non-authenticated users and AJAX calls
  • Get object from AWS S3 as a stream
  • htaccess rewriting URLs with multiple forward slashes
  • Arrow is showed instead of the material design version hamburger icon. Why doesn't syncState in
  • ActionScript 2 vs ActionScript 3 performance
  • Display Images one by one with next and previous functionality
  • How to make Safari send if-modified-since header?
  • Web-crawler for facebook in python
  • Data Validation Drop Down Box Arrow Disappearing
  • A cron job substitute?
  • json Serialization in asp
  • Hits per day in Google Big Query
  • FormattedException instead of throw new Exception(string.Format(…)) in .NET
  • Linking SubReports Without LinkChild/LinkMaster
  • XCode 8, some methods disappeared ? ex: layoutAttributesClass() -> AnyClass