JSF渲染嵌入式面板列表ajax不起作用

时间:2018-11-05 09:36:38

标签: jsf mojarra

我有两个面板,一个是外部面板“ outer_lst_panel”,一个是内部面板“ inner_lst_panel”。内部的一个嵌入外部的一个。问题是我无法从内部面板中删除项目。 “删除内部项目”按钮不起作用。如果我查看生成的代码(请参见下文),则似乎与真实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>

有效。怎么了?

来自https://maven.java.net/content/repositories/releases/org/glassfish/javax.faces/2.3.2/javax.faces-2.3.2.jar的JSF 2.3.2

Bean:

@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}" />
        ...

0 个答案:

没有答案