0

Maybe this question was asked a lot but not in the same way so here is my problem and I hope someone can help.

After having retrieved some research rows from database and returned the results into a List which I have bound to the my Spring MVC Controller Model:

if(!result.hasErrors())
{
  try{
    List<Question> questionlist = questionservice.findByCategoryAndLevel(questionform.getCategory(),questionform.getLevel());
    model.addAttribute("questionlist",questionlist);
    return "addExam";
  }catch(NullPointerException e)
  {
    return "redirect:/admin/addexam";
  }
}

Here is my view:

<form:form action="addexam" method="POST" modelAttribute="questionlist">
  <table class="table table-striped table-bordered table-hover" id="sample_1">
    <thead>
      <tr>
        <th class="table-checkbox">
          <input type="checkbox" class="group-checkable" data-set="#sample_1 .checkboxes"/>
        </th>
        <th>
          Category
        </th>
        <th>
          level
        </th>
        <th>
          Type of question
        </th>
        <th>
          Status
        </th>
        <th>
          &nbsp;
        </th>
      </tr>
    </thead>
    <tbody>
      <c:forEach items="${questionlist}" var="question">
        <c:choose>
          <c:when test="${question.isVisible()}">
            <tr class="odd gradeX">
              <td>
                <input type="checkbox"  class="checkboxes" />
              </td>
              <td>
                ${question.category.getCategoryName() }
              </td>
              <td>
                ${question.level }
              </td>
              <c:choose>
                <c:when test="${question.isSingleChoiceQuestion() }">
                  <td>Question à choix unique</td>
                </c:when>
                <c:otherwise>
                  <td>Question à choix mutiple</td>
                </c:otherwise>
              </c:choose>
              <td class="center">
                <c:choose>
                  <c:when test="${question.getState() == 'Desactivated'}">
                    <span class="label label-sm label-default"> Desactivated </span>
                  </c:when>
                  <c:when test="${question.getState() == 'Activated'}">
                    <span class="label label-sm label-success"> Activated </span>
                  </c:when>
                  <c:when test="${question.getState() == 'Pending'}">
                    <span class="label label-sm label-warning"> Pending </span>
                  </c:when>
                </c:choose>
              </td>
              <td>
                <a href="${pageContext.request.contextPath }/admin/question?view=${question.idQuestion}" class="btn btn-xs btn-default" target="_blank">View</a>
              </td>
            </tr>
          </c:when>
        </c:choose>
      </c:forEach>
    </tbody>
  </table>
</form:form>

Now how do I submit the selected items?

1
  • Can you elaborate more your question, whay are you expecting? What have you done sor far to submit your form? You should provide also you controller method signatures to check the bindings. Commented Jul 7, 2014 at 12:22

2 Answers 2

1

yes i wanted to display the question list and then pick the ones i needed via a checkbox

i created a form, it holds the list of Idquestions

public class checkedquestion {

    private List<Long> listIdQuestion ;

    //getter & setter
   }

then added a path attribute to checkbox like below :

<form:form action="submit" method="POST" modelAttribute="checkedquestion">  

// .......

     <td>
        <form:checkbox  value="${question.idQuestion}" path="listIdQuestion"/>
     </td>

By submitting the list of id i have the ones i needed :

public String add(@ModelAttribute ("checkedquestion") @Valid CheckedQuestion checkedquestion , BindingResult result )
    {
        if(!result.hasErrors())
         {
                List<Long> list = checkedquestion.getListIdQuestion();
                List<Question> questionlist = questionservice.getQuestion(list);
         }
     }

it seems to work fine

Sign up to request clarification or add additional context in comments.

Comments

0

Give a id/name to input checkbox type as below

<input type="checkbox"  class="checkboxes" id="someId" name="someId" value="uniqueValueToEachCheckBox"/>

Then after submitting your form, you can able to access your selected checkbox values in your controller as below.

request.getParameterValues("someId");

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.