Reputation: 788
I need reload a JSF component when press a key, i have the following code
<script>
document.onkeypress=teclaPulsada
function teclaPulsada()
{
var teclaASCII=event.keyCode
var teclaCHAR=String.fromCharCode(teclaASCII)
if (teclaASCII==49 )
{
document.getElementById("formularioImagen").setAttribute("value", "TiffBean.getImagen()")
}
else if ( teclaASCII==50)
{
alert("disminuir")
}
}
</script>
<h:form id="formularioImagen">
<p:graphicImage id="imagen" value="#{TiffBean.getImagen()}" width="1000" height="1500" border="5" cache="FALSE" >
</p:graphicImage>
</h:form>
when I run the image no reload
Upvotes: 1
Views: 1740
Reputation: 20691
Use the Primefaces hotkey. It's purpose-built for this. In your case:
<h:form id="formularioImagen">
<p:graphicImage id="imagen" value="#{TiffBean.getImagen()}" width="1000" height="1500" border="5" cache="FALSE" >
</p:graphicImage>
<p:hotkey bind="ctrl+shift+s" update="imagen"/>
</h:form>
Upvotes: 0
Reputation: 1053
you can use p:remoteCommand
for it.
<p:remoteCommand name="refreshImage" process="@this" update="formularioImagen:imagen"/>
and in your javascript code, you can do the following:
if (teclaASCII == 49)
{
refreshImage();
}
Upvotes: 2
Reputation: 3846
You'll want to "re-render" the graphicImage component or one of its parents. An easy way would be to add
<p:commandButton id="hiddenBtn" update="formularioImagen:imagen" style="visibility: hidden"/>
to the form and have your Javascript select and click the button when a key is click
Upvotes: 1