Validate text before going to the screen

1

I have the following dataTable :

<p:dataTable id="tabela" var="c" value="#{geracaomb.lista}" paginator="true" rows="10"
                    rendered="#{not empty geracaomb.lista}" paginatorPosition="top">
                    <p:column styleClass="botoesGrid">
                        <p:commandButton icon="ui-icon-pencil" action="#{geracaomb.editar(c.id)}" process="@this" update="cadastro,pesquisa"
                            ajax="false" />
                        <p:commandButton icon="ui-icon-trash" action="#{geracaomb.excluir(c)}" ajax="true" process="@this" update="pesquisa">
                            <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="#{c.nome}" style="width:12%;">
                        <h:outputText value="#{c.nome}" escape="false" />
                    </p:column>

And I have the following method:

public String checkTipo(String texto) {
        List<TipoPokemon> lista = Arrays.asList(TipoPokemon.values());
        String palavras[] = texto.split(" ");

        for (int i = 0; i < lista.size(); i++) {
            String tipo = lista.get(i).getNome().toLowerCase();
            for (String palavra : palavras) {
                if (palavra.toLowerCase().equals(tipo)) {
                    texto = texto.replace(palavra, "<b>"+palavra+"</b>");
                }
            }
        }

        return texto;
    }

My method that performs the search:

public void pesquisar() {
        try {
            lista = dao.findAll();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

The goal is to load the text into dataTable so that if there is any word in the text, the word is formatted, as the example will be in bold. What I need is that every time the search button is triggered, before the data goes to dataTable , be validated before, that is, how do I call my method in outputText ?

    
asked by anonymous 16.11.2016 / 16:23

2 answers

2

Your problem seems to be on a strange course, if I understood correctly what you need, this answer will solve.

  • This does not need algorithms as jsf already has a property to handle it.
  • Another thing will need to save the formatting, because if you recover the data from the database, it will not be shown secondly.
  • The property is: escape="false"

See an example

<p:outputLabel value="Valor <br /> <srtong>description<strong/>" 
               styleClass="sys-font-normal" escape="false"  />

Update to your context.

    
16.11.2016 / 17:33
1

In your outputText you can define a variable with the already formatted text ...

la in your bean you create a String textFormat.

uses the same logic as the check method Pro value of String

then in the outputText value="# {your.Bean.textoFormatado}

If it does not resolve, I hope I have given a light rsrs

    
16.11.2016 / 17:59