简体   繁体   English

如何使用f:ajax在jsf结构的不同部分中呈现事物

[英]how to render things in different parts of a jsf structure with f:ajax

The concise version of the question I have is this: How do I in response of a blur event on a 我的问题的简洁形式是:我如何响应屏幕上的模糊事件

<h:inputText> 

get the same value to show in a 得到相同的值以显示在

<h:outputText> 

located outside the scope of the inputText field. 位于inputText字段范围之外。

The inputtext field has the following xpath: inputtext字段具有以下xpath:

//*[@id="form:j_idt40:src_table:0:j_idt137"]

The outputtext is located here: 输出文本位于此处:

//*[@id="form:j_idt40:target_table:0:target_id"]

I am using primefaces datatable and the two paths are located in two separate datatables 我正在使用primefaces数据表,两个路径位于两个单独的数据表中

The jsf code for the input field is the following: 输入字段的jsf代码如下:

<p:dataTable id="src_table">
    <p:column id="src_id" headerText="srcHeader">
        <h:inputText value="#{bean.myAttribute}">
            <f:ajax event="blur" render="src_id WHAT_SHOULD_GO_HERE?" ></f:ajax>
        </h:inputText>
    </p:column>
</p:datatable>

and the code for the output is the following 和输出的代码如下

<p:dataTable id="target_table">
    <p:column headerText="TargetHeader">
        <h:outputText id="target_id" value="#{bean.myAttribute}" />
    </p:column>
</p:datatable>

i have tried several paths on the WHAT_SHOULD_GO_HERE? 我在WHAT_SHOULD_GO_HERE上尝试了几种路径? placeholder but I can't seem to get it right. 占位符,但我似乎无法正确处理。 They have all ended up throwing faces exceptions like the following: 他们最终都抛出了如下异常:

javax.faces.FacesException: <f:ajax> contains an unknown id ':target_id' - cannot locate it in the context of the component j_idt137

this was of course when I replaced WHAT_SHOULD_GO_HERE? 这当然是当我更换WHAT_SHOULD_GO_HERE时? with :target_id 与:target_id

I have also tried: 我也尝试过:

form:j_idt40:target_table:0:target_id, 

:form:j_idt40:target_table:0:target_id 

but no luck. 但没有运气。

Can anyone help with my understanding of xpath or maybe even f:ajax and rendering specific parts of a view? 谁能帮助我理解xpath甚至f:ajax并渲染视图的特定部分?

Can anyone help with my understanding of xpath 谁能帮助我理解xpath

JSF doesn't use Xpath in <f:ajax> at all. JSF根本不在<f:ajax>中使用Xpath。 It just expects a relative or absolute client ID. 它只是期望一个相对或绝对的客户端ID。 This is in detail explained in How to find out client ID of component for ajax update/render? 这在如何查找用于ajax更新/渲染的组件的客户端ID中有详细说明 Cannot find component with expression "foo" referenced from "bar" . 找不到从“ bar”引用的表达式为“ foo”的组件

You should only change the component represented by the autogenerated ID j_idt40 to have a fixed ID set, otherwise it would break again when you add or remove a component in the view later. 您仅应将自动生成的ID j_idt40表示的组件更改为具有固定的ID集,否则稍后在视图中添加或删除组件时,组件将再次中断。

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

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