How to update only tab title in p:tabView /p:accordion or similar component?

前端 未结 2 1410
萌比男神i
萌比男神i 2021-01-23 15:26

I am trying to make the title of some tabs underlined if some specific content is shown on that tabs using ajax update (just titles, nothing else). Currently it works only if I

相关标签:
2条回答
  • 2021-01-23 15:42

    You cannot update individual tabs since they do not have renderers in PrimeFaces. What you can try is to move the title to a f:facet name="title"..., put an h:outputText id="tabIdTitle"... and update that outputText when required. This is supported since PF 3.2. So something like

    <p:tabView id="m_tabview" widgetVar="m_tabviewWv" scrollable="false">
      <p:tab title="Basic information">
        <h:form id="base_form">
          <!-- Some form data with submit button -->
        </h:form>
      </p:tab>
      <p:tab id="documentsTab" name="documentsTab">
        <f:facet name="title">
           <h:outputText id="documentsTabTitle" value="#{clientform.documentsHeaderInline}" />
        </f:facet>
        <h:form id="documents_form">
          <!-- Some form data with submit button -->
        </h:form>
      </p:tab>
      <p:tab title="Social data">
        <h:form id="social_data_form">
          <!-- Some form data with submit button -->
        </h:form>
      </p:tab>
      <p:tab id="contactsTab">
        <f:facet name="title">
          <h:outputText id="contactsTabTitle" value="#{clientform.contactsHeaderInline} "/>
        </f:facet>
        <h:form id="сontacts_form">
          <!-- Some form data with submit button -->
        </h:form>
      </p:tab>
    </p:tabView>
    
    0 讨论(0)
  • 2021-01-23 15:42

    Thanks to Kukeltje and Geinmachi!

    The right way is really to use a facet (but with CSS style separately because if you use CSS inline, the tags will be shown as is and text won't be underlined):

    <p:tab id="documentsTab" name="documentsTab">
      <f:facet name="title">
        <h:outputText id="documentsTabTitle" value="Documents" style="#{clientform.documentsHeaderInline}"/>
      </f:facet>
    ...
    </p:tab>
    

    and (in managed bean if necessary):

    documentsHeaderInline = "text-decoration: underline;";
    
    0 讨论(0)
提交回复
热议问题