Tuesday, May 31, 2011

ADF 11g Quicky 2 - Set Focus on MouseOver Event

Another Quick solution here. What if I want to set focus on a field without actually having to click it ? This can be done by using a clientListeners and some java script code.

1:  <?xml version='1.0' encoding='UTF-8'?>  
2: <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
3: xmlns:f="http://java.sun.com/jsf/core"
4: xmlns:h="http://java.sun.com/jsf/html"
5: xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
6: <jsp:directive.page contentType="text/html;charset=UTF-8"/>
7: <f:view>
8: <af:document>
9: <af:resource type="javascript">
10: function makeActive(event){
11: event.getSource().focus();
12: }
13: </af:resource>
14: <af:form id="f1">
15: <af:inputText label="Label 1" id="it1">
16: <af:clientListener type="mouseOver" method="makeActive"/>
17: </af:inputText>
18: <af:inputText label="Label 2" id="it2"/>
19: </af:form>
20: </af:document>
21: </f:view>
22: </jsp:root>



When the user hovers the first input text field, the field gets focus and the user can start (or continue) typing.

Easy as that.

No comments: