Search code examples
jsf-2inputprimefacescompare

Compare multiple input fields


I have following form:

enter image description here

I can add an answer with the add-button, so it is possible to create a question with more than two answers.

Also I have a pie chart of the results:

enter image description here

You can see my problem, do you? The piechart put my two answer options to one..

How can I check if one or more answers are the same?


Solution

  • PieChartModel make use of a LinkedHashMap to store the chart data, where your answers are the keys and the votes the values, thus you cannot have the same answer-option multiple times in a piechart.

    What you can do is e.g.

    • use a HashMap in your ManagedBean to store thw answer-Options as well. This way the dubplicate answers will be ignored and only saved once, when you save your question
    • check during the creation of a question if there are duplicate answers and throw a validation error
    • ...

    There are many ways to handle this, basicly depending on the exact behavior you want to implement.


    See also: PieChartModel.java