Call a method via datatable rows

0

Given my datatable below:

<p:dataTable id="tabela" var="linha" value="#{naturemb.lista}" paginator="true" rows="10" rendered="#{not empty naturemb.lista}" >
                    <p:column styleClass="botoesGrid">
                    <p:commandButton icon="ui-icon-pencil" action="#{naturemb.editar(linha.id)}" process="@this" update="cadastro,pesquisa" ajax="false"/>
                    <p:commandButton icon="ui-icon-trash" action="#{naturemb.excluir(linha)}" ajax="true" process="@this">
                    <p:confirm header="#{msg['cabecalho.apagar.registro']}" message="#{msg['apagar.registro']}" icon="ui-icon-alert"/>
                    </p:commandButton>
                    <p:confirmDialog global="true" showEffect="exploud" hideEffect="fade">
                        <p:commandButton value="Sim" type="button" styleClass="ui-confirmdialog-yes" icon="ui-icon-check"/>
                        <p:commandButton value="Não" type="button" styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
                    </p:confirmDialog>
                    </p:column>
                    <p:column headerText="#{msg['nome']}" sortBy="#{linha.nome}" style="width:12%;">
                        <h:outputText value="#{linha.nome}" />
                    </p:column>

I am creating a method so that if there are some specific words inside the lines, they will have different formatting. How do I call the method that will do this check in <h:outputText ? Or would not it be what I call the method?

    
asked by anonymous 14.06.2016 / 00:10

1 answer

1

For various styles you could create a method in the bean that returns the styleClass according to the passed value:

.base{
    background-image: none !important;
    font-weight: bold;
    width: 100%!imporant;
    height: 100%!imporant;
}
.base .atack{
    color: blue !important;
}
.base .foo{
    color: yellow !important;
}
.base .bar{
    color: red !important;
}

and no bean

private static final String ATACK = "atack";
  private static final String FOO = "foo";
  private static final String BAR = "bar";    
  public String getStyle(String val){         
      if(val.toLowerCase().contains(ATACK))
          return ATACK;       
      else if(val.toLowerCase().contains(FOO))
          return FOO;         
      else if(val.toLowerCase().contains(BAR))
          return BAR;         
      return "";
  }

no xhtml

<p:column **styleClass="base"**>
   < h:outputText value="#{var.nome}" styleClass="#{seuBean.getStyle(var.nome)}"/>
</p:column>
    
14.06.2016 / 13:40