hello all ,
inspiration from the use case which have encountered in last days , i decide to share my learning
inspiration from the use case which have encountered in last days , i decide to share my learning
Today's Discussion :
the use case is pretty simple that
"How can we use Enter key instead of Tab key in af:form in ADF application just like in Oracle forms "
so here is the simple and brief solution about this use case
i will use java script function and client listener for this
i am using jdeveloper Studio Edition Version 11.1.2.3.0 11gR2
step 1:
first of all create the simple application base on HR Schema and cretae the Employees view object and based on employees entity and then drag it as Form on page just like below
step 2:
now go to page source and paste this javascript code :
<af:resource type="javascript">
function myonkeypressbookdate(componentEvent)
{
var evt = componentEvent.getNativeEvent();
var keyCode = AdfAgent.AGENT.getKeyCode(evt);
if (AdfAgent.AGENT.getKeyCode(evt) == 13) // 13 is ENTER
{
AdfFocusUtils.focusNextTabStop(componentEvent.getNativeEventTarget());
}
}
</af:resource>
step 3
now back to the design mode of page and select one of inputtext from form and then drag
af:clientlistener from component pallet set the properties as below:
for example i have seleted firstName and set the property as
<af:inputText value="#{bindings.FirstName.inputValue}" label="#{bindings.FirstName.hints.label}"
required="#{bindings.FirstName.hints.mandatory}"
columns="#{bindings.FirstName.hints.displayWidth}"
maximumLength="#{bindings.FirstName.hints.precision}"
shortDesc="#{bindings.FirstName.hints.tooltip}" id="it2">
<f:validator binding="#{bindings.FirstName.validator}"/>
<af:clientListener method="myonkeypressbookdate" type="keyPress"/>
</af:inputText>
or as in figure:
now run the page press CreateInsert , the focus will be on FirstName ,
Press Enter key insted of tab , you will see the focus navigate to next Inputtext for example Last Name
:)
Note:
but for using Enter Key for all input text we have to write the class which cretae client listener to all inputtext present on page
just a 2 step more ,
Now for all input text
Step 1:
cretae java class from gallery which impliments PagePhaseListener
as
This will create a class name as Onpage in view ,
Step 2:
now add the below code of class in class
as
package view;
import java.util.Iterator;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import oracle.adf.controller.v2.lifecycle.Lifecycle;
import oracle.adf.controller.v2.lifecycle.PagePhaseEvent;
import oracle.adf.controller.v2.lifecycle.PagePhaseListener;
import oracle.adf.view.rich.component.rich.input.RichInputText;
public class Onpage implements PagePhaseListener {
public Onpage() {
super();
}
@Override
public void afterPhase(PagePhaseEvent pagePhaseEvent) {
if (pagePhaseEvent.getPhaseId() == Lifecycle.PREPARE_RENDER_ID) {
addClientListener(FacesContext.getCurrentInstance().getViewRoot());
}
}
@Override
public void beforePhase(PagePhaseEvent pagePhaseEvent) {
}
private void addClientListener(UIComponent component) {
Iterator<UIComponent> i = component.getFacetsAndChildren();
while (i.hasNext()) {
UIComponent child = (UIComponent) i.next();
if (child instanceof RichInputText){
oracle.adf.view.rich.event.ClientListenerSet appliedCL = ((RichInputText)child).getClientListeners();
if (appliedCL == null) {
appliedCL = new oracle.adf.view.rich.event.ClientListenerSet();
System.out.println("in seelct inputtext");
((RichInputText)child).setClientListeners(appliedCL);
}
appliedCL.addListener("keyPress", "myonkeypressbookdate");
}
addClientListener(child);
} // of while
}
}
Step 3:
now go to ViewController/META-INF/adf-settings in application navigator and in its source paste this lines
<adf-config xmlns="http://xmlns.oracle.com/adf/config">
<adfc-controller-config xmlns="http://xmlns.oracle.com/adf/controller/config">
<lifecycle>
<phase-listener>
<listener-id>Onpagee</listener-id>
<class>view.Onpage</class>
</phase-listener>
</lifecycle>
</adfc-controller-config>
</adf-config>
thats all , run the pae and you will see at this time you can use Enter Key Instead of Tab On Web Page . :) :)
you feed back will be an asset for me ,
further more Share and Like :) :)
Regards:
ZeeShan Ali
No comments:
Post a Comment