【问题标题】:Values in rich:dataTable not getting updated in the beanrich:dataTable 中的值未在 bean 中更新
【发布时间】:2013-12-30 16:38:03
【问题描述】:

这个问题是在我们迁移到richfaces4.3 和JSF2.0 时出现的。

上下文是:Rich:dataTable 在其各自的列中采用 answerId、answerDefinition 等。在 answerid 列上执行 onchange 事件,其中添加了一个新行。

<rich:extendedDataTable rowKeyVar="currentRowVar"
        value="#{DiscQuestMgtController.answerChoiceList}"
            var="dataItem" rowClasses="row1, row2" id="ansChoiceList">
                <rich:column width="160" sortable="false">
                   <h:inputText id="answerID"  value="#{dataItem.answerId}"
                            onchange="addNewRowToAnsChoice('DiscQuestMgtForm',#{fn:length(DiscQuestMgtController.answerChoiceList)});" />     
                </rich:column>
                <rich:column sortable="false">
                    <h:inputText id="choiceValue" value="#{dataItem.choiceValue}"/>
                </rich:column>
                <rich:column sortable="false">
                    <h:inputText id="definitionId"  value="#{dataItem.definition}"/>
                </rich:column>
    </rich:extendedDataTable> 

将值检索到数据表中时,工作正常。但是,当我将值输入 answerId(第一个单元格)并转移焦点时,现有行被完全消除,创建一个新行。

addNewRowToAnsChoice,JS 方法,对输入的值进行少量验证,然后调用 a4j 函数 .. addEmptyAnsChoice .. 下面是代码,添加了一个新行,在支持 bean 中。

//添加新行

public void addEmptyRow( ActionEvent ae )
    {

        removeEmptyChoiceRow();
        String logStr = " DiscQuestMgtController:addEmptyRow()>>>";
        logger.debug( logStr + " Entered" );
        AnswerChoiceBean bean = new AnswerChoiceBean();
        bean.setQuestionId( discQuestBean.getQuestionId() );
        logger.debug( logStr + "Choice list size: answerChoiceList size-->",answerChoiceList.size() ); //@abc
        if ( answerChoiceList.size() == 1 )
            answerChoiceList.get( 0 ).setQuestionId( discQuestBean.getQuestionId() );
        if ( !answerChoiceList.contains( bean ) )
            answerChoiceList.add( bean );
        logger.debug( logStr + " Returned" );
    }

removeEmptyChoiceRow() 检查是否存在任何空行并删除它们,以添加新行。 @abc,列表大小始终是默认大小。 (页面加载总是有一行),尽管输入了值,但它并没有改变。请推荐!!

这是 a4j:function:

<a4j:jsFunction name="addEmptyAnsChoice"
                render="ansChoiceList,addDiscQuest,applyDiscQuest"
                actionListener="#{DiscQuestMgtController.addEmptyRow}"
                oncomplete="focusToNewCell('DiscQuestMgtForm',#{fn:length(DiscQuestMgtController.answerChoiceList)});">
            </a4j:jsFunction>

【问题讨论】:

  • 您能否包括#{DiscQuestMgtController.answerChoiceList} 的方法定义以及相关bean 的范围?
  • 提到的输入字段触发函数addNewRowToAnsChoice onchange。这是您的功能之一。为了真正帮助您,请删除 xhtml 中不重要的部分(例如 f:facet name="header"、styles 等),这样可以更轻松地理解您的问题。还提供连接的 JavaScript 函数和托管 bean,例如DiscQuestMgtController.
  • @L-Ray 我编辑了我的问题。
  • @mzzzzb bean 是会话范围的。请查看我编辑的问题。

标签: jsf jsf-2 richfaces


【解决方案1】:

从 JSF 1.2 到 JSF 2 的一个主要变化是引入了属性 renderexecute 替换 rerender

  • execute 部分更新树的标记部分的模型
  • render 渲染树的标记部分并通过 AJAX 发送以替换原始部分。

这很方便,例如侦听器更新值也显示为页面上的输入字段。

更新:您在更改answerId 时调用addNewRowToAnsChoice,稍后再调用a4j:jsFunction addEmptyAnsChoice

元素 ansChoiceList ,addDiscQuest,applyDiscQuest 被重新渲染,但没有为 execute 发送任何内容。因此,您输入的answerId 行 - 嗯 - 永远不会在服务器端更新。

在下一步中,在 actionListener 中删除所有空行(这也是如此)并在底部添加一个新行。

IMO,请尝试跳过 jsFunction 调用,而是让相同的东西作为 f:ajaxa4j:ajax 执行。 (未经测试的)代码可能如下所示...

<h:inputText id="answerID"  value="#{dataItem.answerId}"
                        onchange="<yourValidationFunction>">
    <a4j:ajax execute="@this"
            render="ansChoiceList addDiscQuest applyDiscQuest"
            actionListener="#{DiscQuestMgtController.addEmptyRow}"
            oncomplete="focusToNewCell('DiscQuestMgtForm',#{fn:length(DiscQuestMgtController.answerChoiceList)});">
    </a4j:ajax>
</h:inputText>

这样,您可以将 ID 与要在服务器端更新的值保持一致。

希望它能起作用并有所帮助......

【讨论】:

  • 感谢 TONNN.. 它确实有效.. 我添加了执行属性.. :) @L-Ray
  • 酷 ...'nd thnx 的反馈。
猜你喜欢
  • 1970-01-01
  • 2012-11-15
  • 1970-01-01
  • 1970-01-01
  • 2014-10-14
  • 1970-01-01
  • 2012-07-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多