com.vaadin.ui.JavaScript类的使用及代码示例

x33g5p2x  于2022-01-22 转载在 JavaScript  
字(8.5k)|赞(0)|评价(0)|浏览(180)

本文整理了Java中com.vaadin.ui.JavaScript类的一些代码示例,展示了JavaScript类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JavaScript类的具体详情如下:
包路径:com.vaadin.ui.JavaScript
类名称:JavaScript

JavaScript介绍

[英]Provides access to JavaScript functionality in the web browser. To get an instance of JavaScript, either use Page.getJavaScript() or JavaScript.getCurrent() as a shorthand for getting the JavaScript object corresponding to the current Page.
[中]提供对web浏览器中JavaScript功能的访问。要获取JavaScript实例,请使用Page。getJavaScript()或JavaScript。getCurrent()作为获取与当前页面对应的JavaScript对象的缩写。

代码示例

代码示例来源:origin: com.vaadin/vaadin-server

  1. /**
  2. * Executes JavaScript in this window.
  3. *
  4. * <p>
  5. * This method allows one to inject javascript from the server to client. A
  6. * client implementation is not required to implement this functionality,
  7. * but currently all web-based clients do implement this.
  8. * </p>
  9. *
  10. * <p>
  11. * Executing javascript this way often leads to cross-browser compatibility
  12. * issues and regressions that are hard to resolve. Use of this method
  13. * should be avoided and instead it is recommended to create new widgets
  14. * with GWT. For more info on creating own, reusable client-side widgets in
  15. * Java, read the corresponding chapter in Book of Vaadin.
  16. * </p>
  17. *
  18. * @param script
  19. * JavaScript snippet that will be executed.
  20. *
  21. * @deprecated As of 7.0, use JavaScript.getCurrent().execute(String)
  22. * instead
  23. */
  24. @Deprecated
  25. public void executeJavaScript(String script) {
  26. getPage().getJavaScript().execute(script);
  27. }

代码示例来源:origin: com.vaadin/vaadin-server

  1. /**
  2. * Executes the given JavaScript code in the browser.
  3. *
  4. * @param script
  5. * The JavaScript code to run.
  6. */
  7. public static void eval(String script) {
  8. getCurrent().execute(script);
  9. }

代码示例来源:origin: com.vaadin/vaadin-server

  1. public JavaScript getJavaScript() {
  2. if (javaScript == null) {
  3. // Create and attach on first use
  4. javaScript = new JavaScript();
  5. javaScript.extend(uI);
  6. }
  7. return javaScript;
  8. }

代码示例来源:origin: viritin/viritin

  1. public static void detectCookieValue(String key, final Callback callback) {
  2. final String callbackid = "viritincookiecb"+UUID.randomUUID().toString().substring(0,8);
  3. JavaScript.getCurrent().addFunction(callbackid, new JavaScriptFunction() {
  4. private static final long serialVersionUID = -3426072590182105863L;
  5. @Override
  6. public void call(JsonArray arguments) {
  7. JavaScript.getCurrent().removeFunction(callbackid);
  8. if(arguments.length() == 0) {
  9. callback.onValueDetected(null);
  10. } else {
  11. callback.onValueDetected(arguments.getString(0));
  12. }
  13. }
  14. });
  15. JavaScript.getCurrent().execute(String.format(
  16. "var nameEQ = \"%2$s=\";var ca = document.cookie.split(';');for(var i=0;i < ca.length;i++) {var c = ca[i];while (c.charAt(0)==' ') c = c.substring(1,c.length); if (c.indexOf(nameEQ) == 0) {%1$s( c.substring(nameEQ.length,c.length)); return;};} %1$s();",
  17. callbackid,key
  18. ));
  19. }

代码示例来源:origin: org.opencms/opencms-core

  1. public void run() {
  2. JavaScript.eval(
  3. "if (window.parent && window.parent."
  4. + CmsLegacyApp.VAR_IS_LEGACY_APP
  5. + ") window.parent.location.reload();");
  6. }
  7. });

