Skip to Main Content

Java Development Tools

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

set focus to a button when user tabs out of input field using javascript

Muhammad.RizwanDec 4 2014 — edited Dec 18 2014

Hi,

I am using jdev 11.1.2.4.

I am following the link from Frank Nimphius to notify the server and have setup client/server events in my page.

https://blogs.oracle.com/jdevotnharvest/entry/how_to_notify_the_server

I want when user press tab the focus goes to the save button

pastedImage_6.png

but instead it goes to the tab of the browser (as shown below)

pastedImage_7.png

I've amended Frank's code as

public void onBlurNotify(ClientEvent clientEvent) {

   RichInputText inputTxt =  (RichInputText) clientEvent.getComponent(); 

    //Get access to the payload

   Map  parameters = clientEvent.getParameters();

   System.out.println("SubmittedValue = "+parameters.get("submittedValue"));

   System.out.println("LocalValue =  "+parameters.get("localValue"));

   // additional code to set the focus to save button

   FacesContext fctx = FacesContext.getCurrentInstance();

    UIViewRoot viewRoot = fctx.getViewRoot();

    UIComponent component=null;

    component = viewRoot.findComponent("pt1:cbSave");

    if (component != null) {

        String clientId = component.getClientId(fctx);

    if (clientId != null) {

        StringBuilder script = new StringBuilder();

        //use client id to ensure component is found if located in the naming container

        script.append("var component = ");

        script.append("AdfPage.PAGE.findComponentByAbsoluteId");

        script.append("('" + clientId + "');");

        script.append("if(component != null){");

        script.append("component.focus();");

        script.append("}");

       writeJavaScriptToClient(script.toString());

    } else {

        System.out.println("No clientId found for component " + component.getId());

    }

    } else {

        System.out.println("No Component found.");

}

}

when I run in the debug mode, it finds the component/client ids which means that the code seems to be working but for some reason not setting the focus.

please help.

This post has been answered by dvohra21 on Dec 5 2014
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 15 2015
Added on Dec 4 2014
15 comments
3,456 views