我有以下JSF单选按钮:
<h:selectOneRadio id="journeyDir"
value="#{refParam.journeyDir}">
<f:selectItems value="#{newMessage.journeyDirectionSelectItemList}" />
</h:selectOneRadio>
用户可以选择的单选按钮的值在此Java方法中定义:
public List<SelectItem> getJourneyDirectionSelectItemList() {
final List<SelectItem> journeyDirectionSelectItemList = new ArrayList<SelectItem>();
journeyDirectionSelectItemList.add(new SelectItem(Journey.BIDIRECTION,
YES));
journeyDirectionSelectItemList.add(new SelectItem(Journey.ONEWAY, NO));
return journeyDirectionSelectItemList;
}
现在我遇到了问题,通过加载JSF网页,将自动选择在上面的Java方法中声明的单选按钮的第一个值。我有要求,系统不能自动选择任何值。
我该如何解决这个问题?有任何想法吗?我使用JSF 1.2。
答案 0 :(得分:1)
确保您的journeyDir
变量设置为null
答案 1 :(得分:0)
只需在yourController.java
@PostConstruct
public void postConstruct() {
// ....
// initialize journeyDir by setting its default value
// Note you must write ONLY one of next lines
refParam.journeyDir = null; // if you need to unchecked all choices
refParam.journeyDir = YES; // if you need to checked first choice
refParam.journeyDir = NO; // if you need to checked second choice
// ....
}
注意:你必须小心这一点 控制器中没有其他代码稍后更改其默认值 直到第一次加载屏幕页面