1

I have a managed bean which contains a list of ids. When I iterate through that list using a data table, I use a h:selectBooleanCheckbox and assign the id value to it like this:

<h:selectBooleanCheckbox value = "#{managedBean.objectMap[<objectKey>]}">

However, after the page is rendered, I don't see the value attribute being rendered. So I wanted to know why it is not being rendered?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Sujay DSa
  • 1,172
  • 2
  • 22
  • 37
  • Hi, please read [ask] and [mcve] and http://www.stackoverflow.com/tags/jsf/info and improve your question accordingly – Kukeltje Nov 08 '15 at 10:37

1 Answers1

3

However, after the page is rendered, I don't see the value attribute being rendered. So I wanted to know why it is not being rendered?

Because it's not relevant in order to trigger a Boolean. Just the request parameter being null or non-null depending on HTML checked state is sufficient to represent a Boolean. The <h:selectBooleanCheckbox> doesn't support non-Boolean values anyway.

If you're absolutely positive you need a checkbox value, use either <h:selectManyCheckbox> with only a single item.

<h:selectManyCheckbox value="#{bean.selectedValues}">
    <f:selectItem itemValue="#{bean.someValue}" itemLabel="#{null}" />
</h:selectManyCheckbox>

Or if it's actually for JavaScript purposes (I'm just guessing because you confusingly tagged on a JSF question without explaining its relevance anywhere), then you could also use a HTML5 data attribute which you can set as passthrough attribute (requires JSF 2.2).

<html ... xmlns:a="http://xmlns.jcp.org/jsf/passthrough">
...
<h:selectBooleanCheckbox value="#{bean.someBoolean}" a:data-value="#{bean.someValue}" />

It'll be available in JS as below:

var value = element.dataset.value;

Or jQuery:

var value = $(element).data("value");

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555