2014-10-07 21 views
1

一個JSF標籤,我需要重新加載JSF組件時按一個鍵,我有以下代碼重裝用JavaScript

<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> 

當我運行的圖像沒有重裝

回答

1

你會想「再-render「graphicImage組件或其父母之一。一個簡單的方法是將

<p:commandButton id="hiddenBtn" update="formularioImagen:imagen" style="visibility: hidden"/> 

添加到窗體,並有你的Javascript選擇並點擊按鈕時的一個關鍵就是點擊

+0

您好,感謝您的回答,但我需要的是像「重新渲染」時,按一個鍵,我不能使用的按鍵 – oriaj 2014-10-07 19:53:19

+0

@oriaj「有你的Javascript選擇並點擊按鈕當一個鍵被點擊時「答案的一部分引用你的案例,但由於沒有提供適用的例子,你可以在這裏看看關於選擇組件:http://stackoverflow.com/questions/7927716/how-到選-primefaces-UI-或-JSF的組件 - 使用-jquery的 – 2014-10-08 11:15:47

1

你可以使用p:remoteCommand它。

<p:remoteCommand name="refreshImage" process="@this" update="formularioImagen:imagen"/> 

,並在你的JavaScript代碼,你可以做到以下幾點:

if (teclaASCII == 49) 
{ 
    refreshImage(); 
} 
0

使用Primefaces hotkey。這是專門爲此製作的。你的情況:

<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>