Calling a method via datatable lines

Asked

Viewed 152 times

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 within the lines there are some specific words, they will have different formatting. As I call the method that will make this check on <h:outputText ? Or is it not in him that I call the method?

1 answer

1


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

.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 in the 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 "";
  }

in xhtml

<p:column **styleClass="base"**>
   < h:outputText value="#{var.nome}" styleClass="#{seuBean.getStyle(var.nome)}"/>
</p:column>
  • Show, I’ll test and let you know if it worked. But what do the foo and the bar mean?

  • any other variable you want to inform, as if it were x and y in mathematics, but note that the check is done and returned based on the subclass of css, for example: checks if the value contains Atack and returns Atack which in turn is a subclass of css. So if you want to include say "defense" you would have to add the subclass . base . defense{ color: black ! Important; } and on the Beam include checking the same private 1º create the attribute Static final String DEFENSE = "defense"; 2º add the Else if for defense.

  • Show, I must test today and talk to you. Thank you very much.

  • Show, it worked, thank you very much.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.