<h:form>
<h:selectManyMenu id="carsList"
value="#{bean.carList}"
style="width:400px; height:100px" label="List">
<f:selectItems value="#{bean.cars}" var="i"
itemLabel="#{i.code}" itemValue="#{i.Name}" />
<f:selectItem itemLabel="Other" itemValue="other"/>
<f:ajax event="change" execute="@this" render="othermodel"/>
</h:selectManyMenu>
<br></br>
<h:panelGroup id="othermodel">
<h:outputText value="Others:" style="margin-top:10px;color:red;font-weight:bold;"
rendered="#{bean.carList.contains('other')}" />
<h:inputText size="50" id="otherinput" required="true"
rendered="#{bean.carList.contains('other')}"/>
<h:message for="otherinput"></h:message>
</h:panelGroup>
<h:commandButton value="Next" action="#{bean.submitForm}"/>
</h:form>
我的 bean 是requestScoped
,当我carList
有一个值时,other
我可以显示,panelGrid
但是当用户没有在使用呈现的输入字段中输入任何值时AJAX
,即使我指定required=true
了但它没有得到验证。并且在后端代码中输入文本框的值为空。
如何对使用渲染的输入字段进行验证AJAX
,为什么我的值为 null?我正在使用 JSF 2.0