我想在会话范围内传递选定的单选按钮值。我的代码不起作用。
这是视图(searchPerson.xhtml):
<h:form>
<h:selectOneRadio id="searchRadio" value="#{controller.radioButtonFlag}" valueChangeListener="#{controller.selectRadioButton}" >
<f:selectItem itemValue="fachid" itemLabel="#{msg.fachId}">
<f:attribute name="radioButtonField" value="fachid" />
</f:selectItem>
<f:selectItem itemValue="vngw" itemLabel="#{msg.VNGW}">
<f:attribute name="radioButtonField" value="vngw" />
</f:selectItem>
</h:selectOneRadio>
... <h:commandButton action="#{controller.search}" value="#{msg.search}"></h:commandButton>
这是托管bean:
@ManagedBean @SessionScoped public class Controller { private String radioButtonField = "fachid"; private boolean VNGWSelected = false; public void selectRadioButton(ValueChangeEvent event){
String select = (String) event.getComponent().getAttributes().get("radioButtonField");
if(select.equals("vngw"))
VNGWSelected = true;
} public String search() {... if(!VNGWSelected){logger.info("FachID RadioButton selected."); else{... logger.info("VNGW RadioButton selected."); ...} return "personsearch"; } ...} ... }
有人可以告诉我我在这里做错了什么吗?
提前致谢。