使用AJAX渲染组件

时间:2013-09-16 10:06:20

标签: jquery ajax jsf

我有HTML/JSF形式的以下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保持可见,没有任何迹象。有没有人知道出了什么问题?

1 个答案:

答案 0 :(得分: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