a4j:ajax nested on h:inputText prevents execution of h:commandButton action on first click - ajax4jsf

I have the following code:
...
<h:inputText
id="valorMoedaLocal"
value="#{pagamentoRegistrarMB.valorMoedaLocal}"
styleClass="right dinheiro"
size="12"
maxlength="12">
<f:convertNumber
type="number"
minFractionDigits="2"
maxFractionDigits="2" />
<a4j:ajax
event="change"
execute="valorMoedaLocal"
render="valorPagamento"
listener="#{pagamentoRegistrarMB.calculaValorRealOuroCorrecao}" />
</h:inputText>
<h:outputText
id="valorPagamento"
value="#{pagamentoRegistrarMB.valorPagamento}"
maxlength="12">
<f:convertNumber
type="number"
minFractionDigits="2"
maxFractionDigits="2" />
</h:outputText>
...
<h:commandButton
id="cbCorrigir"
value="#{messages['label.corrigir.pagto']}"
action="#{pagamentoRegistrarMB.validarCorrecao}"
disabled="#{empty pagamentoRegistrarMB.idRequerimentoMovimentoCorrigir}">
<f:param
name="id"
value="#{pagamentoRegistrarMB.bean.id}" />
</h:commandButton>
If I change the content of field valorMoedaLocal and then I click on button cbCorrigir, the ajax nested on the inputText is executed and the action from button cbCorrigir is not executed; it requires a second click to execute.
This happens because when I click on the button, the inputText looses focus and this caauses its ajax to be executed, preventing following executions. Is there a way to avoid this undesired behavior?

Related

f:param works only first time when using the same name in multiple commandButtons

My requierement is to upload some data and generate different reports for download with one click. In the example below I show appropriate button witch has a parameter that is sent to the download bean to select the correct version of the report.
But the f:param is only set the first time a p:commandButton is executed and then stays the same also for other buttons. Why is that and how can I solve this issue?
<h:form id="mainForm" enctype="multipart/form-data">
<p:fileUpload ...../>
....
....
<p:selectBooleanCheckbox id="opt1"
<p:ajax event="change" update="hiddingPanel"/>
</p:selectBooleanCheckbox>
<p:selectBooleanCheckbox id="opt2"
<p:ajax event="change" update="hiddingPanel"/>
</p:selectBooleanCheckbox>
<h:panelGroup id="hiddingPanel">
<p:commandButton id="doOpt1" rendered="#{bean.opt1 and !bean.opt2}"
actionListener="#{bean.readFile}" ajax="false" />
<p:fileDownload value="#{downloadBean.content}" />
<f:param name="reportType" value="REPORT1"/>
</p:commandButton>
<p:commandButton id="doOpt1" rendered="#{!bean.opt1 and bean.opt2}"
actionListener="#{bean.readFile}" ajax="false" />
<p:fileDownload value="#{downloadBean.content}" />
<f:param name="reportType" value="REPORT2"/>
</p:commandButton>
</h:panelGroup>
</h:form>
Thanks for any suggestions!
Regards.

JSF 2.2 custom validator not triggered in ui:repeat

after a desperate period of trials and errors i come to you looking for help, since now i am even unsure if i am doing it all wrong.
My code below displays some fields from a user profile in read only input text boxes. The data comes from a bean as ArrayList of "field" objects, whos properties are described in the ui:param directives.
The user can click an unlock/lock button next to the box to start/finish editing her data.
I want to trigger input validation when the user presses enter after editing or clicks the lock button.
But whatever i tried, after editing and pressing enter or clicking the button, the changed value is not written back and my custom validator is not triggered. Somehow it seems that after clicking the button the then rendered input box is not bound to the field? However, the validator works (and all attributes get passed to it) if used in an input text that is always rendered - and i don't understand it :)
Please have a look at it. If i did not explain my intent well enough or if you need more code, please let me know.
Edit: the annotations of the backing bean:
#ManagedBean( name = "beanProfile" )
#RequestScoped
The jsf code:
<ui:composition>
<ui:param name="i18n" value="#{field.i18n}" />
<ui:param name="val" value="#{field.value}" />
<ui:param name="req" value="#{field.required}" />
<ui:param name="min" value="#{field.min}" />
<ui:param name="max" value="#{field.max}" />
<ui:param name="validationType" value="#{field.validationType}" />
<ui:param name="useHidden" value="#{field.hidden}" />
<ui:param name="locked" value="#{field.locked}" />
<ui:param name="fullName" value="#{beanProfile.name}" />
<h:form id="profileFrm">
<h:outputText value="#{msg.role_profile} " styleClass="headingOutputText" />
<h:outputText value="#{fullName}" styleClass="headerTitle" />
<p />
<h:panelGroup>
<ui:repeat var="field" value="#{beanProfile.userFields}">
<h:panelGrid columns="2">
<h:outputText value="#{msg[i18n]}" styleClass="headerTitle" />
<h:message showDetail="true" for="visInput" styleClass="warn"
rendered="#{!useHidden}" />
<h:message showDetail="true" for="invisInput" styleClass="warn"
rendered="#{useHidden}" />
</h:panelGrid>
<h:panelGrid columns="2" columnClasses="nameColumn">
<h:inputText id="visInput" required="true" value="#{val}"
rendered="#{!useHidden}" readonly="#{locked}" >
<f:validator validatorId="customValidator" />
<f:attribute name="requiredField" value="#{req}" />
<f:attribute name="minLen" value="#{min}" />
<f:attribute name="maxLen" value="#{max}" />
<f:attribute name="type" value="#{validationType}" />
</h:inputText>
<h:inputSecret id="invisInput" required="true" value="#{val}"
rendered="#{useHidden}" readonly="#{locked}">
<f:validator validatorId="customValidator" />
<f:attribute name="requiredField" value="#{req}" />
<f:attribute name="minLen" value="#{min}" />
<f:attribute name="maxLen" value="#{max}" />
<f:attribute name="type" value="#{validationType}" />
</h:inputSecret>
<h:commandLink id="lock" action="#{beanProfile.lock(field)}"
rendered="#{!locked}" title="#{msg.profile_lock}">
<h:graphicImage height="16" width="16"
name="images/padlock_unlocked.svg" alt="#{msg.profile_lock}" />
</h:commandLink>
<h:commandLink id="unlock" action="#{beanProfile.unlock(field)}"
rendered="#{locked}" title="#{msg.profile_unlock}">
<h:graphicImage height="16" width="16"
name="images/padlock_locked.svg" alt="#{msg.profile_unlock}" />
</h:commandLink>
</h:panelGrid>
</ui:repeat>
</h:panelGroup>
<p />
<h:commandButton id="submitProfileBtn" value="#{msg.cmd_submit}"
styleClass="button" includeViewParams="true"
action="#{beanProfile.submitProfile()}" />
</h:form>
</ui:composition>
The origin of your problem is that you are using the RequestScoped scope for your backing bean containing the Model, so when you want to do a postback request in order to execute the backing bean method the binding just have dissapeared (not in the server memory) and the JSF lifecycle doesn't execute as expected. The solution is to use a longer scope as the ViewScoped scope. Ideally you should use the CDI compatible viewScoped scope, so you have to use JSF 2.2.x version.
Thank you lametaweb, you led me in the right direction.
Being unable to use the #ViewScoped annotation i found the link
how-to-install-cdi-in-tomcat
and followed BalusC's directions for using CDI in Tomcat. Then i had to let all the java classes implement the Serializable interface.
Now i can use the #ViewScoped annotation and the validator gets triggered.

