Skip form validation on command button - jsf

I have a JSF page that includes a tree form tag which is rendered depending on some bean property. There are two buttons for next and previous page. I want to skip form validation on the button which goes to the previous page.
I tried the following ways to disable the validation:
Set h:commandButton immediate="true"
Change button by a4j:commandButton ajaxSingle="true" rerender="someparts"
It does not work. Why does the navigation fail when I want to skip validation?

immediate="true" does skip the validation. Make sure you have redeployed successfully, and the there aren't any errors.

I solve problem using a4j:commandButton ajaxSingle="true" reRender=":outhercomponent:formconteningcomponent:component"
reRender needs absolute path to component even if component id unique

Related

Bean value is getting set on click of a cancel button in JSF, How to avoid this? [duplicate]

I have a JSF/PrimeFaces form page set up to edit some configuration details. At the bottom are Submit and Cancel buttons implemented as CommandButton. The Cancel button looks like this:
<p:commandButton
action="priorPage.xhtml?faces-redirect=true"
value="Cancel" />
The problem is that the view bean still winds up doing more processing on the data that's been entered into the form than I'd like. It isn't updating anything in the database, but if (say) I enter a string into a field that's looking for a numeric in the bean, it still produces errors.
Part of my solution is, of course, to get the bean to gracefully handle that sort of bad data, and I'm working on it. But I'd also like to tweak that button so that it just takes the user to the prior page. Is there some attribute I can set that will prevent the form from being processed at all?
The <p:commandButton> submits the form. You don't want to submit the form. You should then not use the <p:commandButton>, but just <p:button>.
<p:button value="Cancel" outcome="priorPage.xhtml" />
See also:
Difference between h:button and h:commandButton

jsf commandLink doesn't invoke backing bean method in first click

i have a button in my form with following code :
<p:commandButton value="#{msgs['message.report.button.search.show']}"
icon="ui-icon-image" id="searchBtn"
process="#this"
actionListener="#{sixteenFormController.search()}"
update=":assetListForm">
</p:commandButton>
when i click on the button first time it dosen't call backing bean method. but in the next time it work correct. i check request header in each time. request header for first click was :
assetListForm_SUBMIT=1
javax.faces.partial.ajax=true
javax.faces.partial.execute=searchBtn
javax.faces.partial.render=assetListForm
javax.faces.source=searchBtn
searchBtn=searchBtn
and for second click :
assetListForm_SUBMIT=1
javax.faces.ViewState=5LLh2g4iknGg3jt6KJ36nXF8zkcaHWvjQA7VyP8TZwTyqsEL3Ftbch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K95pxIqzDUUNTvTAvOV1+31l4ewi9GuIzHklP9517pUVZm4lEETcXzORxoda+MxO09gTsaDTX+MU0Id7Xyv2KGXIcsHopR8J+WjiaZOjhXp4ENZ2PfqG3KMKiz3YHE2GGpnTPekcAVWN/L1LJePovVtvnyUcwtren9gLGx4PacFsJ12mbgfRDdfdJv4/FbcCgjRU3HJDJxaPQb2W/fuPvNEX7hNH4dOxiCh2SPwHuFOYqD25yoFRyzwW4HKgv+FmJUFcPzhdozRCvydzVvAbBBexFRuQt8xaSKs+iKpa6HgFox6f5El+IAeXCGfqtwppCtvbYC39px0L2i2NCAsdP/nzjc8UFnwyzZkjsdYxTwvIEtg+LsI02MX0DUwFQA/z547LsR+RAPftr3HlIufVYIoD7tCUoNKWeIl1J7+zBZ6TAiCivKjIewhzvWnbqXH8YP+9bEEMn7WJMBN7uGbJBjMuZouNzDoWdyh/dPpLl7lpGGA3SnHOuJ6ah0oORZTVtwvynNeV2NorBrKU4vSFWV3mCjQf2hg/rw93Uon448iSnZFxuiVc5o9rafGa98TcMNyrd31R4YQR9PACykMo+o4wDiAEU9sWBcJoii4sS3PGr3izWJS7hzKf07nFup0QBp2XJo+V1JhK9XJtCuOl1tUdJtCyn3jBrIj72CT/Uh0RqoIFnzyEHDKBCFZvkUxeBiQafUfiGb3yXZY5+cEH4T4KtoZYUdYyDxJLl2hlQUzSTH9Qcyx7Mq6P3SI2hEbr1YKXZdNTvx/Ay93PSlBqU9t9PzV+x75uUWq8bVfvXdYoAi11v2RddzU//Wwnj01nx6YoFrUUGs/Z0Va7NJuNEsKwQ==
javax.faces.partial.ajax=true
javax.faces.partial.execute=searchBtn
javax.faces.partial.render=assetListForm
javax.faces.source=searchBtn
searchBtn=searchBtn
do you know reason of this behaviour?
thanks.
It can be related with the issue https://java.net/jira/browse/JAVASERVERFACES_SPEC_PUBLIC-790. Look how fix this issuse, for example, in the link: how to fixe twice needed click inside JSF page?

PrimeFaces CommandButton that Doesn't Process Data