代码示例来源:origin: viritin/viritin

  1. @Override
  2. public void call(JsonArray arguments) {
  3. JavaScript.getCurrent().removeFunction(callbackid);
  4. if(arguments.length() == 0) {
  5. callback.onValueDetected(null);
  6. } else {
  7. callback.onValueDetected(arguments.getString(0));
  8. }
  9. }
  10. });

代码示例来源:origin: stackoverflow.com

  1. public JavaScriptResult Example()
  2. {
  3. return new JavaScript("var response = 10");
  4. }

代码示例来源:origin: jreznot/electron-java-app

  1. private void initElectronApi() {
  2. JavaScript js = getPage().getJavaScript();
  3. js.addFunction("appMenuItemTriggered", arguments -> {
  4. if (arguments.length() == 1 && arguments.get(0) instanceof JsonString) {
  5. String menuId = arguments.get(0).asString();
  6. if ("About".equals(menuId)) {
  7. onMenuAbout();
  8. } else if ("Exit".equals(menuId)) {
  9. onWindowExit();
  10. }
  11. }
  12. });
  13. js.addFunction("appWindowExit", arguments -> onWindowExit());
  14. Page.Styles styles = getPage().getStyles();
  15. try {
  16. InputStream resource = MainUI.class.getResourceAsStream(
  17. "/org/strangeway/electronvaadin/resources/electron.css");
  18. styles.add(IOUtils.toString(resource, StandardCharsets.UTF_8));
  19. } catch (IOException ignored) {
  20. }
  21. }

代码示例来源:origin: org.opencms/opencms-core

  1. public void attach(AttachEvent event) {
  2. JavaScript.eval(VAR_IS_LEGACY_APP + " = true;");
  3. }
  4. });

代码示例来源:origin: OpenNMS/opennms

  1. @Override
  2. public void execute(final List<VertexRef> targets, final OperationContext operationContext) {
  3. final Collection<VertexRef> availableNodes = m_geoAssetProvider.getNodesWithCoordinates();
  4. final StringBuilder sb = new StringBuilder();
  5. sb.append(VaadinServlet.getCurrent().getServletContext().getContextPath());
  6. sb.append("/node-maps#search/nodeId%20in%20");
  7. final List<String> nodeIds = new ArrayList<>();
  8. for (final VertexRef ref : targets) {
  9. if (availableNodes.contains(ref)) {
  10. nodeIds.add(ref.getId());
  11. }
  12. }
  13. final Iterator<String> i = nodeIds.iterator();
  14. while (i.hasNext()) {
  15. sb.append(i.next());
  16. if (i.hasNext()) {
  17. sb.append(",");
  18. }
  19. }
  20. final String redirectUrl = sb.toString();
  21. LOG.info("redirecting to: " + redirectUrl);
  22. final UI ui = operationContext.getMainWindow();
  23. ui.getPage().getJavaScript().execute("window.location = '" + redirectUrl + "';");
  24. }

代码示例来源:origin: viritin/viritin

  1. public static void setCookie(String key, String value, String path) {
  2. JavaScript.getCurrent().execute(String.format(
  3. "document.cookie = \"%s=%s; path=%s\";", key, value, path
  4. ));
  5. }

代码示例来源:origin: org.opencms/opencms-core

  1. public void detach(DetachEvent event) {
  2. JavaScript.eval(VAR_IS_LEGACY_APP + " = false;");
  3. }
  4. });

