如何识别Java服务器面临2.0复合材料部件在使用AJAX?复合材料、部件、如何识别、服务器

2023-09-10 21:37:58 作者:▁为什么放弃治疗ゞ

我有以下的Java服务器面临2.0复合材料构件。请注意,我使用的逐字的

I have the following Java Server Faces 2.0 composite component. Notice i am using verbatim

resources/customer/customer.xhtml

<composite:interface>
    <composite:attribute name="id" required="false"/>
    <composite:attribute name="firstName" required="false"/>
    <composite:attribute name="lastName" required="false"/>
    <composite:attribute name="age" required="false"/>
    <composite:attribute name="rendered" required="false"/>
</composite:interface>
<composite:implementation>
    <f:verbatim id="#{cc.attrs.id}" rendered="#{cc.attrs.rendered}">
        <div>
            <div>
                <p>First name</p>
                <h:outputText value="#{cc.attrs.firstName}"/>
            </div>
            <div>
                <p>Last name</p>
                <h:outputText value="#{cc.attrs.lastName}"/>
            </div>
            <div>
                <p>Age</p>
                <h:outputText value="#{cc.attrs.age}"/>
            </div>
        </div>
    </f:verbatim>
</composite:implementation>

为了使用Ajax,我这样做(注意的渲染的属性)

In order to use ajax, i have done (Notice render attribute)

<h:form id="search">
<div>
    <h:commandButton value="Search" action="#{customerSearchController.search}">
        <f:ajax execute="@form" render="search:result"/>
    </h:commandButton>
</div>
<customer:customer id="result"
                   rendered="#{customerSearchController.customer != null}"
                   firstName="#{customerSearchController.customer.firstName}"
                   lastName="#{customerSearchController.customer.lastName}"
                   age="#{customerSearchController.customer.age}"/>
</h:form>

我的CustomerSearchController如下所示

My CustomerSearchController is shown as follows

private Customer customer;

// getter's and setter's

public void search() {
    customer = new Customer();

    customer.setFirstName("First");
    customer.setLastName("Last");

    customer.setAge(30);
}

无论CustomerSearchController和客户进行管理的bean。但是,当我叫Ajax请求,它抱怨:搜索:结果没有发现的

我应该做的我来解决这个问题???

What should do i to solve this issue ???

推荐答案

&LT; F:AJAX渲染&GT; 应指向在HTML DOM树中的现有客户端ID。然而,由于搜索:结果元素是不是在HTML DOM树用,因为它不是由服务器端渲染,JS / AJAX找不到HTML DOM树的任何更新/渲染。

<f:ajax render> should point to an existing client ID in the HTML DOM tree. However, since search:result element is not available in the HTML DOM tree because it's not rendered by the server side, JS/ajax cannot find anything in HTML DOM tree to update/render.

敷在它总是在HTML DOM树可用,这样的Ajax可以找到它的另一元素

Wrap it in another element which is always available in the HTML DOM tree so that Ajax can locate it.

<h:panelGroup id="result">
    <customer:customer rendered="..." />
</h:panelGroup>

无关的实际问题,注意 F:逐字应该只包含逐字(纯HTML),没有JSF组件。通过替换它。H:panelGroup中

Unrelated to the actual problem, note that f:verbatim is supposed to contain only verbatim (plain HTML), not JSF components. Replace it by h:panelGroup.