You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pivot.apache.org by "Roger Whitcomb (JIRA)" <ji...@apache.org> on 2015/07/07 19:34:04 UTC

[jira] [Commented] (PIVOT-949) bxml:script using js file (absolute path) doesn't work

    [ https://issues.apache.org/jira/browse/PIVOT-949?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14617030#comment-14617030 ] 

Roger Whitcomb commented on PIVOT-949:
--------------------------------------

I think I may know the underlying reason for this, after getting a similar error in one of our BXML files that had this script in it:
  <bxml:script>
      importClass(org.apache.pivot.wtk.Button);
      function isSelected(state) {
          return state == Button.State.SELECTED;
      }
  </bxml:script>
We would get an error with Java 8 (but not with Java 7):  "Mapping function "isSelected" is not defined.".
After much debugging and research I found several resources that helped to fix the problem:
https://wiki.openjdk.java.net/display/Nashorn/Rhino+Migration+Guide
It turns out that the new Nashorn script engine in Java 8 does not directly support the Rhino function "importClass".  Instead you need to load a compatibility script first:
      try {
          load("nashorn:mozilla_compat.js");
      } catch (exception) { }
There is also a difference in the way the global namespace is stored under Nashorn.  So, I am preparing a patch to BXMLSerializer to fix this.  This will do two things:
1) If "nashorn" is detected as the script engine, run this script fragment before any user scripts so that "importClass()" and etc. are available (to maintain backward compatibility).
2) Do the namespace switching (basically load the "nashorn.global" element into the script GLOBAL_SCOPE before invoking functions).

I will have a separate patch for this in a couple of hours after I finish testing with my application.

I have no comment, however, on your proposed patch, Sandro.  If it helps, great, but I suspect this other problem I have just described is also causing problems.

> bxml:script using js file (absolute path) doesn't work
> ------------------------------------------------------
>
>                 Key: PIVOT-949
>                 URL: https://issues.apache.org/jira/browse/PIVOT-949
>             Project: Pivot
>          Issue Type: Bug
>          Components: core-serialization
>    Affects Versions: 2.0.3, 2.0.4
>         Environment: Windows 7
> Java 7 Update 67, Java 8 Update 20
>            Reporter: Said SAID EL IMAM
>            Assignee: Sandro Martini
>              Labels: java7, java8, javascript
>             Fix For: 2.1, 2.0.5
>
>         Attachments: PIVOT-949_patch1.patch
>
>
> Hi,
> I use in my bxml files lines like:
> <bxml:script src="/gui/pivot/scripts/variables.js" />
> which loads some variables that I can use in the file by calling them like $icon
> But when using a Java version higher than 6, I get this error:
> org.apache.pivot.serialization.SerializationException: Value "icon" is not defined.
> 	at org.apache.pivot.beans.BXMLSerializer.processAttributes(BXMLSerializer.java:1093)
> 	at org.apache.pivot.beans.BXMLSerializer.processStartElement(BXMLSerializer.java:819)
> 	at org.apache.pivot.beans.BXMLSerializer.readObject(BXMLSerializer.java:443)
> 	at org.apache.pivot.beans.BXMLSerializer.processStartElement(BXMLSerializer.java:910)
> 	at org.apache.pivot.beans.BXMLSerializer.readObject(BXMLSerializer.java:443)
> 	at org.apache.pivot.beans.BXMLSerializer.readObject(BXMLSerializer.java:634)
> 	at org.apache.pivot.beans.BXMLSerializer.readObject(BXMLSerializer.java:607)
> 	at dcp.main.gui.pivot.Master.startup(Master.java:190)
> 	at org.apache.pivot.wtk.DesktopApplicationContext$2.run(DesktopApplicationContext.java:641)
> 	at org.apache.pivot.wtk.ApplicationContext$QueuedCallback.run(ApplicationContext.java:1607)
> 	at java.awt.event.InvocationEvent.dispatch(Unknown Source)
> 	at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
> 	at java.awt.EventQueue.access$400(Unknown Source)
> 	at java.awt.EventQueue$3.run(Unknown Source)
> 	at java.awt.EventQueue$3.run(Unknown Source)
> 	at java.security.AccessController.doPrivileged(Native Method)
> 	at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
> 	at java.awt.EventQueue.dispatchEvent(Unknown Source)
> 	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
> 	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
> 	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
> 	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
> 	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
> 	at java.awt.EventDispatchThread.run(Unknown Source)
> And my application shows a popup window with the message:
> Value "icon" is not defined.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)