【问题标题】:Rendering a component using AJAX使用 AJAX 渲染组件
【发布时间】:2013-09-16 10:06:19
【问题描述】:

我在JSF 表单中有以下HTML/JSF 元素:

<div class="btn-group" data-toggle="buttons-radio">
    <h:commandButton type="button" styleClass="btn btn-inverse" value="One Way"><f:ajax render="flexibleDates" listener="#{searchFlightsBean.setDirectionOneWay}"/></h:commandButton>
    <h:commandButton type="button" styleClass="btn btn-inverse" value="Round Trip"><f:ajax render="flexibleDates" listener="#{searchFlightsBean.setDirectionRoundtrip}"/></h:commandButton>
</div>

<h:panelGrid columns="2" id="flexibleDates" rendered="#{searchFlightsBean.directionInd.label == 'Return'}">
    <h:selectBooleanCheckbox value="#{searchFlightsBean.flexibleDates}" styleClass="flight-results-left-padding checkbox inline"/>
    <h:outputText value="+/- 3 days"/>
</h:panelGrid>

我在后端 bean 中有这样的代码:

public void setDirectionOneWay(AjaxBehaviorEvent event)
{
    this.directionInd = DirectionInd.ONEWAY;
    log.info("setting direction to oneway " + directionInd.label);
}

public void setDirectionRoundtrip(AjaxBehaviorEvent event)
{
    this.directionInd = DirectionInd.RETURN;
    log.info("setting direction to return " + directionInd.label);
}

日志反映代码运行良好。

但是,应该被渲染的panelGrid 保持可见,没有显示任何迹象。有谁知道出了什么问题?

【问题讨论】:

  • @Daniel 谢谢,这就是我需要的解决方案!

标签: jquery ajax jsf


【解决方案1】:

您应该将包装器添加到该 h:panelGrid 并在您的 f:ajax 中指向它,而不是原来的 h:panelGrid

例如:

<f:ajax render="flexibleDatesWrapper"...


<h:panelGroup id="flexibleDatesWrapper">
    <h:panelGrid columns="2" id="flexibleDates" rendered="#{searchFlightsBean.directionInd.label == 'Return'}">
        <h:selectBooleanCheckbox value="#{searchFlightsBean.flexibleDates}" styleClass="flight-results-left-padding checkbox inline"/>
        <h:outputText value="+/- 3 days"/>
    </h:panelGrid>
</h:panelGroup>

阅读此question/answer

【讨论】:

  • 感谢您的详细说明。我读了另一个问题,但没有完全理解。我应该像您在代码中所说的那样在ajax元素中使用render,还是应该使用update? (只是想清楚)
  • 不客气,你应该使用render。在另一个问题中,用户正在使用 primefaces 库,其中他们使用 p:ajax 和 update 属性而不是 render 和 process 而不是 execute 但想法是一样的(使用包装器并指向它)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-04-20
  • 2011-12-12
  • 1970-01-01
  • 2011-04-14
  • 1970-01-01
  • 2019-02-19
  • 1970-01-01
相关资源
最近更新 更多