Validate text before going to the screen

Asked

Viewed 95 times

1

I got 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 does the research:

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

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

  • Related question: http://answall.com/q/165762/132

  • @Victorstafusa I’m not very experienced yet on the site.. This has problem ?

  • No, not a problem. The idea is to guide who will answer the question or then analyze it under some other aspect know where to look for more information.

  • I get it, thank you :)

2 answers

2


Your problem seems to be on a strange course, if I understand what you need, this answer solves.

  • That does not need algorithms because jsf already has a property to treat that.
  • Something else will need to save the formatting as if you recover the data from the database, it will not be shown in second moment.
  • The property is: escape="false"

Take an example

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

Upgrade to your context.

  • I didn’t understand the value part, just remembering that some words will be formatted only...

  • Value is a property, in this case the outputLabel, but it depends on what you’re using, it’s the field value, in jsf usually looks like this for example, value=#{seu_bean_manage.name}

  • Did it work? marks the answer that solved to have problem, to help other people

1

in your outputText you can set a variable with already formatted text...

In your bean you create a String textFormated.

uses the same logic as the checkTipo pro string value method

then outputText value="#{youBean.textFormated}

If not, I hope I have given a light rsrs

  • What would be the code to go through my list ?

  • for (Typopokemon type: list) { system.out.println(type.values()); } ?

Browser other questions tagged

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