JSF 1.1-如何在备用Bean中获取h:selectBooleanCheckbox的ID属性 [英] JSF 1.1 - How to get the ID attribute of h:selectBooleanCheckbox in backing bean

查看:123
本文介绍了JSF 1.1-如何在备用Bean中获取h:selectBooleanCheckbox的ID属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,这是jsf组件:

So, here is the jsf component:

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

这是支持bean java的一部分:

And here is a part of the backing 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,这一点非常重要,因此有许多解决方案不适用于该版本.

When the page is loading the checkboxes, I want to check this way if the checkbox is selected or not. So the question is, what to write instead of ?? to get the ID of the checkbox who called the method? It's very important that I can use only JSF 1.1, so there are many solutions which won't work with this version.

推荐答案

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

as @Kukeltje correctly notes, the main issue is that the value expression is incorrect. Once you change that, the below is applicable.

您不需要计算"复选框的值(设置"或未设置"). JSF会简单地调用backingbean.setValue(x)(xtruefalse),具体取决于该复选框是在打开还是关闭时(即提交页面时).

You don't need to "calculate" the value ("set" or "unset") of your checkbox. JSF will simply call backingbean.setValue(x) (with x being true or false) depending on whether the checkbox is on or off at that moment (i.e. when you submit the page).

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

This happens automatically because you said value="#{backingBean.value}".

因此,在setValue()中,您只需存储参数,在getValue中,您返回存储的参数.其余的工作由JSF为您完成.

So in setValue() you simply store the argument, in getValue you return the stored argument. The rest is done by JSF for you.

如果您希望默认情况下选中此复选框,则将存储的值设置为true.

If you want the checkbox to be on by default, you set the stored value to 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;
}

这篇关于JSF 1.1-如何在备用Bean中获取h:selectBooleanCheckbox的ID属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