[英]Call java method in JSF/xhtml by keyPress and update form
Hi I got school project to code game in JSF but I struggle o lot with keyboard. 嗨,我有一个学校项目要用JSF编写游戏代码,但是我在键盘方面很费劲。
I want to call method moveCubeUp()
from cubefield to move UP if user press keyboard UP and then update form and do this to all 4 directions. 我想从多维数据集字段调用方法
moveCubeUp()
来向上移动,如果用户按下键盘UP,然后更新窗体并将其执行到所有4个方向。
I tried javascripts, jQuery, primefaces hotkey 我尝试了javascript,jQuery,primefaces热键
This is in my xhtml: 这是在我的xhtml中:
<div class="game">
<h:form id="form">
<g:cuberoll value="#{cubefield}"/>
Cube X: <h:outputLabel value="#{cubefield.getCubeX()}"/>
Cube Y: <h:outputLabel value="#{cubefield.getCubeY()}"/>
</h:form>
</div>
and cubefield: 和cubefield:
@Named("cubefield")
@SessionScoped
public class Field implements Serializable{
public Field() {
... constructor
}
public void moveCubeRight(){
... do stuff
}
I think you can try to trigger it with ajax. 我认为您可以尝试使用Ajax触发它。 It should look like this :
它应该看起来像这样:
`<f:ajax event="onkeypress" execute="keyCode" listener="#{bean.listener}" />`
Then you can get the key in an hidden input. 然后,您可以在隐藏的输入中获取键。
`<h:inputHidden id="keyCode" binding="#{keyCode}" value="#{bean.keyCode}" />`
This topic is related to what you are asking : Catch KeyCode in AjaxBehaviorEvent of JSF 2 本主题与您的要求有关: 在JSF 2的AjaxBehaviorEvent中捕获KeyCode
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.