PrimeFaces commandButton not work after submit - jsf

I have the following problem I have a CommandButton of primefaces that does well its function which is to save an accounting movement, but when you try to enter a second movement the button does not work to such an extent that it does not warn you if the required fields are empty.
Note that if I give the cancel button that only has a JS to hide and show some labels there is if the button works again.
I need that button to continue working without having to hit the cancel button.
I'm going to leave a partial code that includes the TAG of the form and the buttons warn if you need to also put the fields.
<h:form id="form_agregar_movimiento" prependId="false" >
...
<p:commandButton styleClass="Tamano-Texto-Datos Boton-Afirmativo"
value="Agregar"
action="#{movimientosController.agregarNuevoMovimiento()}"
update=":growl_mensaje_eventos :dataTable_listar_movimientos form_agregar_movimiento"
/>
<p:commandButton styleClass="Tamano-Texto-Boton Boton-Negativo"
value="Cancelar"
onclick="js_ocultar('agregar_movimiento_contenedor'); js_mostrar('movimiento_contenedor_botonAgregarMovimiento');"/>
</h:form>

594/5000
Hi guys, I have solved the problem, I noticed that other forms presented the same problem and testing by ending with #form as recommended and the "prependId = true" and additional add the attribute resetValues="true" and with And the buttons come back to work without problems.
Note: in the example that this function did not work for me but it was for something else, I had a RequestContext.getCurrentInstance().Execute() which calls a JavaScript and it was giving me an error in the browser, I corrected it and works correctly.
Thanks for the tips that have left me

Related

Update JSF in carusell

I currently try to implement a website, where an dialog, opened from an carousel, changes something in the database and the result is shown on the screen. For that, I try to update an area in the dialog. Unfortunately, updating things in an carusell does not seem to work.
I shortened the code to an minimal example, so with the following code:
<p:carousel id="page" value="#{pagebean.pages}"
var="item" numVisible="1">
<h:form id="dlg_2_form">
<h:outputText id="test_2" value="#{pagebean.value}" />
<p:remoteCommand name="update_2" update="test_2" />
Increment
</h:form>
</p:carousel>
the function pagebean.value is not called after I click on Increment, but therefore the constructor of pagebean is called when I click on Increment. So it seems like the carousel makes it impossible to update something in it.
Does anyone know, if there is an possibility to update something which is in a carousel, or if there is a workaround for this problem?
EDIT: After the discussion below, I know that Increment does work, if the scope of the corresponding bean is set to #ViewScoped. I could also trigger this button by giving it a widgetVar and accessing its click function, so this would work. Unfortunately, the Bean I want to use is SessionScoped, and with this kind of view it does not work. Has anybody an hint how to solve this problem? I could copy everything into a second Bean, which is ViewScoped, but this is not a very nice solution.

p:outputLabel would not update

I have a dialog box containing p:inputText with required="true" and a corresponding p:outputLabel.
<p:outputLabel for="name" value="First Name" />
<p:inputText id="name" value="#{userManagedBean.name}" required="true"/>
I submit the dialog box without any value causing a validation error indicated by the p:outputLabel in red required mark. But on reopening the dialog without submitting, the outputLabel is still in the invalidate state(red font). It doesnt get updated until I submit or navigate back from other page. I tried to update the whole dialog box but it wouldnt affect the label.
Thanks in advance
This is expected behaviour as input components (and related components) will maintain their state after validation fails. The state is only changed after the full request is re-executed and the complete JSF lifecycle is executed again.
You're not stating exactly how you're "updating" the panel, but I can recommend <p:resetInput/> to explicitly reset the state of related input components, without having to resubmit the entire <h:form/>. If you'd posted more meaningful code, I might have been able to give a working snippet
It will not be updated since opening the dialog box is happening in javascript (client side).
You need to re-render your dialog box when you open it.

JSF listener triggers buttons onclick

<h:form>
<h:selectOneMenu value="#{productBean.productName}">
<f:selectItem itemValue="" itemLabel="..." />
<f:selectItems value="#{productBean.pizza}" var="pizza" itemValue="#{pizza.name}" itemLabel="#{pizza.name}" />
<f:ajax listener="#{productBean.valueChanged(productBean.productName)}" render="pizzaResult pizzaButton" />
</h:selectOneMenu>
<h:commandButton value ="Dodaj do zamówienia" disabled="#{productBean.isDisabled}" id="pizzaButton" onclick="#{productBean.order}"/>
<h:outputText id="pizzaResult" value="#{productBean.message}" />
</h:form>
This is my JSF form. I used valueChanged listener to make button diabled in ome cases and it works good. But I don't get why it triggers also the buttons onclick. How to do something which enable me to use button ONLY after clicking it?
I noticed that when I delete the disabled option it works good:/ But why I cannot trigger the action when button is enabled in the moment?
onclick is a client side attribute so you shouldn't try to bind it to managed bean method calls and it looks as though you did onclick=#{productBean.order} (apart from the missing quotes). This may be the cause of your problems.
OK i did that. The problem is that the button may appear as enabled (disabled="false") but its client side change and server don't know about it and application thinks that the button is still disabled. Even it looks like enabled button it won't work with action="#{something}".
You have to let server know about the change. THe only thing i did is adding the #ViewScoped to the managed bean. Now the action of disabling and enabling the button is also being seen by the server and works perfectly.
However i have a question. Client side verifaction is a bad idea. Disabled button is the only thing which prevent user from sending empty itemValue or product(in my case) which is unavailable (is_available = 0 in DB). The question is: Is it enough to ensure that it will be safe?
edit: Unfortunately after clicking the button the buttons appear enabled even though the oneSelectMenu is turned to the first, empty value. After changing the list it works again as previously, and after clicking again the situation takes time again.

Pressing enter to click on hidden button without using JS on a jsf page?

I have a jsf page where I have several 's. When I press enter I want a particular button to be clicked - and this button is hidden. Is there a way to do this without using JS?
I know if i place the button as the first button on the page, it will be clicked by default - but it does not seem to work.
Here is the sample code. I want the "hiddenButton" to be clicked on Enter.
<h:form>
<h:commandButton id="button1" action="#{bean.action1}" />
<h:commandButton id="button2" action="#{bean.action2}" />
<h:commandButton id="button3" action="#{bean.action3}" />
<h:commandButton id="hiddenButton" action="#{bean.hiddenAction}" style="display:none;"/>
<h:form>
Is there a way to do this without using JS?
Not if you want to support all browsers.
I know if i place the button as the first button on the page, it will be clicked by default - but it does not seem to work.
This works only in Firefox, not in Chrome (Webkit) or IE. If you replace display:none by visibility:hidden, then it'll also work in Chrome, but still not in IE.
So, if you want to support all browsers, JS is your best bet. There may be better solutions depending on the concrete functional requirement, which you didn't tell anything about in the question.

Skip form validation on command button

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

Resources