简体   繁体   English

使用h:inputtext和a4j:support onkeyup发布值

[英]Post value using h:inputtext and a4j:support onkeyup

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. 我最初在h:inputText字段中使用a4j:commandButton发布了一个值,但我不得不将commandButton更改为s:link,因为commandButton也触发了要导出的pdf文档,我相信通过ajax调用,该文档是在浏览器中呈现相反。

So now I am trying to post the value using h:inputText and a4j:support 所以,现在我想用小时,张贴值:inputText的和A4J:支持

<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. 我的setNumberOfPatients(x)被调用,但是我认为我没有正确传递值。 How should I pass the value of the h:inputText field? 我应该如何通过H的值:inputText字段?

You don't need to explicitly set the value of numberOfPatients while executing ajax support. 执行ajax支持时,无需显式设置numberOfPatients的值。 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. a4j:support标记在执行期间会处理其父组件,这意味着将为每个onkeyup事件设置numberOfPatients的值,即使您没有调用action事件也是如此。 You can see it better at Richfaces' site : 您可以在Richfaces的网站上更好地看到它:

RichFaces uses form based approach for Ajax request sending. RichFaces使用基于表单的方法来发送Ajax请求。 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. 这意味着每次单击Ajax按钮或生成异步请求时,最接近的JSF表单中的数据都会与XMLHTTPRequest对象一起提交。 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. 当“ ajaxSingle”属性值为“ true”时,它命令仅将当前组件的值(以及<a4j:actionparam>值(如果有的话)一起)包含到请求映射中。 In case of <a4j:support> , it is a value of the parent component. <a4j:support>情况下,它是父组件的值。 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. 仅当您想在事件发生时添加额外的逻辑时,才指定操作方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM