【发布时间】:2017-09-26 14:55:07
【问题描述】:
我正在使用 JSF 2.2 和 primefaces 6.0
我有一个这种形式的表格
<table>
<tr>
<td rowspan="2">
Direction
</td>
<td colspan="#{etpBean.activites.size()}">
Activites
</td>
</td>
<td rowspan="2">
Controle
</td>
</tr>
<tr>
<ui:repeat var="activite" value="#{etpBean.activites}">
<td>
<h:outputText value="#{activite.nom}"/>
</td>
</ui:repeat>
</tr>
<ui:repeat value="#{etpBean.affectations}" var="affectation">
<tr>
<ui:repeat var="activite" value="#{etpBean.activites}">
<td rowspan="#{etpBean.affectations.size()}"><h:outputText value="#{affectation.structure.nom}" />
</td>
<td>
<p:inputText value="#{etpBean.getValeurActivite(affectation,activite).etp}" required="true">
<p:ajax listener="#{etpBean.onControleChange(affectation)}" update="controle" event="blur" />
</p:inputText>
</td>
<td>
<h:outputText id="controle" value="#{etpBean.message}"/>
</td>
</ui:repeat>
</tr>
</ui.repeat>
</table>
对于该表的每一行,我有许多相同类型的输入,在我的侦听器 onControleChange 中,我检索这些输入的值,因为我在每个条目之后计算总和,如果总和超过,我想更新列 controle 100 我想放不ok else Ok。
这里是 onControleChange
public void onControleChange(Affectation affectation){
double somme=0;
for (ETP etp : etpss) {
if(etp.getAffectation().equals(affectation) && etp.getEtp() != null){
somme+=etp.getEtp();
}
affectation.setSomme(somme);
}
if(somme>100){
this.message="Not ok";
}else{
this.message="Ok";
}
}
但是当我运行我的 XHTML 时会出现这个错误
Grave: org.primefaces.expression.ComponentNotFoundException: Cannot find component for expression "controle" referenced from "form:j_idt77:0:j_idt94:0:j_idt96".
我不知道是不是因为ui:重复所有列“contrôle”采用相同的id。
有什么想法吗??
【问题讨论】:
-
嗨,首先为所有命名容器和组件分配 id。一般来说,更容易为自己“调试”和“良好实践”,删除所有不会改变你看到的行为的代码,并将其设为minimal reproducible example,并阅读 Stackoverflow 中所有 >50 个投票的问题和答案,这样你就知道了最基本/相关的东西(例如stackoverflow.com/questions/8634156/…)
-
后一个链接包含对stackoverflow.com/questions/7415230/… 的引用,这可能会导致您的问题,但我们看不到,因为您没有发布minimal reproducible example...
-
这是我第一次进入堆栈,我将阅读最小的 Complete.. 我会更新我的问题,谢谢@Kukeltje
-
太棒了...对于我第一条评论中的“id”,您可以使用showcase.omnifaces.org/viewhandlers/… 在开发过程中帮助您实施这个“策略”
标签: primefaces jsf-2 el