我有两个面板,一个外面板“外面板”和一个内面板“内面板”。里面的嵌在外面的里面。问题是我无法从内面板中移除项目。“删除内部项目”按钮不起作用。如果我查看生成的代码(见下文),似乎是生成真实id(“mojarra.ab(this,event,'action',0,'inner_lst_panel')”的问题。如果我硬编码
<h:commandButton
value="Remove inner item"
action="#{bean.do_delete_inner_item(mas, mav)}">
<f:ajax render="aform:j_idt13:0:inner_lst_panel" /> <!-- Hard coded!!! -->
</h:commandButton>
它起作用了。发生了什么?
JSF 2.3.2来自
https://maven.java.net/content/repositories/releases/org/glassfish/javax.faces/2.3.2/javax.faces-2.3.2.jar
豆子:
@Named
@ViewScoped
public class Bean
...
<h:form id="aform">
<h:panelGroup id="outer_lst_panel">
<ui:repeat
var="mas"
value="#{bean.mas_lst}">Outer item
<h:panelGroup id="inner_lst_panel">
<ui:repeat
var="mav"
value="#{mas.mav_lst}">Inner item
<h:commandButton
value="Remove inner item"
action="#{bean.do_delete_inner_item(mas, mav)}">
<f:ajax render="inner_lst_panel" /> <!-- Not working!!! -->
</h:commandButton>
</ui:repeat>
<h:commandButton
value="Add inner item"
action="#{bean.do_add_inner_item(mas)}">
<f:ajax render="inner_lst_panel" />
</h:commandButton>
</h:panelGroup>
<h:commandButton
value="Remove outer item"
action="#{bean.do_delete_outer_item(mas)}">
<f:ajax render="aform:outer_lst_panel" />
</h:commandButton>
</ui:repeat>
</h:panelGroup>
<h:commandButton
value="Add outer item"
action="#{bean.do_add_outer_item()}">
<f:ajax render="aform:outer_lst_panel" />
</h:commandButton>
</h:form>
生成代码:
<form
id="aform"
name="aform"
method="post"
action="test.xhtml"
enctype="application/x-www-form-urlencoded">
<input
name="aform"
value="aform"
type="hidden"> <span id="aform:outer_lst_panel"> Outer item <span
id="aform:j_idt13:0:inner_lst_panel"> Inner item <input
id="aform:j_idt13:0:j_idt35:0:j_idt31"
name="aform:j_idt13:0:j_idt35:0:j_idt31"
value="Remove inner item"
onclick="mojarra.ab(this,event,'action',0,'inner_lst_panel');return false"
type="submit"><input
id="aform:j_idt13:0:j_idt42"
name="aform:j_idt13:0:j_idt42"
value="Add inner item"
onclick="mojarra.ab(this,event,'action',0,'aform:j_idt13:0:inner_lst_panel');return false"
type="submit"></span><input
id="aform:j_idt13:0:j_idt43"
name="aform:j_idt13:0:j_idt43"
value="Remove outer item"
onclick="mojarra.ab(this,event,'action',0,'aform:outer_lst_panel');return false"
type="submit"></span><input
id="aform:j_idt44"
name="aform:j_idt44"
value="Add outer item"
onclick="mojarra.ab(this,event,'action',0,'aform:outer_lst_panel');return false"
type="submit"><input
name="javax.faces.ViewState"
id="j_id1:javax.faces.ViewState:0"
value="-2796149469970124814:8174359678892564468"
autocomplete="off"
type="hidden">
</form>
更新:
不,我的问题没有人回答
How to find out client ID of component for ajax update/render? Cannot find component with expression "foo" referenced from "bar"
我还不清楚为什么ajax标记中的render属性没有得到
inner_lst_panel
有一个连续的计数器。从我的观点来看
onclick="mojarra.ab(this,event,'action',0,'aform:j_idt13:0:inner_lst_panel')
但它没有。它变成
onclick="mojarra.ab(this,event,'action',0,'inner_lst_panel')
作为权宜之计(不,我不能用
render="@form"
出于其他原因)我可以使用以下内容:
<h:form id="aform">
<h:panelGroup id="outer_lst_panel">
<h:panelGroup id="inner_lst_panel" binding="#{foo}">
...
<f:ajax render="#{foo.clientId}" />
...