使用p:ajax禁用并重新启用文本字段后,primefaces水印消失

时间:2014-09-26 06:15:04

标签: ajax jsf primefaces

我在p:selectOneRadio中使用p:ajax of primefaces来禁用和重新启用表单输入文本字段。这些文本字段的水印在禁用后会消失,即使重新启用它们也不会出现。我无法弄清楚这个问题。请帮忙。它出现的代码块如下所示

<h:outputText 
   value="#{msg['elicense.contractorLicenseForm.personal.licenseApplied']}"/>
<p:selectOneRadio id="licenseApplied" 
                  value="#{contractorLicenseBean.licenseApplied}">
    <f:selectItem itemLabel="Yes" itemValue="1" />
    <f:selectItem itemLabel="No" itemValue="0"/>
    <p:ajax update="licensePersonName, relationshipPersonName" />
</p:selectOneRadio>
<h:outputText value="When it is yes, it should skip to supervisor details"/>

<h:outputText 
   value="#{msg['elicense.contractorLicenseForm.personal.licensePersonName']} "/>
<p:inputText id="licensePersonName" 
             value="#{contractorLicenseBean.licensePersonName}" 
             required="true" 
             label="LicensePersonName" 
             disabled="#{contractorLicenseBean.licenseApplied=='1'}"/>
<p:watermark for="licensePersonName" 
             value="Person/firm/company on whose Favour License is Sought " 
             id="watermark2" />

<h:outputText 
   value="#{msg['elicense.contractorLicenseForm.personal.relationshipPersonName']} "/>
<p:inputText id="relationshipPersonName" 
             value="#{contractorLicenseBean.relationshipPersonName}" 
             required="true" 
             label="RelationshipPersonName" 
             disabled="#{contractorLicenseBean.licenseApplied=='1'}" />
<p:watermark for="relationshipPersonName" 
             value="Relationship of the Applicant " 
             id="watermark3" />

2 个答案:

答案 0 :(得分:1)

在加水印的组件周围使用h:panelGroup并更新h:panelGroup而不是组件 Primefaces通过JQuery将水印绑定到组件。如果您更改/更新组件,则绑定到该组件的事件将不起作用,这可能是您的问题的原因。

答案 1 :(得分:0)

我使用了primefaces 5.0,我遇到了你的问题。当我将p:inputText放入p:panelGrid并更新panelGrid时。问题消失了。

    <h:form>
        <p:messages id="messages" showDetail="true"/>

        <p:selectOneRadio id="radio" value="#{watermarkView.radio}">
            <f:selectItem itemLabel="Yes" itemValue="1" />
            <f:selectItem itemLabel="No" itemValue="0"/>
            <p:ajax process="radio" update="panelGridInput" />
        </p:selectOneRadio>
        <h:panelGrid id="panelGridInput" 
                     columns="3" cellpadding="5" 
                     style="margin-bottom:10px">
            <h:outputLabel value="Search: "/>
            <p:inputText id="keyword" 
                         value="#{watermarkView.keyword}"
                         required="true" 
                         label="Keyword"
                         disabled="#{watermarkView.radio eq '1'}"/>
            <p:watermark for="keyword" 
                         value="Search with a keyword" 
                         id="watermark" />

            <h:outputLabel value="Search: "/>
            <p:inputText id="keyword2" 
                         value="#{watermarkView.keyword2}"
                         required="true" 
                         label="Keyword"
                         disabled="#{watermarkView.radio eq '1'}"/>
            <p:watermark for="keyword2" 
                         value="Search with a keyword" 
                         id="watermark2" />
        </h:panelGrid>

        <p:commandButton id="regular" 
                         actionListener="#{watermarkView.search}" 
                         value="Regular" 
                         ajax="false" /> 
        <p:commandButton id="ajax" 
                         actionListener="#{watermarkView.search}" 
                         value="Ajax" 
                         onclick="PrimeFaces.cleanWatermarks();" 
                         oncomplete="PrimeFaces.showWatermarks();" 
                         update="messages" />
    </h:form>