我有以下代码:
<h:form id="formId">
<h:inputHidden id="x" value="#{userBean.x}" />
<h:inputHidden id="y" value="#{userBean.y}" />
<h:selectBooleanCheckbox event="click" listener="#{userBean.submit}" />
</h:form>
<script>
function getVars() {
var x = 10;
var y = 20;
document.getElementById("formId:x").value = x;
document.getElementById("formId:y").value = y;
}
</script>
,ManagedBean代码如下:
public class UserBean {
public int x;
public int y;
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
public void submit() {
System.out.println("x: " + x);
System.out.println("y: " + y);
// ...
}
在复选框的点击事件中我想要x
&amp;的值要传递给托管bean文件的y
个变量。怎么做?