2013-07-30 47 views
-1
<a4j:outputPanel id="tapalSectionSendToPanel" ajaxsingle="true"> 
    <h:inputText id="sendToId1" value="#{MainBean.SectionBean.sendTo}" 
     class="createresizedTextbox" 
     required="true" requiredMessage="#{msg.labl_required}" 
     disabled="true" /> 
<h:message for="sendToId1" style="color:red" /> 
</a4j:outputPanel> 

驗證失敗我需要驗證文本框空驗證和應顯示當我點擊按鈕而不在文本框中輸入任何值所需。它工作正常,沒有disabled="true"。什麼是我的要求的替代方案。爲什麼需要=不「真」而不是當禁用=「true」是指定

+0

您有衝突的要求:'禁用=「真正的」'不會允許用戶輸入任意值,它會爲任何事情比其他的顯示被忽略。那麼,爲什麼你想在這裏附上驗證器? – mabi

+0

另外,在JSF中有幾個無效屬性:'autosubmit','showRequired','requiredMessage'在這裏不會做任何事情,'class'可能應該是'styleClass'。 – mabi

+0

我已經刪除了驗證器和最新的問題與我的jsf –

回答

3

disabled="true"禁止輸入(所以表單提交時它跳過),如果你不希望用戶在其中鍵入使用readonly="readonly"

4

首先,requireddisabled不順利在一起,因爲它們是按照所述JSF Spec互斥:

  • 需要:指示用戶需要提供此輸入分量的提交的值標誌。
  • 已禁用:指示此元素絕不會獲得焦點或被包含在後續提交中的標誌。

就像我在評論中說,你可以當用戶試圖提交表單,而不選擇一個節點只顯示一條消息:

<h:inputText id="sendToId1" value="#{MainBean.SectionBean.sendTo}" 
    styleClass="createresizedTextbox" required="true" readonly="true" /> 
<h:message for="sendToId1" value="#{msg.labl_required}" 
    rendered="#{facesContext.postback and facesContext.validationFailed}" /> 

作爲替代你可以只顯示文本的任何地方您的標記:

<h:outputText value="#{msg.labl_required}" 
    rendered="#{empty MainBean.SectionBean.sendTo}" /> 
相關問題