[Oracle ADF] Создание и вызов javascript в бине


Hello World Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;

import org.apache.myfaces.trinidad.render.ExtendedRenderKitService;
import org.apache.myfaces.trinidad.util.Service;


****

public void onFirstButtonPressed(ActionEvent actionEvent) {

    System.out.println("Buton 1 Begin");

    String buttonId = "pt1:analysis_fragment:pt1:some_other_region:dc_ctb2";

    FacesContext context = FacesContext.getCurrentInstance();

    StringBuilder script = new StringBuilder();

    script.append("alert('HELLO!'); ");

    System.out.println("Result " + script.toString());

    ExtendedRenderKitService erks = Service.getService(context.getRenderKit(), ExtendedRenderKitService.class);
    erks.addScript(context, script.toString());

    System.out.println("Buton 2 END");

}


Next Step

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
public void onFirstButtonPressed(ActionEvent actionEvent) {


    System.out.println("Buton 1 Begin");

    String buttonId = "pt1:analysis_fragment:pt1:some_other_region:dc_ctb2";

    FacesContext context = FacesContext.getCurrentInstance();

    StringBuilder script = new StringBuilder();


    script.append("var comp1 = AdfPage.PAGE.findComponentByAbsoluteId('").append(buttonId).append("'); ");       

    script.append("alert(comp1); ");

    System.out.println("Result " + script.toString());

    ExtendedRenderKitService erks =
                            Service.getService(context.getRenderKit(), ExtendedRenderKitService.class);
                        erks.addScript(context, script.toString());


    System.out.println("Buton 2 END");

}

Добиваемся, чтобы на экране появилось сообщение вида:

AdfRichButton [oracle.adf.RichButton] id = <some_id>


Next Step

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
public void onFirstButtonPressed(ActionEvent actionEvent) {


    System.out.println("Buton 1 Begin");

    String buttonId = "pt1:analysis_fragment:pt1:some_other_region:dc_ctb2";

    FacesContext context = FacesContext.getCurrentInstance();

    StringBuilder script = new StringBuilder();

    script.append("var comp1 = AdfPage.PAGE.findComponentByAbsoluteId('").append(buttonId).append("'); ");       

    script.append("var actionEvent = new AdfActionEvent(comp1); ");
    script.append("actionEvent.forceFullSubmit(); ");
    script.append("actionEvent.noResponseExpected(); ");
    script.append("actionEvent.queue(); ");

    System.out.println("Result " + script.toString());

    ExtendedRenderKitService erks =
                            Service.getService(context.getRenderKit(), ExtendedRenderKitService.class);
                        erks.addScript(context, script.toString());


    System.out.println("Buton 2 END");

}

Что конкретно делают, forceFullSubmit(), noResponseExpected() не знаю. Потому, что быдлокодер.


Помогло:

https://community.oracle.com/thread/2326406?tstart=0


Еще примеры: