将默认值设置为h:按钮单击时选择选项

时间:2013-04-01 05:03:47

标签: java javascript jsf selectonemenu

我在按钮点击时显示输出面板,它有一个selectonemenu项目,默认选择值1,当我更改某个值并单击CANCEL按钮并重新打开输出面板时,将显示最后一个选定的值。有没有办法显示默认值“1”...提前感谢

<a4j: outputPanel id="new"> 

<h:selectOneMenu id="menuID" value="#{myController.count}" immediate="true"> 
<f:selectItem itemLabel="1" itemValue="1" /> 
<f:selectItem itemLabel="2" itemValue="2" /> 
<f:selectItem itemLabel="3" itemValue="3" /> 
<f:selectItem itemLabel="4" itemValue="4" /> 
<f:selectItem itemLabel="5" itemValue="5" /> 
<f:selectItem itemLabel="6" itemValue="6" /> 
<f:selectItem itemLabel="7" itemValue="7" /> 
<f:selectItem itemLabel="8" itemValue="8" /> 
<f:selectItem itemLabel="9" itemValue="9" /> 
<f:selectItem itemLabel="10" itemValue="10" /> 
</h:selectOneMenu></td> 

<div id="popActionButtons"> 
<h:commandLink value="cancel" onclick="return closePoUpWindow(this);" /> 

<c1:ajaxCommandButton id="save" title="Save" 
onclick="return vailidatesav();" 
value="save" validationType="required" 
eventType="click" styleClass="inputButton" /></div> 
</div> 
</a4j: outputPanel>

2 个答案:

答案 0 :(得分:0)

您可以在面板打开时重置“#{myController.count}”吗?问题是你在selectOneMenu上放了immediate =“true”,所以在点击取消按钮时,表单就会被提交,所有过程如验证,转换,更新模型都会出现在“应用请求值”阶段。这就是你看到最后一个价值的原因。因此,要么从selectOneMenu中删除immediate =“true”并将其置于取消按钮,要么必须在按钮单击时重置“#{myController.count}”,这将打开面板。

答案 1 :(得分:0)

检查以下案例中的问题

1.我认为您使用<t:savestate>此变量计数 ..如果是这种情况,请删除。
 2.检查bean weather的构造函数,为此变量 count 设置任何值。

如果不是这种情况,你最好使用java脚本我建议

  1. 页面的onload将默认值设置为下拉列表。
  2. 使用 onclick 事件取消按钮并调用java函数将drop box值设置为1 ..