【问题标题】:JSF 1.1 - How to get the ID attribute of h:selectBooleanCheckbox in backing beanJSF 1.1 - 如何在支持 bean 中获取 h:selectBooleanCheckbox 的 ID 属性
【发布时间】:2017-12-28 10:17:45
【问题描述】:

所以,这里是 jsf 组件:

<h:selectBooleanCheckbox id="cb#{index}" value="backingBean.value" />

这是支持bean java的一部分:

/**
 * getValue is a method which checks if a checkbox is selected or not, using the checkbox ID
 */
public boolean getValue() { 
  //TODO: get the checkbox id
  String checkboxID = ??

  if (getCheckedIDs().contains(checkboxID)) {
    return true;
  }

  return false;
}

当页面加载复选框时,我想以这种方式检查复选框是否被选中。 那么问题来了,要写什么而不是 ?? 来获取调用该方法的复选框的 ID? 我只能使用 JSF 1.1 非常重要,因此有很多解决方案不适用于此版本。

【问题讨论】:

  • value="backingBean.value" 错误...应该是`value="#{backingBean.value}"

标签: jsf jsf-1.1


【解决方案1】:

编辑:正如@Kukeltje 正确指出的那样,主要问题是值表达式不正确。更改后,以下内容适用。

您无需“计算”复选框的值(“设置”或“取消设置”)。 JSF 将简单地调用 backingbean.setValue(x)xtruefalse),具体取决于当时复选框是打开还是关闭(即当您提交页面时)。

这是自动发生的,因为你说的是​​value="#{backingBean.value}"

所以在setValue() 中您只需存储参数,在getValue 中您返回存储的参数。其余的由 JSF 为您完成。

如果您希望复选框默认打开,请将存储的值设置为 true。

例如:

private boolean storedValue = true;  // or false if you want it to be off by default

public boolean getValue() {
  return storedValue;
}

public void setValue(boolean value) {
  this.storedValue = value;
}

【讨论】:

  • value="backingBean.value" 错了...应该是value="#{backingBean.value}"
猜你喜欢
  • 2018-06-11
  • 2012-03-15
  • 2011-06-29
  • 1970-01-01
  • 1970-01-01
  • 2012-04-01
  • 1970-01-01
  • 2011-06-26
  • 1970-01-01
相关资源
最近更新 更多