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

3 Answers 3

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();
}
Sign up to request clarification or add additional context in comments.

Comments

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

2 Comments

HI, thanks for your answer but I need that the image "re-render" when press a key, I can't use buttons
@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: stackoverflow.com/questions/7927716/…
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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.