我必須驗證h:inputText是否有值。在那裏,我在該組件上使用了required =「true」。它完成這項工作,並且工作,但是然後發生了一些奇怪的事情。JSF inputText的值在清除後重新出現
當我將其留空時,會發生required =「true」。當我在inputText中鍵入一些文本時,不會發生required =「true」。當我在添加文本之後刪除文本時,會發生required =「true」,但之前輸入的值會重新出現在inputText中。
我真的不知道這可能是什麼。請注意,當我說「required =」true「」時,我的意思是inputText的邊框變爲紅色(請參閱代碼)。
下面是代碼:
<h:form id="generateLetterForm">
<h:panelGroup id="submitterPanel">
<h:panelGrid styleClass="rSplitPanel1" columns="1">
<e:inputText entityBB="#{entityBB}" type="#{type}"
property="submitterFirstName" />
<e:inputText entityBB="#{entityBB}" type="#{type}"
property="submitterLastName" />
</h:panelGrid>
<h:panelGrid styleClass="rOnePanel" columns="1">
<h:panelGroup>
<h:outputText value="#{AppMessages[type.concat('.address')]}"
styleClass="Fieldname" />
<h:panelGrid columns="3" cellpadding="2" cellspacing="0"
styleClass="Fieldcontent"
columnClasses="rAddressStreet, rAddressStreetNr, rAddressBoxNr">
<h:panelGroup>
<h:inputText id="submitterStreetName"
value="#{entityBB.entity.address.street}" required="true" styleClass="#{component.valid ? '' : 'addressError'}" />
<rich:tooltip target="submitterStreetName">
<h:outputText
value="#{AppMessages[type.concat('.submitterStreetName')]}" />
</rich:tooltip>
</h:panelGroup>
"2 other similar columns" (would make code to complex for the problem)
</h:panelGrid>
</h:panelGroup>
</h:panelGrid>
</h:panelGroup>
<a4j:commandButton value="#{AppMessages['general.action.save']}"
actionListener="#{entityBB.createStandardLetter()}"
render="generateLetterForm messages letterExistsPanel"
status="ajaxStatus" styleClass="floatRight"/>
</h:form>
編輯:第一2輸入文本字段(E:inputText的)是我自己的組件。那裏沒有什麼問題。當你輸入正確的值存儲在ViewScoped豆屬性形式
的支持bean是ViewScoped
我猜,我沒有進入更新模型值,因爲我從來沒有提交表單沒有錯誤。 我最好的猜測是UIComponents在驗證失敗後使用localValue。所以看起來,舊值被保存在「應用請求值」階段並在驗證失敗時使用。 這實際上對我來說似乎有點奇怪的行爲,因爲我,用戶,告訴該字段是空的.. – GregD