every button click display panelGroup component(it contains 3 components)

every button click display panelGroup component(it contains 3 components).how to do it using jsf or richfaces
<h:form id="autoId">
<h:panelGroup id="pg1" columns="3" >
<rich:autocomplete mode="client" minChars="1" autofill="false"
selectFirst="false"
autocompleteMethod="#{autocompleteBean.autocomplete}"
autocompleteList="#{autocompleteBean.suggestions}"
/>
<h:inputText value=""/>
<h:inputText value=""/>
</h:panelGroup>
<a4j:commandButton value="show pg" />
</h:form>
when clicking on commanButton i like to show panelGroup
how to do it

by default value is not set in p:inputtext n jsf2

i have two inputs with percentageId_input_s1 and percentageId ids, in both
inputs i want to set default values "0" when page gets load
value (0) is set in percentageId_input_s1. After loading p:dialog when i click on
p:rowExpansion value is not set in percentageId, but when i use p:inputText
id="percentageId" value="#{0}" value is set in percentageId can any one tell me
whats happening ??
see code below:
abc.xhtml
<h:form>
<p:inputText
id="percentageId_input_s1" value="0"
size="4" maxlength="4"
onkeypress="reset_column('#{p:component('columnId_select_s1')}');">
<f:convertNumber integerOnly="true" type="number" />
</p:inputText>
</h:form>
// other inputs with there own forms
<h:form>
<h:link>
// this h:link open/show below p:dialog
</h:form>
<p:dialog>
<h:form>
<p:datatable>
<ajax event=toggle listener="#{someaction}">
// some columns
// using rowexpension p:rowExpansion
<p:rowExpansion>
<p:inputText
id="percentageId" value="0"
size="4" maxlength="4"
onkeypress="reset_column('#{p:component('columnId_select_s1')}');">
<f:convertNumber integerOnly="true" type="number" />
</p:inputText>
// all closing

rich:pickList Add/Remove Button not rendering a4j:outputpanel on first click

I am using richfaces 4.1 rich:picklist and need to render a4j:outputpanel on addition or removal of items in targetList. It renders outputpanel immediately on selecting Source/Target List elements but if directly click AddAll or RemoveAll button, output panel is not rendered on first click but renders onsecond click anywhere inside or outside screen.
Here is my code:
<rich:pickList value="#{myBean.selectedRegions}"
valueChangeListener="#{myBean.regionChangeListener}"
switchByClick="true" immediate="true">
<a4j:ajax event="additems" execute="#this" render="countryPanel" />
<a4j:ajax event="removeitems" execute="#this" render="countryPanel" />
<a4j:ajax event="sourceblur" execute="#this" render="countryPanel"/>
<a4j:ajax event="targetblur" execute="#this" render="countryPanel"/>
<a4j:ajax event="change" execute="#this" render="countryPanel" />
<f:selectItems value="#{myBean.regions}" var="region"
itemValue="#{region}" itemLabel="#{region.regionDesc}" />
<f:converter converterId="RegionConverter" />
</rich:pickList>
<a4j:outputPanel id="countryPanel" >
Upgrading to the latest RichFaces version should help. Also it would allow to simplify the code, you would need to specify only change event handler as the following issue has been fixed: https://issues.jboss.org/browse/RF-12360

Resources