是否有办法在JSF 2.0中使用AJAX来获取鼠标所在的单词(甚至在outputText组件上也可以)?
我的目标是把这个词存储在一个bean变量上(比如说#{bean.selectedWord}),以便用于进一步的操作。
到目前为止,我只能得到输入文本元素的全部值......。我想知道我是否也必须使用jQuery。
page.xhtml
<h:inputText id = "myIinput" value="this is a test">
<f:ajax event="mouseover" render="myOutput" execute="myInput"
listener="#{bean.ajaxFunction}"/>
</h:inputText>
<h:outputText id ="myOutput" value="#{bean.selectedWord}" />
bean.java
String selectedWord;
public void ajaxFunction(AjaxBehaviorEvent event) {
UIComponent uic = event.getComponent();
String output = (String) uic.getAttributes().get("value");
myOutput = output ;
}
public String getSelectedWord(){
return selectedWord
}
普通的JSF和我知道的任何组件套件都没有这样的组件。所以实际上你需要把你的问题一分为二。
将两者结合起来,你就有了解决方案。但是不要忘记在悬停中添加一个延迟,这样就不是每次qucik悬停都是emd,只是在用户暂停的时候。