【问题标题】:Value of t:radio not being passed to Backing Bean in Myfaces 2.1t:radio 的值未传递给 Myfaces 2.1 中的 Backing Bean
【发布时间】:2014-02-09 00:18:35
【问题描述】:

我有一个问题,即 t:radio(与 t:selectOneRadio 相关联)的值未传递给支持 bean。我们目前正在从 JSF 1.x 转换到 JSF 2.x,在 Jboss 7.2.0 上使用 MyFaces 2.1.13,并且我们确实有 2.0 版本的 Tomahawk 库。我花了几个小时尝试不同的事情来让它工作并搜索高低,但找不到遇到同样问题的其他人。我已经确定一旦检查了值,就永远不会调用 setter。

我已经提取并简化了代码,但仍然没有在 ajax 调用上传递任何内容。

<h:form id="profileReport">

    <h:messages />

    <h:panelGrid columns="2">

        <t:selectOneRadio id="selectQuestionnaire" layout="spread" required="true" 
                value="#{viewProfile.selectedQuestionnaire}">
            <f:selectItem itemValue="SC_PRE!20121212095427.0000000.059814626868021525" /> 
            <f:ajax event="click" execute="@this" render="profileReport:selectTemplate profileReport" />    
        </t:selectOneRadio>

        <h:outputLabel for="selectQuestionnaire" value="#{prmsgs.firstQuestionnaireLabel}" styleClass="labelText" />
        <t:radio index="0" for="profileReport:selectQuestionnaire" />

        <h:outputLabel for="selectTemplate" value="#{prmsgs.exploratoryProcessTemplate}:" styleClass="labelText" />
        <h:selectOneListbox id="selectTemplate" value="#{viewProfile.selectedInterpretiveProfileTemplateId}" required="#{menuNavigation.selectInterpretiveProfileActive}">
            <f:selectItems value="#{viewProfile.interpretiveProfileTemplates}"/>
        </h:selectOneListbox>
    </h:panelGrid>
</h:form>

仅出于测试目的,我已将 t:selectOneRadio 替换为 h:selectOneRadio 并调用了 setter。然后我尝试了没有 t:radio 的 t:selectOneRadio 并且成功了。所以这似乎是 t:radio 的问题,尽管我现在不确定它是什么。我知道 Icefaces 有类似的功能,但我现在不想介绍另一个完整的组件库只是为了这个单一的用途。我们正在尝试尽可能减少更改,因为这是一个非常精益的转换过程。

【问题讨论】:

  • 尝试使用 t:radio index="0" for="profileReport:selectQuestionnaire" renderLogicalId="true"。我发现这已在TOMAHAWK-1551 中解决
  • @lu4242 谢谢。我尝试添加该代码,但它并没有解决问题。仍然没有调用 setter - 我尝试使用 renderLogicalId true 和 false 只是为了看看会发生什么并且不会导致任何功能更改。
  • 尝试将 f:ajax 中的 execute="@this" 更改为 execute="@form"。可能 t:radio 中的值没有在 ajax 请求中处理。
  • @lu4242 谢谢。这似乎解决了这个问题。这里的问题是在所有必需的值都存在之前提交表单(最初来自)会使其他元素的验证失败(所有其他元素都在执行@this)。在这种情况下,单选按钮是最后选择的项目之一,因此它将在这种情况下工作。问题是,为什么 t:radio 中的值在引用自身时没有在 ajax 请求中提交?如果您将您的 cmets 添加到答案中,那么我可以将其选为正确的。

标签: jsf-2 myfaces tomahawk selectoneradio


【解决方案1】:

当使用 t:selectOneRadio layout="spread" 时,t:selectOneRadio 是一个组件,t:radio 是另一个组件,即使它们一起工作。在这种情况下,执行 ajax 请求时,生命周期会在 t:selectOneRadio 上执行,但不会在 t:radio 上执行。 f:ajax 组件不能以这种方式被覆盖,因此一旦启动,就不可能在生命周期中包含 t:radio。

【讨论】:

    猜你喜欢
    • 2011-02-02
    • 1970-01-01
    • 2011-07-20
    • 1970-01-01
    • 2019-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-25
    相关资源
    最近更新 更多