【问题标题】:JSF does not call getter methods in popupJSF 不在弹出窗口中调用 getter 方法
【发布时间】:2013-06-23 09:10:04
【问题描述】:

我有一个普通的数据表,其中包含编辑按钮,它会打开一个弹出窗口。

 <h:form id="creditcard_configuration_form">
  <rich:dataTable id="test" width="100%"
    value="#{creditcardConfigurationService.cardsList}"
    iterationStatusVar="it" var="card">
    <rich:column>
      <a4j:commandLink execute="@this" ajaxSingle="true"
        oncomplete="#{rich:component('test123')}.show()">
        <h:graphicImage value="../../resources/images/edit.gif"
          alt="edit" />
        <a4j:param value="#{it.index}"
          assignTo="#{creditcardConfigurationAction.currentIndex}" />
      </a4j:commandLink>
    </rich:column>
  </rich:dataTable>

  <rich:popupPanel id="test123"
    header="#{creditcardConfigurationAction.currentIndex}"
    onmaskclick="#{rich:component('test123')}.hide()">
        asdf
  </rich:popupPanel>
</h:form>

在打开弹出窗口之前,我在我的 bean 中设置了一个索引变量。但是,JSF 在打开弹出窗口时不会调用 getter 方法来获取indexa4j:param(或者至少不再如此)。我发现,在呈现页面时调用了 getter-method,但在那之后就再也没有了。 (意味着,对于弹出窗口,索引始终显示为 0)。

包含索引变量的 bean 是视图范围的,而服务 bean 是会话范围的。我正在使用最新版本的 RichFaces(4.3.2 Final)和 JSF 2.0.6。

【问题讨论】:

  • 会很好,但这不会改变任何事情。
  • 哦! index var 意思是 #{it.index}param 标签中,对吗?我预计您会谈论您在popuppanel 中添加的一些元素。
  • 是的,索引变量的值是#{it.index},它在bean中被称为currentIndex,就像你可以看到的那样。我在 popupPanel 中有一些输入元素和按钮,但这并不重要,因为它甚至不起作用,如果 popupPanel 是空的,就像我在上面发布的示例中一样。
  • 所以在这种情况下,您可以在 commandLink 中使用actionactionlistner 并从中获取索引值。

标签: jsf popup getter


【解决方案1】:

您的问题有点令人困惑,所以我正在证明我预测的两种解决方案都可以解决您的问题,

答案 1:
首先参考这个link of richfaces show case with demo
这是它的代码

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:a4j="http://richfaces.org/a4j"
    xmlns:rich="http://richfaces.org/rich">
    <h:form>
        <rich:panel>
            <h:panelGrid columns="2">
                <a4j:commandButton value="Set Name to Alex" render="rep">
                    <a4j:param value="Alex" assignTo="#{userBean.name}" />
                </a4j:commandButton>

                <a4j:commandButton value="Set Name to John" render="rep">
                    <a4j:param value="John" assignTo="#{userBean.name}" />
                </a4j:commandButton>
            </h:panelGrid>
        </rich:panel>
        <br />
        <rich:panel>
            <h:outputText id="rep" value="Selected Name:#{userBean.name}" />
        </rich:panel>
    </h:form>
</ui:composition>

如您所见,您需要render 任何组件(这里使用rep),其中name 变量的getter setter 被调用(在请求范围内设置的页面提交参数值不调用getter-setter,它调用仅获取页面加载时间)。

2:
首先检查您的数据是否与来自 DB 的所有 Param 数据的 0 不同,您可以在 button 之后放置一个 outputtext 进行检查,其值为 #{it.index},就像您在 param 中使用的一样。
还有一个预测,如示例所示将您的commandLink 更改为commandButton,然后重试它可能会起作用。

【讨论】:

  • 哈哈,真傻。感谢您解决问题(第一个解决方案做到了):)
猜你喜欢
  • 2011-02-16
  • 2019-04-07
  • 1970-01-01
  • 1970-01-01
  • 2021-05-21
  • 1970-01-01
  • 1970-01-01
  • 2017-01-07
  • 1970-01-01
相关资源
最近更新 更多