Rajesh Renke
Rajesh Renke

Reputation: 127

How to pass multiple component values to listener via ajax on button click

I have select box for list of account numbers, an input field to enter amount and a button to calculate total debit. I want to pass the amount and account values via ajax to an event handler on click event.

Some how I am not able to pass the values entered to event handler.

Can someone suggest me, on how to do ?

My Xhtml:

<h:selectOneMenu class="RUIFW-from-el form-control"
id="fromAccountIndex" value="#{parentBean.fromAccountIndex}"
validator="#{tptValidator.validateFromAccount}">
<f:selectItems value="#{parentBean.fromAccountUIMap}"/>
</h:selectOneMenu>


<h:inputText id="amount" name="amount" value="#{parentBean.amount}" class="RUIFW-form-el form-control" validator="#{tptValidator.validateAmount}"/>

Updated code:

<h:commandLink class="RUIFW-btn mar-lft-10 veraligntop">
<h:outputLabel value="#{GIBBundle.tpt_btn_calculate}"/>
<f:ajax execute="@this fromAccountIndex amount onclick" listener="#{parentBean.calculateClickedListener}"/>
</h:commandLink> 

My Bean Method

public void calculateClickedListener(AjaxBehaviorEvent event) {
                System.out.println("getFromAccountIndex()....."+getFromAccountIndex());
System.out.println("getAmount()....."+getAmount());
    }

Upvotes: 0

Views: 1015

Answers (1)

kolossus
kolossus

Reputation: 20691

You're not setting the execute attribute on the f:ajax. That attribute defaults to @this, and as a result, no other component will be processed and no values will be set. This is why the value bindings of your input components are likely to turn out null.

Set your execute="@form" or execute="@this fromAccountIndex amount" to get the values updated in your bean

Reference:

Upvotes: 1

Related Questions