简体   繁体   English

JSF:如何使用selectOneRadio立即更新后备bean?

[英]JSF: How to use selectOneRadio for immediate update of backing bean?

I have a choice of four locations, presented as a "selectOneRadio". 我可以选择四个位置,显示为“ selectOneRadio”。 When I select one location, the bean gets updated when I click to one of the 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>

What do I have to change when I want an immediate change of the backing bean when I click on a radio button? 当我想单击单选按钮时立即更改备用bean时,我必须更改什么?

Any help is very appreciated. 任何帮助都非常感谢。

To perform the submit at the time of click, you need to use Ajax. 要在单击时执行提交,您需要使用Ajax。

For JSF 1.2, that means you need to use one of the many ajax frameworks for JSF (like richfaces with A4J). 对于JSF 1.2,这意味着您需要为JSF使用许多ajax框架之一(例如A4J的richfaces)。

For JSF 2.x, it's built-in. 对于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>

This will submit the form as soon as the radio button is clicked. 单击单选按钮后,将立即提交表单。 You can also specify which fields to process, and which to rerender. 您还可以指定要处理的字段,以及要重新渲染的字段。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM