2014-02-06 25 views
1

我必須驗證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

回答

1

。當你錯誤地輸入表單時,'流程驗證'階段將產生一個錯誤,這意味着'更新模型值'階段沒有被執行,因此ViewScoped bean中的值仍然是您輸入時所輸入的原始值正確的形式,並且這是呈現視圖時重新顯示的值。

+0

我猜,我沒有進入更新模型值,因爲我從來沒有提交表單沒有錯誤。 我最好的猜測是UIComponents在驗證失敗後使用localValue。所以看起來,舊值被保存在「應用請求值」階段並在驗證失敗時使用。 這實際上對我來說似乎有點奇怪的行爲,因爲我,用戶,告訴該字段是空的.. – GregD

0

該問題位於,雖然不是固定的,因爲可能的修復(將context-param設置爲false)可能不會發生。我猜這種行爲可以被看作是JSF中的一個錯誤?

在Web XML:

<context-param> 
    <param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-n‌​ame> 
    <param-value>false</param-value> 
</context-param>