JSF:如何使用selectOneRadio立即更新支持bean?

时间:2012-06-15 13:38:33

标签: java jsf

我可以选择四个位置,显示为“selectOneRadio”。当我选择一个位置时,当我点击其中一个commandLinks时,bean会更新。

<ui:composition template="/WEB-INF/templates/BasicTemplate.xhtml">
    <ui:define name="content">
    <h:form>
    <h:commandLink action="#{wrapper.goBack}" value="GESTERN"></h:commandLink>
    ---------
    <h:commandLink action="#{wrapper.goForward}" value="MORGEN"></h:commandLink>
    <br />
    <h:selectOneRadio id="locationSelection" value="#{wrapper.actualLocation}" >
        <f:selectItems value="#{wrapper.allLocations}" var="actualLocation" ></f:selectItems>
    </h:selectOneRadio>
</h:form>    
</ui:define>
</ui:composition>

当我想要在单击单选按钮时立即更改支持bean时,我需要更改什么?

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

要在单击时执行提交,您需要使用Ajax。

对于JSF 1.2,这意味着你需要使用JSF的许多ajax框架之一(就像带有A4J的richfaces)。

对于JSF 2.x,它是内置的。

<ui:composition template="/WEB-INF/templates/BasicTemplate.xhtml">
    <ui:define name="content">
    <h:form>
    <h:commandLink action="#{wrapper.goBack}" value="GESTERN"></h:commandLink>
    ---------
    <h:commandLink action="#{wrapper.goForward}" value="MORGEN"></h:commandLink>
    <br />
    <h:selectOneRadio id="locationSelection" value="#{wrapper.actualLocation}" >
        <f:selectItems value="#{wrapper.allLocations}" var="actualLocation" ></f:selectItems>
        <f:ajax event="click" />
    </h:selectOneRadio>
</h:form>    
</ui:define>
</ui:composition>

单击单选按钮后,将立即提交表单。 您还可以指定要处理的字段以及要重新渲染的字段。

请参阅:http://mkblog.exadel.com/2010/04/learning-jsf-2-ajax-in-jsf-using-fajax-tag/