How to show Yes and No instead of 0 and 1 in java?

Asked

Viewed 58 times

-1

I’m caught in this problem, I need to show Yes and No in the xhtml table instead of 0 and 1, the return type in get and set is Bigdecimal and the shapes I tried always end up breaking or not running because I want to put a String in place, what would be the best way to do that?

this is the method to record the data in the front table: (the change I want to make would be in the record[3])

private ContaFornecedorVO getContaFornecedor(Object[] record) {
    
    String validar;
    ContaFornecedorVO vo = new ContaFornecedorVO();
    vo.setCodigoConta(((BigDecimal) record[0]).longValue());
    vo.setDsConta((String) record[1]);
    vo.setNrContaSap((BigDecimal) (record[2]));
    vo.setFlagAbatimentoOrigem((BigDecimal) (record[3]));   

    return vo;
}

the data type in the VO:

private BigDecimal flagAbatimentoOrigem;

the shape that the column is on the front:

<p:column id="flag" style="width:50px" styleClass="columnRight">
    <f:facet name="header">
        <h:outputText value="Flag Abatimento" />
    </f:facet>
    <h:outputText value="#{tbl.flagAbatimentoOrigem}" />
</p:column>

1 answer

2


Since the display possibilities are for Yes or Not, you could put two outputText varying their display by means of the attribute rendered as follows:

  <p:column id="flag" style="width:50px" styleClass="columnRight">
                                            <f:facet name="header">
                                                <h:outputText value="Flag Abatimento" />
                                            </f:facet>
                                            <h:outputText value="Sim" rendered="#{tbl.flagAbatimentoOrigem == 1}"/>
                                            <h:outputText value="Não" rendered="#{tbl.flagAbatimentoOrigem == 0}"/>
                                        </p:column>

A more elaborate way of resolving it would be with the use of converter, but for the situation would not find it necessary.

  • THANK YOU!!! was trying to do this in the backend a couple of days ago and had caught, bigDecimal is kind of boring to work, it worked perfectly!!

Browser other questions tagged

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