0
I have the following question: How JSF works with Javascript ?
I’ll be more specific. I’m in a project where I’m using JSF (primefaces), but I can’t do anything simple with Javascript, which would be a
var btnCarregaAnexo = document.querySelector('carregaAnexo')
btnCarregaAnexo.style.display = 'none'
Shows an error in the console, that the variable btnCarregaAnexo
this "null"
.
But in the button
I’m trying to catch, you’re with "id" = carregaAnexo;
I’ve also tested with getElementById
, but without success...
So conclusion, does JSF (primefaces) or Jboss, which I’m using, interfere with the ID’s path? I can’t possibly catch a component with JS...
Thank you, I’m sorry if I didn’t express myself in the best way, but I’m willing to talk to you.
I changed to perform the 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
What position did you put this script in? At the head or end of the body?
– Laerte
Put your code
– Roknauta
Well, I don’t know what your knowledge of Javascript, but, this is not how the
querySelector
works, by your example the correct would be querySelector('#loaded').– LeAndrade
So Leandrade, I also tested with '#' but it presents same error, I posted just below with an attempt to get by the CSS class, but it presents the same error in the console... Laerte the script is at the end of body ! , but I have also tested with the script at the beginning of body, I also tried to put the script in another file... and import it into html, but always same error...
– Bruno Passos
Jsf component ids are generated dynamically. You would need to define a class and use findByClassName.
– Giuliana Bezerra
vc did not consider using the upload component of primefaces files?
– Adriano Gomes
Adrianogomes, I’m using the prime upload component, but the version of prime qe utilizo is an older version, and this version is not accessible (visually impaired)... And I want to try to make it accessible using Avascript, but even the basics are not working, I do not know if Jboss interferes, or primefaces is not letting me get components cm JS.
– Bruno Passos
You’re trying to do something via javascript that I think is easier via EL. What exactly do you need to do? Control the rendering of commandButton?
– Marcus Martins