Guest User

Untitled

a guest
Oct 17th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1. package com.magicpigeon.adf.util;
  2.  
  3. import javax.faces.context.FacesContext;
  4.  
  5. import oracle.adf.view.rich.component.rich.RichPopup;
  6.  
  7. import org.apache.myfaces.trinidad.render.ExtendedRenderKitService;
  8. import org.apache.myfaces.trinidad.util.Service;
  9.  
  10. /**
  11. * Class that contains utility methods for manipulating the client-side
  12. * rich components in server-side code using the Extended render Kit Services
  13. */
  14. public final class RichClientUtils {
  15.  
  16. /**
  17. * Default Constructor
  18. */
  19. private RichClientUtils() {
  20. }
  21.  
  22. /** Show popup window.
  23. * @param popup The popup to be shown
  24. * @param alignId If specified, align after end with this id.
  25. * If null, no alignment is configured (and by default the popup will open
  26. * in the middle of the browser window).
  27. */
  28. public static void showPopup(RichPopup popup, String alignId) {
  29. FacesContext context = FacesContext.getCurrentInstance();
  30. String popupClientId =
  31. popup.getClientId(FacesContext.getCurrentInstance());
  32.  
  33. // Send Javascript to the client to open the popup window, since
  34. // opening an <af:popup> is totally on the client side.
  35. StringBuilder script = new StringBuilder();
  36. script.append("var popup = AdfPage.PAGE.findComponent('").append(popupClientId).append("'); ").append("if (!popup.isPopupVisible()) { ").append("var hints = {}; ");
  37. if (alignId != null) {
  38. script.append("hints[AdfRichPopup.HINT_ALIGN_ID] = '").append(alignId).append("'; ").append("hints[AdfRichPopup.HINT_ALIGN] = AdfRichPopup.ALIGN_AFTER_END; ");
  39. }
  40. script.append("popup.show(hints);}");
  41. ExtendedRenderKitService erks =
  42. Service.getService(context.getRenderKit(),
  43. ExtendedRenderKitService.class);
  44. erks.addScript(context, script.toString());
  45.  
  46. }
  47.  
  48. /**
  49. * Hides the popup given by parameter
  50. * @param popup
  51. */
  52. public static void hidePopup(RichPopup popup) {
  53. FacesContext context = FacesContext.getCurrentInstance();
  54. String popupClientId = popup.getClientId(context);
  55. StringBuilder script = new StringBuilder();
  56. script.append("var popup = AdfPage.PAGE.findComponent('").append(popupClientId).append("'); ").append("popup.hide();");
  57. ExtendedRenderKitService erks =
  58. Service.getService(context.getRenderKit(),
  59. ExtendedRenderKitService.class);
  60. erks.addScript(context, script.toString());
  61. }
  62.  
  63. /**
  64. * Write JavaScript to the Client
  65. * @param script
  66. */
  67. public static void writeJavaScriptToClient(String script) {
  68. FacesContext fctx = FacesContext.getCurrentInstance();
  69. ExtendedRenderKitService erks =
  70. Service.getRenderKitService(fctx, ExtendedRenderKitService.class);
  71. erks.addScript(fctx, script);
  72. }
  73.  
  74. }
Add Comment
Please, Sign In to add comment