【问题标题】:Best way to pass value into backing bean in Richfaces在 Richfaces 中将值传递到支持 bean 的最佳方法
【发布时间】:2011-04-18 19:04:48
【问题描述】:

我有一个表并使用 actionListener 执行删除操作,见下图。 现在我正在使用 event.getComponets() 来获取从 f:param 标签设置的值。但是,通过这种方式,我必须将组件 ID 硬编码到支持 bean。看起来不是一个好方法。当表格中有操作按钮列表时,它有更好的方法从 UI 传递值。

    final UIParameter parm = (UIParameter) event.getComponent().findComponent(EDIT_SITE_ID_PARM);
    return (Integer)parm.getValue();

【问题讨论】:

    标签: richfaces


    【解决方案1】:

    您可以使用 a4j:actionParam name=".." value="..",它的工作原理与 f:param 类似,但也会自动分配给 bean 属性。另一种选择是使用 f:setPropertyActionListener。

    【讨论】:

    • 这看起来像是我正在寻找的答案,但我看不到完整的句子。
    • 抱歉,我的回答出了点问题。已更新。
    【解决方案2】:

    你的动作监听器应该是这样的:

    public void deleteActionListener(ActionEvent event) {
            final String param = (String) FacesContext
                    .getCurrentInstance().getExternalContext()
                    .getRequestParameterMap().get("deleteIdParam");
                    //convert to int and call your delete method
    }
    

    所以您只需硬编码参数的名称 ant 而不是组件的 id。

    当然,现在您的 actionListener 将是 deleteActionListener 而不是旧的。

    【讨论】:

      【解决方案3】:

      Christian 通过使用 actionparam 帮助找到了一种方法。我已经把代码放在下面

      <a4j:commandButton value="delete" >
      <a4j:support event="onclick" reRender="reviewArea">
          <a4j:actionparam name="setViewMode" assignTo="#{backingBean.selectTmpId}" value="#{item.id}" actionListener="#{backingBean.viewMsgContent}" />
      </a4j:support>
      

      【讨论】:

        猜你喜欢
        • 2010-10-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-10-13
        • 2013-12-30
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多