2014-03-28 86 views
0

我面臨的一個問題,驗證後,JSF文本字段驗證失敗

方案之後都沒有得到更新。在選擇第一個下拉列表時,將填充第二個下拉列表,並且2個文本字段的值取決於第一個下拉選擇。

1)所以,當我從第一個下拉列表中選擇一些值,第二個下拉列表和文本字段填充適當的值。 2)當我點擊提交按鈕而沒有從第二個下拉列表中選擇值時,它顯示了預期的驗證消息。 3)現在我更改了驗證錯誤/失敗後第一個下拉的值。文本字段中的值不會根據需要更改(表示文本字段值仍顯示舊值),但第二個下拉值正在按預期更改。

注意: - 問題只有在驗證失敗後。

<span class="col1 smallRightPadding marginBtmAdDiag"> 
<rich:select defaultLabel="Select bldng" enableManualInput="true" 
id="search_bldng" 
value="#{testManagedBean.bldng.bldngID}" 
required="true" requiredMessage="#{testHome.selectBldng}"> 
<f:selectItemsvalue="#{testManagedBean.lstBldng}" var="bldngVar" 
itemValue="#{bldngVar.bldngID}" itemLabel="#{bldngVar.bldngCode}"> 
</f:selectItems> 
<a4j:ajax execute="@this" event="selectitem" 
listener="#{testManagedBean.populateFloor}" 
render="search_floor,hidSelBldng,hidSelFloor,hidSelbldngID" /> 
</rich:select> 
<h:inputHidden id="hidSelBldng" value="#{testManagedBean.bldng.bldngCode}" /> 
<h:inputHidden id="hidSelbldngID" value="#{testManagedBean.bldng.bldngID}" /> 
</span> 

<rich:select defaultLabel="Select Floor" enableManualInput="true" 
id="search_floor" 
    value="#{testManagedBean.floor.floorID}" 
required="true" 
requiredMessage="#{testHome.selectFloor}"> 
<f:selectItems value="#{testManagedBean.floorLst}" 
var="flr" itemValue="#{flr.floorID}" 
itemLabel="#{flr.floorName}"> 
</f:selectItems> 
</rich:select> 

<h:commandButton id="goButtonId" value="#{testHome.goButton}" styleClass="saveButton"> 
<a4j:ajax event="click" execute="@form" oncomplete="drawLayerFromBtn();" 
listener="#{testManagedBean.viewReport}" 
render="tableId,hidSelFloor"/> 
</h:commandButton> 

+0

我已經粘貼到清除文本框的局部值我的代碼在 – user3474541

+0

以上你指的是什麼文本字段?這裏沒有代碼中的文本字段。請花些時間來格式化您的代碼,以使其更易於閱讀。現在它只是一堆亂七八糟的文字 – kolossus

回答

0

的問題

這是典型的問題驗證錯誤後重新輸入字段的本地值。驗證失敗之後,JSF不復位被捉住了之前的驗證錯誤的字段的值,因此你看到的仍然是舊值


之所以要解決

您基本上需要自行重置這些(缺失)文本字段的值。在一個方便的地方,也許在populateFloor

if(ctxt.isValidationFailed()){ 
     UIInput textField1 = (UIInput) FacesContext.getCurrentInstance().getViewRoot().findComponent("theTextFieldId") 
     textField1.resetValue(); 
    } 

上面的代碼片段將執行僅在當前請求週期標記爲失敗,然後繼續用id="textField1"