JSF and JavaScript

0

I have the following question: How does JSF work with JavaScript?

I'll be more specific. I'm working on a project with JSF (primefaces), but I can not seem to do something simple with JavaScript, which would be a

var btnCarregaAnexo = document.querySelector('carregaAnexo')
btnCarregaAnexo.style.display = 'none'

It displays an error in the console, that the btnCarregaAnexo variable is "null" .

But in the% w / w I'm trying to get, it has% w / o%

I've also tested with button , but to no avail ...

So in conclusion, does JSF (primefaces) or JBoss, which I'm using, interfere with ID's path? I can not get a component with JS ...

Thank you, sorry if I did not express myself in the best way, but I am willing to talk.

I changed to perform selection by CSS classes and the error persists ...

XHTML

<p:commandButton id=“carrega1” styleClass="botaoAnexo"
value="Carregar Declaração"
title="Carregar Declaração e/ou Diploma de Conclusão do Ensino Médio"
onclick=“editarArquivo1.show();“
rendered=”#{empty atletaCidadaoController.atletaCidadao.tipoArquivo1}”/>

JavaScript

var btnCarregaAnexo = document.querySelector('botaoAnexo');
            btnCarregaAnexo.style.display ='block';

CSS

.botaoAnexo{
    display: none;
}

CONSOLE ERROR

Uncaught TypeError: Cannot read property ‘style’ of null
    
asked by anonymous 03.10.2018 / 21:27

1 answer

0

If you need to control the style of a component, try to use EL. The example below displays a gray-scale div if it is waiting for closure ( controlador.aguardandoEncerramento is a boolean):

<h:panelGroup id="pnlFoto">
    <ui:param name="escalaDeCinza" value="#{controlador.aguardandoEncerramento ? 'filter: grayscale(1);' : ''}" />
    <p:outputPanel style="height: 100%; background: url(/imagens/user.gif) no-repeat center center fixed; background-size: cover; #{escalaDeCinza}" />
</h:panelGroup>

In this case, it is only necessary to update the pnlFoto to change the style.

    
10.10.2018 / 19:15