【问题标题】:Getting an h:inputbox to become disabled once I checked a h:selectBooleancheckbox一旦我检查了 h:selectBooleancheckbox,就会禁用 h:inputbox
【发布时间】:2011-01-11 15:24:37
【问题描述】:

我正在尝试使“h:selectBooleanCheckbox”组件在复选框设置为 true(选中)后使另一个 h:inputbox 被禁用。

我尝试了几个版本,但都没有成功(当我选中该框时,没有任何反应)

版本 1

<f:view>
 <h:form id="MyForm">
  <h:panelGrid id="OutgoingMailPanel" styleClass="subConfigurationPanel">
   <h:panelGrid columns="1">
    <h:outputText styleClass="propertyName" value='Password' />
    <h:outputText styleClass="properyDescription" value='Password for the incoming mail server' />
    <h:inputText id="OutGoingMail" styleClass="propertyInput" value="#{email.currentOutgoingMailPassword[0]}" />
   </h:panelGrid>
   <h:panelGrid columns="1">

    <h:panelGroup>
     <h:selectBooleanCheckbox value="#{email.currentUsePasswordSameAsIncoming[0]}" 
     onclick="document.getElementById('MyForm:OutGoingMail).disable = !this.checked" />
     <h:outputText styleClass="propertyName" value='Outgoing Password Same As Incoming.' />
    </h:panelGroup>
   </h:panelGrid>
  </h:panelGrid>
 </h:form>
</f:view>

第 2 版

<f:view>
 <h:form id="MyForm">
  <h:panelGrid id="OutgoingMailPanel" styleClass="subConfigurationPanel">
   <h:panelGrid columns="1">
    <h:outputText styleClass="propertyName" value='Password' />
    <h:outputText styleClass="properyDescription" value='Password for the incoming mail server' />
    <h:inputText id="OutGoingMail" styleClass="propertyInput" value="#{email.currentOutgoingMailPassword[0]}"
     disabled="#{email.currentUsePasswordSameAsIncoming[0]}"/>
   </h:panelGrid>
   <h:panelGrid columns="1">

    <h:panelGroup>
     <h:selectBooleanCheckbox value="#{email.currentUsePasswordSameAsIncoming[0]}" >
      <a4j:support event="onclick" rerender="OutGoingMail">
     </h:selectBooleanCheckbox>
     <h:outputText styleClass="propertyName" value='Outgoing Password Same As Incoming.' />
    </h:panelGroup>
   </h:panelGrid>
  </h:panelGrid>
 </h:form>
</f:view>

两个版本都因同样的原因不能工作 - 当我选中该框时没有任何反应。 有任何想法吗? (使用 Jsf1.2、myfaces、richfaces)

谢谢!

【问题讨论】:

    标签: ajax jsf richfaces


    【解决方案1】:

    在你的 version1 中修改代码为

    document.getElementById('MyForm:OutGoingMail').disabled = this.checked

    【讨论】:

    • @Ben - 和我一样好用,确保你的代码中有三个更改,1.Closing ') 在元素 id 的末尾,2.禁用,更正,3.删除'!'
    • 谢谢。我没有检查您的解决方案,因为我使用了 2 的变体。但是为了公平。我会把它标记为答案。
    【解决方案2】:

    在版本 2 中,重新渲染应该是重新渲染

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-13
      • 2011-04-17
      • 1970-01-01
      • 2021-12-14
      • 2021-12-11
      相关资源
      最近更新 更多