a4j:commandButton does not invoke action - jsf-2

i am trying to migrate a jsf 1.x richfaces 3.x app to jsf2.x and richfaces 4.x. i have a richpopupPanel inside a form which has a form and two a4j:commandButtons. i am not able to invoke action on the secondbutton to submit the form.
the code goes as follows.
<h:form id="outsideform">
<rich:popupPanel id="details" domElementAttachment="form">
<f:facet name="header">
<h:outputText value="PopuPTitle" style="text-align: center;" styleClass="center"/>
</f:facet>
<a4j:commandButton id="firstButton" render = "detailsform" action="#{mybean.getDetails()}"/>
<h:form id="detailsForm>
content to be submitted
<a4j:commandButton id ="secondButton" action ="#{mybean.action()}" render="addContent"/>
</h:form>
</rich:popupPanel>
The detailsForm renders succesfully on the click of the firstButton, but when make some changes in the content and try to submit by clicking on secondButton the action on the secondButton is not invoked. the form to be submitted is the detailsForm.

Do not use nested h:forms. Move "details" popupPanel outside of "outsideform" form.

Remove <h:form id="detailsForm>and add process="details" attribute to the second button.

Related

Primefaces dialog client validation not displaying

I have a Primefaces 5.0 modal dialog on a composite control. The dialog has a few field marked as required. When the button on the dialog is clicked I expected the client validation to fire and it seems it does as the backing bean is not called, but the messages are not displaying:
<p:dialog id="dialogCorporateShareHolder" header="Shareholder (Company)"
widgetVar="dlgCorporateShareHolder" modal="true">
<p:panelGrid columns="3" id="corporateShareHolderDetails">
<h:outputLabel for="companyName" value="Company name"/>
<p:inputText id="companyName" required="true"
value="#{cc.attrs.corporateShareHolder.companyName}"
label="Company name"/>
<p:message for="companyName"/>
<f:facet name="footer">
<p:commandButton id="submitCorporate" value="Submit"
update="corporateShareholders"
actionListener="#{cc.attrs.controller.addCorporateShareHolder}"/>
</f:facet>
</p:panelGrid>
</p:dialog>
The dialog displays, the validation gets called (I'm pretty sure), but no message is displayed.
You only need to update the p:message or a parent too, for example with
update="corporateShareholders corporateShareholderDetails"
Btw. I believe best practises are to
have the dialog(s) last in xhtml, outside of other forms
have a form inside the dialog itself

how to reset form inputs after they are submitted in jsf

so i have this code(not in details)
<p:tabView id="tabviewId">
<p:tab>
<h:form id="mainHeadOfAccountsId_form">
// some input fields with validation
// using viewscoped
<p:commandButton value="Add" process="mainHeadOfAccountsId_form" update="mainHeadOfAccountsId_form :#{p:component('allMainHeadOfAccountsId_table')} :#{p:component('successfullySavedUpdatedId_growl')}" action="#{budgetHeadOfAccountsAction.addMainHeadOfAccountsOnAjax}" />
/// also using <p:datatable id= "allMainHeadOfAccountsId_table" >
</h:form
</p:tab>
<p:tab>
<h:form>
</h:form
</p:tab>
</p:tabView>
<p:growl id="successfullySavedUpdatedId_growl" for="successfullySavedUpdatedFor_growl" value="error" showDetail="false" />
my Question is that when i submit form mainHeadOfAccountsId_form successfully i need to update(reset) all fields which are in mainHeadOfAccountsId_form
but remember that i am also using <h:selectOneMenu> so i want to reset(option[0] selected) not empty, how can i do that ? currently its updating allMainHeadOfAccountsId_table and successfullySavedUpdatedId_growl except mainHeadOfAccountsId_form
i have tired tabviewId:mainHeadOfAccountsId_form but getting exception component not found,
as i am thinking this is just because of #viewScoped and i should reset value of those inputs in my action class (.java), m i right ?
see what primefaces offer for reset input or after submitting the form by the action in the bean reset the values by new or null and recreate the list held by
<h:selectOneMenu>

How to perform JSF setPropertyActionListener before javascript onclick event

Here is the deal: I have a dataTable populated by a list in my managed bean. What I want is to open a simple primefaces dialog with the selected object's infos and I am trying to do so by using a setPropertyActionListener and a onclick event.
<p:commandButton id="basic" value="Resumo" onclick="dlg1.show();"
type="button"
>
<f:setPropertyActionListener target="#{consultaArtigoBean.artigoSelecionado}"
value="#{artigo}" />
</p:commandButton>
And the dialog
<p:dialog id="basicDialog" header="Resumo - #{consultaArtigoBean.artigoSelecionado.titulo}"
widgetVar="dlg1"
dynamic="true">
#{consultaArtigoBean.artigoSelecionado.resumo}
</p:dialog>
The thing is that the action performs before the setPropertyActionListener takes effect. So the dialog pops up with no object at all.
What should I do to make sure the setProperty performs before the action thus setting my object.
Update
An other topic here helped answer this.
Pass a value from h:outputLink to JSF after onclick event
and the result is that:
<p:commandLink id="basic" value="Resumo"
oncomplete="dlg1.show();"
update="#form">
<f:setPropertyActionListener target="#{consultaArtigoBean.artigoSelecionado}"
value="#{artigo}" />
</p:commandLink>
and the dialog
<p:dialog id="basicDialog" header="Resumo - #{consultaArtigoBean.artigoSelecionado.titulo}"
widgetVar="dlg1"
dynamic="true">
#{consultaArtigoBean.artigoSelecionado.resumo}
</p:dialog>
Use the oncomplete attribute which will get fired after the ajax postback.
Further update the dialog via the update attribute.
Execute p:commandLink action before onclick event?

How to hide and show p:panel on commandbutton click

i have the following problem:
I'm new to JSF2 and primefaces.
I have a table in a page that will be populated with information, after the user enters a string and clicks a CommandButton. After clicking the button, I want it to be disabled until processing is over.
To disable the CommandButton I'm doing the following;
<p:commandButton update=":outPanel" widgetVar="btnSend" id="btnsend"
value="Calcular" actionListener="#{calcBean.getTrfs}"
onclick="btnSend.disable()" oncomplete="btnSend.enable()" />
And then I have a panel where I want to show its contents:
<p:panel id="outPanel" widgetVar="outpanel">
#{calcBean.result}
</p:panel>
How can I hide this outpanel when the page loads the first time?
How can I hide it when I click the CommandButton, and only show it again if the processing in my bean is successful?
Thanks.
Solved,
i have to put
closable="true" toggleable="true"
attributes in p:panel... Thanks
I have checked following panel hide and show using p:commandButton in JSF,
please try following methods in JSF,
<p:panel id="button_panel" widgetVar="testPanel" closable="true" toggleable="true">
<h1>Testing</h1>
</p:panel>
<p:commandButton onclick="PF('testPanel').show()" value="Show Panel" type="button"/>
<p:commandButton onclick="PF('testPanel').hide();" value="Hide Panel" type="button"/>
to show the panel after the ajax request is finished try this:
<p:commandButton update=":outPanel" widgetVar="btnSend" id="btnsend"
value="Calcular" actionListener="#{calcBean.getTrfs}"
onclick="btnSend.disable()" oncomplete="btnSend.enable();outPanel.show();" />

page navigation not occuring after enabling button from row select using ajax

I am using JSF 2.0 and primefaces 3.0
I am trying to enable a command(Submit) button after a row select from datatable
<p:datatable ....>
<p:ajax event="rowUnselect" onstart="showImageButton.disable();" />
<p:ajax event="rowSelect" onstart="showImageButton.enable();" />
</p:datatable>
<p:commandButton id="commandbuttonid" widgetVar="showImageButton" action="#{bean.methodreturningapage}" value="Submit"
ajax="false" disabled="true" />
after selecting the rows command button gets enabled but the action method is not firing.
Change the disabled attribute into something like #{bean.buttonDisabled}
take a look on this question
p:commandButton not working when disable=“true” initially
and this one
Re-enabled p:commandButton not firing ajax

Resources