gpt4 book ai didi

ajax - JSF2 使用 ajax 更新复合元素

转载 作者:行者123 更新时间:2023-12-02 00:05:46 25 4
gpt4 key购买 nike

有一个输入元素,我想在用户在那里输入内容后更新它。

输入元素:

<h:form id="form">
<h:inputText value="#{message.message}">
<f:ajax event="keyup" render="form:compElem"/>
</h:inputText>
<compositeOutputComponents:test2 id="compElem" message="#{message.message}"/>
</h:form>

这就是我的复合元素的样子:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:composite="http://java.sun.com/jsf/composite">
<h:head>
</h:head>
<h:body>
<fieldset>
<composite:interface>
<composite:attribute name="id"/>
<composite:attribute name="message" required="true"/>
</composite:interface>
<composite:implementation>
<span id="#{cc.attrs.id}">
<h:outputText value="#{cc.attrs.message}"/>
</span>
</composite:implementation>
</fieldset>
</h:body>

我试图在 JSF Updating Composite Component (Primefaces) 中将 id 作为 Balus 传递给复合元素建议(我不使用 primefaces),但页面仍然会产生错误:“格式错误的 XML:更新期间:未找到 form:compElem”。当我使用非复合元素时,一切正常。

最佳答案

你需要#{cc.clientId}而不是 #{cc.attrs.id}在复合实现中。

<span id="#{cc.clientId}">

否则它将以<span id="compElem">结束。而不是 <span id="form:compElem">然后 JavaScript 无法再找到它,导致这个 malformedXML 错误。

修复该部分后,您就可以在 <f:ajax render> 中引用它了通常的方式就像您以相同的形式引用任何其他非复合组件一样:

<f:ajax ... render="compElem" />

或者如果您出于某种原因坚持指定绝对客户端 ID(但这是不必要的):

<f:ajax ... render=":form:compElem" />

另见:

关于ajax - JSF2 使用 ajax 更新复合元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18489057/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com