1

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

oriaj
  • 768
  • 1
  • 16
  • 33

3 Answers3

2

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();
}
tt_emrah
  • 1,043
  • 1
  • 8
  • 19
1

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

Ali Cheaito
  • 3,746
  • 3
  • 25
  • 30
  • HI, thanks for your answer but I need that the image "re-render" when press a key, I can't use buttons – oriaj Oct 07 '14 at 19:53
  • @oriaj "have your Javascript select and click the button when a key is click" part of the answer refers to your case, but since there is no applicable example provided, you can have a look at here about selecting the component: http://stackoverflow.com/questions/7927716/how-to-select-primefaces-ui-or-jsf-components-using-jquery – tt_emrah Oct 08 '14 at 11:15
0

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>
kolossus
  • 20,559
  • 3
  • 52
  • 104