1

I am currently trying to use an h:selectOneMenu to get Input from the User. When the User submits the form the user either gets to the same page again or to a different page. As long as the user always picks the first option available everything is fine, but as soon as he picks another one the component with id=selection1 is complaining: Validation error - value is not valid.

Here is the form:

 <h:form styleClass="form-horizontal">
                    <div class="form-group">
                        <div class="col-sm-offset-2 col-sm-8">
                            <div class="checkbox">
                                <label><h:selectBooleanCheckbox value="#{startBean.abstainFromItem}"></h:selectBooleanCheckbox>Bei dieser Frage enthalten</label>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <ui:fragment rendered="#{startBean.currentItem.type != 'M_OF_N'}">
                            <h:outputLabel for="selection1" styleClass="col-sm-2" value="Option(en) auswählen:"/>
                            <div class="col-sm-8">
                                <h:selectOneMenu value="#{startBean.buffer[0]}" styleClass="form-control" id="selection1">
                                    <f:converter converterId="javax.faces.Integer"/>
                                    <ui:param name="iValue" value="0"/>
                                    <c:forEach items="#{startBean.currentItem.options}" var="option1">
                                        <f:selectItem itemLabel="#{option1.title}" itemValue="#{iValue}"/>
                                        <ui:param name="iValue" value="#{iValue + 1}"/>
                                    </c:forEach>
                                </h:selectOneMenu>
                                <h:message for="selection1"/>
                            </div>
                        </ui:fragment>
                        <ui:fragment rendered="#{startBean.currentItem.type == 'M_OF_N'}">
                            <h:outputLabel for="selection2" styleClass="col-sm-2" value="Option(en) auswählen:"/>
                            <div class="col-sm-8">
                                <h:selectManyMenu styleClass="form-control" id="selection2" value="#{startBean.buffer}">
                                    <f:converter converterId="javax.faces.Integer"/>
                                    <ui:param name="lValue" value="0"/>
                                    <c:forEach items="#{startBean.currentItem.options}" var="option2">
                                        <f:selectItem itemLabel="#{option2.title}" itemValue="#{lValue}"/>
                                        <ui:param name="lValue" value="#{lValue + 1}"/>
                                    </c:forEach>
                                </h:selectManyMenu>
                            </div>
                        </ui:fragment>
                    </div>
                    <ui:debug/>
                    <ui:fragment rendered="#{startBean.index lt startBean.count}">
                        <div class="form-group">
                            <div class="col-sm-offset-2 col-sm-8">
                                <h:commandButton styleClass="btn btn-primary" value="Nächstes Item" action="submitvote">
                                    <f:actionListener binding="#{startBean.nextItem()}"/>
                                </h:commandButton>
                            </div>
                        </div>
                    </ui:fragment>
                    <ui:fragment rendered="#{startBean.index == startBean.count}">
                        <div class="form-group">
                            <div class="col-sm-offset-2 col-sm-8">
                                <h:commandButton styleClass="btn btn-primary" value="Stimmzettel abgeben" action="index">
                                    <f:actionListener binding="#{startBean.submit()}"/>
                                </h:commandButton>
                            </div>
                        </div>
                    </ui:fragment>
                </h:form>

There are various answers to similiar problems, but they all make use of the f:selectItems tag while I do not. Nor do i think i need to implement an equals method.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
jmohrs
  • 11
  • 2
  • Your case is not different. If you're however absolutely sure that your case is different, by all means create and provide a [MCVE](http://stackoverflow.com/tags/jsf/info) (and you'll during a real learning exercise soon figure out that it's after all indeed your mistake and already answered in the abovelinked duplicate). – BalusC Oct 02 '15 at 08:40
  • I looked at various answers before. However, the answers did not explain why submitting the form partly works. To me it seems, that in other cases none of the selected values would work. (BTW, where did i write that it is not my mistake?) – jmohrs Oct 02 '15 at 10:38
  • The selected item is not part of the available items. Really, that is it. You have a lot of conditional building and rendering in your code. The chance is big that the conditions have changed during processing the form submit. This matches #1 cause in the abovelinked duplicate. Just create a MCVE to naildown the conditional fail. – BalusC Oct 02 '15 at 10:43

0 Answers0