1

i have renderd checkboxes. when i select checkbox that checkbox value shoud be displayed in panel.i have written code for this but not worked

                              <h:selectManyCheckbox id="chkedition" value="#{newspaperBean.selectedEditions}" layout="lineDirection" styleClass="nostyle">
                                  <f:selectItems value="#{newspaperBean.searchEditionByNewspaper()}" var="item" itemLabel="#{item.editionName}" itemValue="#{item.editionName}"/>
                                  <f:ajax render="display" event="select"/>
                              </h:selectManyCheckbox>
                          </td>
                        </tr>
                            <tr>
                                <td colspan="2">
                                    <p:panel id="display" header="You have selected">
                                    <c:forEach items="#{newspaperBean.selectedEditions}" var="it">
                                        <h:outputText value="#{it}"/><br/>
                                    </c:forEach>
                                    </p:panel>
                                </td>
                            </tr>

this worked when i submit form but i want that when i select checkbox.

Digma Chauhan
  • 185
  • 1
  • 4
  • 15

1 Answers1

1

Remove the event="select" attribute. This is the incorrect event to hook on. It's only triggered when you select any text in input fields and textareas, not when you click the checkbox.

<f:ajax render="display" />

The default event is already valueChange which will resolve to click in checkboxes and this is exactly what you need. You can if necessary explicitly specify it by event="click", but as said, it's the default value already, so just omit it.

Another potential problem is the <c:forEach> in the panel. This will fail if the bean is view scoped because it runs during view build time and get its own separate instance of the view scoped bean which may not contain the submitted data. You'd need to use <ui:repeat> instead.

<ui:repeat value="#{newspaperBean.selectedEditions}" var="it">
    <h:outputText value="#{it}"/><br/>
</ui:repeat>

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • thanks for giving reply. it works but it needs page refresh everytime for update the panel – Digma Chauhan Jun 06 '12 at 16:06
  • What JSF impl/version are you using? The `` is at least suspicious as it doesn't work well when the bean is view scoped. You'd need to use `` instead of ``. – BalusC Jun 06 '12 at 16:14
  • jsf 2.0 . bean is session scoped – Digma Chauhan Jun 06 '12 at 16:20
  • how to display preview of the content in jsf? preview should be display when i writing content in inputTextArea. – Digma Chauhan Jun 12 '12 at 03:41
  • Please press the `Ask Question` button if you need to ask a new question. – BalusC Jun 12 '12 at 03:44
  • Then give your question and the English language a bit more attention and love. Stack Overflow is a professional Q&A site, not some kind of a teenage chatbox :) Use the shift key wisely (in English, every sentence starts with an uppercase and the word "I" and the abbreviation "JSF" is also to be written uppercased). Write words full out (thus not stupidly "u", but maturely "you"). Also make sure that the question title summarizes the concrete problem properly in a single sentence (and thus not "help i am problem" or something silly). – BalusC Jun 12 '12 at 03:52