Further continuation of pressing command button twice - ajax

Referencing this question because the problem is identical to mine, but I don't think the solution is usable in my situation.
continuation of pressing button twice
I have a workflow with a series of forms that need to be filled out and submitted, and I would like to display a modal overlay after the user clicks the "next" button. In order to show this overlay, I need to make the command button use ajax. This leads to the undesired behavior as described in the linked issue.
The solution for the linked issue seemed to be "don't use Ajax for navigation", but I think in my case I may have to in order to show this waiting dialogue. Is there any other way to guarantee that the view state on the following page will be updated correctly, so that when I continue navigating I do not need to hit the button twice?
I am using Primefaces 3.3.1.
<p:commandButton id="nextCommand" value="Next"
action="#{backingBean.processInputAndDetermineOutcome}"
onclick="waiter.show();" oncomplete="waiter.hide();">
<f:param name="validate" value="true" />
</p:commandButton>
The "validate" param is a flag I am using in a custom BeanValidator so that my "Back" button can submit the form and update the model without processing any of the valdations. I don't think that should have any impact on this question, but I thought I should mention what other pieces are involved in this commandButton.

Your best bet is to navigate with a redirect.
public String processInputAndDetermineOutcome() {
// ...
return outcome + "?faces-redirect=true";
}
Otherwise, for sure if you're actually observing the problem in IE browser only and not in other, more sane, browsers, then you may want to try the PrimeFaces-specific JavaScript fix as proposed here: JSF Language switcher and ajax update.
Or, if you're actually observing the problem in <f:ajax> and not in <p:ajax>, then try the JSF-specific JavaScript fix as proposed here: h:commandButton/h:commandLink does not work on first click, works only on second click.

Related

Kendo UI TabStrip e.preventDefault() doesn't work

Two problems:
1.)
e.preventDefault() doesn't work correctly with Kendo UI TabStrip when somewhere
$("#tabstrip").kendoTabStrip().data('kendoTabStrip');
appears.
2.)
Imagine the User clicks on another tab, but has unsaved changes.
A dialog pops up and ask if he wants to discard the changes and go to the tab or
if he wants to stay on the active tab to save his changes.
My solution doesn't work. Because of the 1. Problem I guess and because
.data() somehow reinitialises the TabStrip?! What is wrong?
Here is a (not) working example
http://jsfiddle.net/Nakkvarr/w9586/
Any ideas on this issue?
The reason it doesn't work for the first tab is because you initialized the tab strip twice on the same element $('#tabstrip'). Since you bound the select event on the first initialization, the subsequent initialization overwrote it (the select event isn't handled anymore). You even answered the problem yourself by stating that it works if you comment the second initialization line out.
I'm not entirely sure what you're trying to accomplish with the setTimeout() function in the second example. It's unnecessary.
Using e.preventDefault() works as expected. JSFiddle: http://jsfiddle.net/w9586/6/

f:ajax render becomes slower and slower

I have a performance issue with my JSF page and can not find an solution. I'm using JSF 2.0.
I click on an element to render another element :
<f:ajax event="click" listener="#{row.select}" render=":dataWrapper"/>
After click the data panel will be rendered. My problem is when I click on the element again. The data panel will be rendered too, but it will takes more time. If I click the third time the rendering needs again more time. And so on ...
What can be the reason for this?
I checked the request with the Firefox debugger and everything looks fine, except the reponse time.
The response time will grow up every request.

AjaxFormValidatingBehavior Performance and Lost focus on Firefox

My project is using Wicket's AjaxFormValidatingBehavior to auto-save form content to Session on sort of a multi-tab form with a tree menu (there is no save button on individual tabs, though there is a "Save" button that actually submits the form, runs the validations and saves contents to database). I am facing few issues:
Since the behavior is added to all form components' onChange event, there is a server-trip every time user moves from one field to another. I know that a throttle duration can be specified to prevent this, but its not possible to set in my case as my forms are of different lengths/complexity, many components dynamically generated (including the tree menu). But is there a more elegant solution to auto-save form content (that doesn't have a submit button) rather than this annoying solution.
Another issue I am facing is that post onChange event, on Firefox the component loses its focus after the "server trip" ends. While on IE7 it works fine.
For the first question I think you need to add a pipelining facility, on your components' onchange call a javascript function of your which calls your webapp. You can include a feature similar to the one provided with the throttle duration but page-wide (delay each calls and only trigger the last if it is older than x milliseconds for example).
For the second one, I think you have to use the AjaxRequestTarget#focusComponent in your behaviors, or handle this thing in your "wrapper" as described in the first answer.

JSF 2.0 values not being submitted

I’m struggling to get my bean to update with the new page values. I have two submit buttons on my page and I toggle which one displays based on a Boolean value for what mode my page is in. When my page is in update only (no validation) I show the submit button that has immediate=”true”. When the page is in process mode (validate) I show the submit button that does not have immediate=”true”.
The problem I’m running into is when I am in update mode (no validation) the values in the input fields are not being set in the bean. All I want to do when in this mode is save the page as is and exit. No validation is needed because the information on that page is not ready to process or “really use” if you will. That said, if I have my page in process mode (validate) then everything works as intended. Values are submitted and saved.
I’m not posting any code yet as there is nothing special about what I’m trying to do. I simply have a value binding that points to simple getter / setter. My bean is in #ViewScope.
I’ve tried using the examples by BalusC in his excellent blogspot post: debug-jsf-lifecycle.
Putting immediate=”true” on the input fields has no affect when clicking on the submit button with immediate="true". All and all though, the way I understand it is immediate=”true” on the UICommand is what tells the application to skip validation or not. Putting it on the input fields simply makes validation happen sooner. Am I missing something?
Any ideas? Any and all help with this is most appreciated!
App specifics:
JSF 2.0.3
Tomcat 6.0.14
The immediate="true" is not intented to disable validation. It's intented to either prioritize validation or to skip processing of the input altogether. See also the summary at the bottom of the article.
You need to disable validation by setting required="false", or <f:validator disabled="true">. Here's an example which assumes that you've a boolean process property which represents the form's state:
<h:inputText value="#{bean.value1}" required="#{bean.process}" />
<h:inputText value="#{bean.value2}" required="#{bean.process}">
<f:validator validatorId="someValidatorId" disabled="#{!bean.process}" />
</h:inputText>
...
This way the fields aren't required and won't be validated when process evaluates false.

Custom "Next" Buttons for Spring MVC AbstractWizardFormController

Currently, a spring application I am working on has several wizards that it is using with Spring's AbstractWizardFormController. During the early stages of development(pre-design phase), the type of "next" button did not matter.
Just to refresh, the Next and Back button are submit buttons with target attributes. So a next button on the first page of a wizard would look like the following.
<input type="submit" name="_target1" value="Next"/>
This is the standard way Spring does wizards on the view. This works fine, given that you want your Next button to be a standard HTML submit button. Otherwise, in my case, If I want a custom button, I am not sure how to do this. I know it is possible, but haven't found any documentation.
I imagine I will need to do a javascript submit, but I am not sure how to set the name of the button, of if something else needs to be done.
I just need to know how I can still extend AbstractWizardFormController, and use custom buttons.
When clicked, HTML submit button submits a form with additional parameter {name}={value}, that is _target1=Next. I guess the value doesn't matter here, controller looks at the name. So, if you want to emulate this with Javascript, you may, for example, dynamically add a hidden field with name = "_target1" before submit.

Resources