Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6470689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:08:22+00:00 2026-05-25T06:08:22+00:00

I’ve found various examples in jsf where folks have done this successfully; in these

  • 0

I’ve found various examples in jsf where folks have done this successfully; in these examples, the person had used to display a dynamic list of checkboxes.

I am trying to do things slightly different by building a HtmlPanelGrid with my checkboxes, then displaying that HtmlPanelGrid on the page. The checkboxes appear on the screen just like they would if I had used the path.

The problem occurs when I try to capture the values from the checkboxes to see if they were checked or not. I had initialized the ‘responses’ array values to ‘false’. After I submit the form with a few of the checkboxes selected, I view the database and it saved all of the values as false (when there should have been a few that were ‘true’).

Hopefully my code snippets can help identify what I am doing wrong:

Snippet from the displayForm.xhtml:

     <h:form id="form_selection_test">

      <!--  Display the prompt -->
      <h3>
      <h:outputText id="selection_prompt" value="#{testBean.prompt}"></h:outputText>
      </h3>

      <!-- Display the selection - the type of selection will vary based on misc criteria -->
      <h:panelGrid binding="#{myBean.testSelectionGrid}">
      </h:panelGrid>

      <br/><br/>
      <h:commandButton id="selection_form_submit" type="submit" value="Submit!" action="#{myBean.processSelection}"/>

     </h:form>

Snippet from myBean.java

public HtmlPanelGrid getTestSelectionGrid() 
 {
      myGrid = new HtmlPanelGrid();
      myGrid.setColumns(2);
      List children = myGrid.getChildren();

      // get application from faces context
      FacesContext facesInstance = FacesContext.getCurrentInstance();
      Application app = facesInstance.getApplication();
      ExpressionFactory expFactory = app.getExpressionFactory();

      int numChoices=choices.size();   //choices is the array containing the values for each selection option

      responses.clear(); //clear any old values out of the array;

      //initialize the response array (also a part of myBean) - this is supposed to capture the items the user selects
      for(int initAns=0;initAns<numChoices;initAns++)
      {
            responses.add("false");
      }

      /*
      *
      *  Other selection types (non-checkbox)
      *  These other selection types seem to work fine with capturing user responses
      *
      */

      if (selectionToDisplay =="multipleChoiceCheckbox")
      {
       HtmlSelectManyCheckbox checkboxPanel = new HtmlSelectManyCheckbox();
          checkboxPanel.setLayout("pageDirection");

          checkboxPanel.setValue("#{myBean.responses}");

          Map<Object,Object> checkChoiceList = new HashMap<Object,Object>();

          for (int i=0;i<numChoices;i++)
          {               
              Object choiceValueExpression= expFactory.createValueExpression(facesInstance.getELContext(),"#{question.responses["+i+"]}",String.class).getValue(facesInstance.getELContext());
              checkChoiceList.put("TEST["+i+"]"+choices.get(i),"true");//choiceValueExpression);
          }

          UISelectItems checkboxList = new UISelectItems();
          checkboxList.setValue(checkChoiceList);
          checkboxPanel.getChildren().add(checkboxList);

          children.add(checkboxPanel);
      }//end of if that checks if we're supposed to display MultipleChoiceCheckbox


      return myGrid;
 }

I’ve been playing with all sorts of permutations, but this has been the closest I’ve gotten so far. It looks like at least now the group of checkboxes is being properly associated with my ‘respnoses’ array, but I still cannot get it to capture each individual checkbox’s value into the corresponding array element.

Any suggestions and/or ideas of where I can look or start?

Thank you in advance!
Cliff

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T06:08:23+00:00Added an answer on May 25, 2026 at 6:08 am

    Whenever you create UIInput or UICommand components dynamically in the bean, you must supply your own component ID instead of letting JSF to autogenerate one.

    checkboxPanel.setId("someIdWhichIsUniqueWithinUIForm");
    

    This way JSF will be able to find the submitted values. Also, you should not recreate the component on every getter call. Assign the created component to an instance variable and add an if check which only creates it whenever it is null.

    public HtmlPanelGrid getTestSelectionGrid() {
        if (myGrid == null) {
            myGrid = new HtmlPanelGrid();
            // ...
        }
    
        return myGrid;
    }
    

    Unrelated to the concrete problem, have you considered a tag file or a composite component which utilizes the rendered attribute to show/hide different input types? Creating components programmatically isn’t a really nice approach with regard to reusability and maintainability. Here are some links which should give some basic ideas:

    • How to make a grid of JSF composite component?
    • How to create dynamic JSF form fields
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.