I have a dialog which is closed with the following button:
<p:commandButton
onclick="propertyEditDialog.hide(),propertyEditDialog.loaded=false"
value="#{i18n['button.cancel']}" ajax="true"/>
There is no action, only client side javascript that simply hides the dialog. However, I've seen in the logs, that the form is validated on cancel. I've set the ajax="true" to prevent form validation, but it not helped anyway.
What is the right way to close the dialog in PrimeFaces without validating the form?
ajax="true" is the default behaviour of p:commandButton!
The right way would be to exclude the inputs of beeing processed. With the attribut process="#this" in the commandButton, only the button should be processed.
But if you dont want to fire some action and do not want to submit the form, maybe you better use a push-button (instead of a submit-button) by adding the attribute type="button" to your commandButton.
You can use attribute immediate="true" to avoid validation.
Related
https://www.primefaces.org/showcase/ui/ajax/event.xhtml
I want do that same what in showcase but without refreshing page. Like: setting value in inputtext and click on button to view result, but if i have <p:ajax event="blur" />or <p:ajax/> then i must click two times on the button
<p:inputText id="data" value="#{buttonView.data}">
<p:ajax/>
</p:inputText>
<p:commandButton value="Ajax Submit" id="ajax" actionListener="#{buttonView.buttonAction}" />
Maybe something like use outpupanel and update that panel in commandbutton?
If you are to use the <p:commandButton /> then the form will be submitted. In this case use update attribute of <p:commandButton /> to update the target component.
If you want to update another component as soon as you type then use <p:ajax event="keyup" update="your_target_component_id" /> to update your target component. (YOur event can be keyup, keypress, change, blur, etc.)
I don't understand why are you mixing the concept of using p:ajax with the functionality of the p:commandButton.
Basically, usage of p:ajax is intended to partially process the
field(s) value and update the component(s) of the form even without
submitting it.
Example:
You have Countries and States drop-downs (pre-populated) on a screen (let's say registration) with some other fields, but if user changes the country, you need to refill the States drop-down and update on the screen asynchronously. There you need to use the p:ajax.
On the other hand, p:commandButton is intended to submit the form
(not to update the components initially). However, it also supports
the updating of the components using update attribute.
Example:
Now, reconsider the above example with similar drop-downs (but disabled with fixed values). Now you know that your screen has nothing to be updated and you just have to tackle with validation (if any) and submit the form (update if required).
As far as you are concerned with using the p:ajax on the p:inputText for some asynchronously updates on the screen and p:commandButton to finally submit the form, that totally depends on your requriement.
Instead p:ajax try f:ajax. You can use < f:ajax event="change" render="#this"/>
once the value gets change, same will reflect in backing bean.
I wanted to ask just what title says:
say we have a inputtext and a button. Well, I wanted to submit an ajax request in the inputtext when button is clicked.
for example, from the inputtext perspective, I want to achive something like this:
<h:inputtext>
<a4j:support event="button.onclick"/>
<h:inputtext>
<h:button id="button">
or, from the button perspective:
<h:inputtext id="input"/>
<h:button id="button">
<a4j:support event="onclick" action="input.submit"/>
</h:button>
Don't know if there exist an easy way to get this done.
thanks in advance!!
If you just want a simple form submit, I think both approach are wrong, as long as you put your inputtext and button properly in a form, the form will automatically submit whatever you have in this form including user's input in inputtext when you click the button. There is no need to do something like input.submit yourself. (and it's not correct, either)
For the following case, you will see the setInputValue() of managed bean being invoked when you click your button.
<h:inputtext id="input" value=#{bean.inputValue}/>
public void setInputValue(String inputValue){
this.inputValue = inputValue;
}
Try using
Richfaces Region component to limit your request to diffrent regions.
http://docs.jboss.org/richfaces/latest_3_3_X/en/devguide/html/a4j_region.html
I finally get this done by means of <a4j:jsFunction>
a4j:jsFunction
I have a required input field in a p:dialog. If firstly I submit nothing for the field, a validation error happens on that field. Then I close the dialog and reopen it, the validation error still exists. What can I do to eliminate the validation error when close the dialog?
You should use the p:resetInput on the element that you have to open the dialog.
For example if you use a p:commandButton
<p:commandButton value="Open dialog" update=":dialogId" oncomplete="PF('dialogWidget').show()" >
<p:resetInput target=":dialogId" />
</p:commandButton>
This will reset the cached values (including the validation messages) upon opening the dialog.
I was able to reproduce your case and you could do the following:
Make your dialog closable="false".
Add a Cancel button that will hide the dialog.
Add a resetInput component from Primefaces Extensions inside your Cancel button. This will clear the form validations and values.
Here is an example that assumes your dialog as a widgetVar named wvDialog.
<p:commandButton value="Cancel" immediate="true" onclick="wvDialog.hide()">
<pe:resetInput for="myDialogFormId />
</p:commandButton>
You could even call a bean method in the button actionListener if you need.
I hope it helps.
Update the p:dialog or p:message every time you submit the Form.
You can do that by using update attribute of p:commandButton.
<p:commandButton update="ID_OF_DIALOG" />
Setting process="#this" inside a <p:dialog> will hit the method in managedBean but the submitted values are empty. Setting process="#form" does not hit a method. Setting process="#all" gives null values. Setting a nested form, introducing a form in a dialogue is not advisable. What do I have to specify in the process attribute?
<p:commandButton id="serachInsideDialogue" value="#{msg.AddSystem_searchLabel}" action="#{testBean.edit}" update="growl" process="#this">
<f:setPropertyActionListener target="#{testBean.searchUserId}" value="#{testBean1.searchId}" />
</p:commandButton>
You can try with some functions like that
function null() { document.getElementById("serachInsideDialogue").style.display= ""; }
and then to customize them as you want for every event.
And them to call them in your process when you want like events.
Introducing a form in a dialogue is not advisable
You have been misinformed.
The dialog must not be placed inside any form. Instead, it must be placed outside any form and in turn have its own form. You obviously don't want to process all other inputs inside the same form outside the dialog when intending to submit the inputs in the dialog.
Once you fix that, you can just use process="#form" which is already the default value and can thus safely be omitted altogether.
I have a form with a validator on one field. I have two h:commandButtons: Ok and Cancel. When I input wrong data and click Cancel, I get a validation message. What must I do that validator don't run when I click cancel?
In case you aren't using ajax, or are still on JSF 1.x, and you really need to invoke a business action in cancel() method (i.e. just reloading the page is insufficient), then your best bet is to add immediate="true" to the button. This way all input fields which don't have immediate="true" will be skipped in processing.
<h:commandButton value="Cancel" action="#{bean.cancel}" immediate="true" />
On JSF 2.x, much better is to submit the form by <f:ajax>, which by default only processes #this instead of #form.
<h:commandButton value="Cancel" action="#{bean.cancel}">
<f:ajax />
</h:commandButton>
If you want to navigate to another page here, add ?faces-redirect=true to the outcome in the cancel() method.
Or, if you actually don't need to invoke any business action at all, then just use <h:button> wherein you directly specify the (implicit) navigation case outcome.
<h:button value="Cancel" outcome="previouspage" />
This will basically reload the page by a GET request. The <h:button> doesn't exist in JSF 1.x, but you can also just use plain HTML+JS for that.
See also:
Why was "immediate" attribute added to the EditableValueHolders?
How to navigate in JSF? How to make URL reflect current page (and not previous one)
How to let validation depend on the pressed button?