Question

I was originally posting a value in the h:inputText field with an a4j:commandButton but I had to change the commandButton to s:link because the commandButton is also triggering a pdf document to be exported, and I believe that with an ajax call, the doc is rendered on the browser instead.

So now I am trying to post the value using h:inputText and a4j:support

<h:inputText id="numberOfPatients" 
    value="#{printLabelsReqFormsAction.numberOfPatients}">
    <a4j:support event="onkeyup" 
        action="#{printLabelsReqFormsAction.setNumberOfPatients(numberOfPatients)}"/>
</h:inputText>

(sorry for the weird formatting..)

My setNumberOfPatients(x) is getting called but I don't think I am passing the value correctly. How should I pass the value of the h:inputText field?

Was it helpful?

Solution

You don't need to explicitly set the value of numberOfPatients while executing ajax support. a4j:support tag processes its parent component during its execution, meaning the value for numberOfPatients will be set for each onkeyup event, even you don't invoke an action event. You can see it better at Richfaces' site:

RichFaces uses form based approach for Ajax request sending. This means each time, when you click an Ajax button or produces an asynchronous request, the data from the closest JSF form is submitted with the XMLHTTPRequest object. The form data contains the values from the form input element and auxiliary information such as state saving data.

When "ajaxSingle" attribute value is "true" , it orders to include only a value of the current component (along with or <a4j:actionparam> values if any) to the request map. In case of <a4j:support> , it is a value of the parent component. An example is placed below:

<h:form>
    <h:inputText value="#{person.name}">
        <a4j:support event="onkeyup" reRender="test" ajaxSingle="true"/>
    </h:inputText>
    <h:inputText value="#{person.middleName}"/>
</form>

In other words, for your case this should work:

<h:inputText id="numberOfPatients" 
    value="#{printLabelsReqFormsAction.numberOfPatients}">
    <a4j:support event="onkeyup" ajaxSingle="true"/>
</h:inputText>

Specify an action method only if you want to add extra logic when the event happens.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top