I have a JSF/PrimeFaces form page set up to edit some configuration details. At the bottom are Submit and Cancel buttons implemented as CommandButton. The Cancel button looks like this:
<p:commandButton
action="priorPage.xhtml?faces-redirect=true"
value="Cancel" />
The problem is that the view bean still winds up doing more processing on the data that's been entered into the form than I'd like. It isn't updating anything in the database, but if (say) I enter a string into a field that's looking for a numeric in the bean, it still produces errors.
Part of my solution is, of course, to get the bean to gracefully handle that sort of bad data, and I'm working on it. But I'd also like to tweak that button so that it just takes the user to the prior page. Is there some attribute I can set that will prevent the form from being processed at all?
The <p:commandButton> submits the form. You don't want to submit the form. You should then not use the <p:commandButton>, but just <p:button>.
<p:button value="Cancel" outcome="priorPage.xhtml" />
See also:
Difference between h:button and h:commandButton

A way to easily check if an element was rendered in jsf2

I have a button that is supposed to close a modal panel and render several elements.
Is there an easy way to check if an element was rendered after the button was pressed?
example button:
<a4j:commandButton onclick="#{rich:component('modal')}.hide();"
style="background-repeat:no-repeat;width:18px;height:18px;"
image="includes/images/close.gif"
render=":id1 :id2">
<f:setPropertyActionListener target="#{Controller.attribute}" value="false" />
</a4j:commandButton>
I have another button that does not "work" on the un-rendered div.
The conditon of the rendered attribute of all of the button's parent components must be preserved when you're submitting the form. So it should not only evaluate true during the request of presenting the form with the button, but it should also evaluate true during the request of processing the form submit. Easiest is to put the backing bean in the view scope by #ViewScoped.
Also, if you're re-rendering a component which in turn contains a <h:form>, you need to explicitly add the client ID of that <h:form> to the render attribute. E.g. when component with client ID id1 has in turn a <h:form id="formOfId1">.
render=":id1 :id2 :formOfId1"
You can debug this all by just exploring the HTTP traffic in the webbrowser's developer toolset (press F12 in Chrome/IE9/Firebug and check the "Network" section).
See also:
commandButton/commandLink/ajax action/listener method not invoked or input value not updated - Points 5 and 7.
I have hit the same problem. My solution was to display the current time inside the element that i want to be rendered.
If, for instance, you want to render a panel, just paste inside that panel the following snippet:
<h:outputText value="#{session.lastAccessedTime}">
<f:convertDateTime pattern="yyyy-MM-dd HH:mm:ss.SSS" type="date" />
</h:outputText>
If the time is updated after button click, then obviously the component was rendered. But is the opposite also true? If the time is not updated, does this mean the component was not rendered? What if the component got rendered properly, but the time displayed is frozen to the moment the page was first accessed? I had small doubts about that, so i refreshed the page, and the time changed. So the time displayed is not frozen to the initial moment.
Also note that there are multiple ways to get the time; if you don't like to use session time, you could set a property in the backing bean, and initialize it to new Date()

have to press command button twice

I'm working on building a web page and notice now that I have to press the command button twice. Any command button has the same problem, so I figured I would add and action listener on one of them to see if I could see something.
<h:form id="formP">
<p:commandButton id="temp" value="photos" actionListener="#{viewBacking.debugBreakpoint()}" action="userPhoto" />
</h:form>
The backing bean has
public void debugBreakpoint() {
int i = 0;
i++;
}
Unfortunately, this does help. It hits my breakpoint only after the second press. I suspect that some field somewhere isn't passing validation but I would like some method of detecting what exactly is going wrong - why do I need the second push? Is there some option I can turn on in Glassfish, or something else where I can look at a dump of debug information? I can ignore the dump until everything is stable and then see what exactly is happening when I press the button for the first time.
Is there any such tool which I can use?
That can happen when a parent component of the given <h:form> has been rendered/updated by another command button/link with <f:ajax>. The given form will then lose its view state which it would only get back after submitting the form for the first time. Any subsequent submits will then work the usual way. This is caused by a bug in JSF JS API as descibred in JSF issue 790 which is fixed in the upcoming JSF 2.2.
You need to fix the another command button/link with <f:ajax> to explicitly include the client ID of the given <h:form> in the render.
<f:ajax render=":somePanel :formP" />
Another way is to replace this <f:ajax> by a PrimeFaces <p:commandLink> or <p:commandButton> so that you don't need to explicitly include the client ID of all the forms. PrimeFaces's own JS API has namely already incorporated this fix.
add event="onclick" in your p:commandbutton
I guess that will sort it out.
or you can add this ajax="false" property in your commandButton
<p:commandButton ajax="false" action="#{userController.create}" value="#{bundle.CreateUserSaveLink}"></p:commandButton>
I ran into the same issue. The solution was simple, instead of having both an actionListener and an action, just convert the actionListener method to return a string to where you want to navigate to and use it as the method for the action (and don't have an actionListener).
In simple terms: only use an action (do not use an actionListener on a commandButton that is submitting a form).
Please check your binding with bean.
bean fields should be String or non primitive.

Resources