代码示例来源:origin: org.opennms.features/vaadin-node-maps

  1. @Override
  2. public void execute(final List<VertexRef> targets, final OperationContext operationContext) {
  3. final Collection<VertexRef> availableNodes = m_geoAssetProvider.getNodesWithCoordinates();
  4. final StringBuilder sb = new StringBuilder();
  5. sb.append(VaadinServlet.getCurrent().getServletContext().getContextPath());
  6. sb.append("/node-maps#search/nodeId%20in%20");
  7. final List<String> nodeIds = new ArrayList<>();
  8. for (final VertexRef ref : targets) {
  9. if (availableNodes.contains(ref)) {
  10. nodeIds.add(ref.getId());
  11. }
  12. }
  13. final Iterator<String> i = nodeIds.iterator();
  14. while (i.hasNext()) {
  15. sb.append(i.next());
  16. if (i.hasNext()) {
  17. sb.append(",");
  18. }
  19. }
  20. final String redirectUrl = sb.toString();
  21. LOG.info("redirecting to: " + redirectUrl);
  22. final UI ui = operationContext.getMainWindow();
  23. ui.getPage().getJavaScript().execute("window.location = '" + redirectUrl + "';");
  24. }

代码示例来源:origin: com.bsb.common.vaadin/com.bsb.common.vaadin7.embed

  1. public void buttonClick(Button.ClickEvent event) {
  2. // Stop the server in a separate thread.
  3. final Thread thread = new Thread(new Runnable() {
  4. public void run() {
  5. server.stop();
  6. }
  7. });
  8. // avoid that catalina's WebappClassLoader.clearReferencesThreads warns about the thread because it is
  9. // part of the web application being stopped.
  10. thread.setContextClassLoader(null);
  11. thread.start();
  12. // Close the browser tab
  13. JavaScript.getCurrent().execute("close();");
  14. }
  15. });

代码示例来源:origin: com.github.markash/statistics-card

  1. /**
  2. * <p>
  3. * Executes the given JavaScript code to manipulate the chart.
  4. * Use the JavaScript variable <code>chart</code> to access the chart.
  5. * </p>
  6. * <p>Example:</p>
  7. * <pre> chart.manipulateChart("chart.addSeries({name: 'new', data: [1, 2]});");</pre>
  8. *
  9. * @param js JavaScript code to be executed
  10. */
  11. public void manipulateChart(String js) {
  12. JavaScript.eval(
  13. "var chart = $('#" + getDomId() + "').highcharts();\n" +
  14. js
  15. );
  16. }
  17. }

代码示例来源:origin: com.haulmont.cuba/cuba-web

  1. @Override
  2. public void doRevert() {
  3. super.doRevert();
  4. JavaScript js = Page.getCurrent().getJavaScript();
  5. js.execute("window.close();");
  6. }

代码示例来源:origin: viritin/viritin

  1. public static void setCookie(String key, String value, String path, LocalDateTime expirationTime) {
  2. String expires = toCookieGMTDate(expirationTime);
  3. JavaScript.getCurrent().execute(String.format(
  4. "document.cookie = \"%s=%s; path=%s\"; Expires=%s\";", key, value, path, expires
  5. ));
  6. }

代码示例来源:origin: org.opencms/opencms-core

  1. /**
  2. * Sets the window title.<p>
  3. *
  4. * @param title the new window title
  5. */
  6. public void setTitle(String title) {
  7. /* HACK: Using a Label destroys the layout for some reason, so we resort to setting the caption directly in the
  8. element via an explicit JavaScript call. */
  9. JavaScript.eval(
  10. "document.querySelector('#"
  11. + getId()
  12. + " .fakewindowheader').innerHTML = '"
  13. + StringEscapeUtils.escapeJavaScript(title)
  14. + "'");
  15. }
  16. }

代码示例来源:origin: org.eclipse.hawkbit/hawkbit-ui

  1. private static void getDynamicStyles(final String colorPickedPreview) {
  2. Page.getCurrent().getJavaScript()
  3. .execute(HawkbitCommonUtil.changeToNewSelectedPreviewColor(colorPickedPreview));
  4. }

代码示例来源:origin: viritin/viritin

  1. public static void setCookie(String key, String value, LocalDateTime expirationTime) {
  2. String expires = toCookieGMTDate(expirationTime);
  3. JavaScript.getCurrent().execute(String.format(
  4. "document.cookie = \"%s=%s; expires=%s\";", key, value, expires
  5. ));
  6. }

相关文章