constraintsopenlaszlolzx

Default placement is not working properly in Open Laszlo 5.0.x


When i tried to use the default placement like this in a class like this $once{property} its giving the following error.

Exception in thread "main" org.openlaszlo.sc.parser.TokenMgrError: Lexical error at line 25, column 249.  Encountered: "@" (64), after : ""
     [exec]     at org.openlaszlo.sc.parser.ParserTokenManager.getNextToken(ParserTokenManager.java:2565)
     [exec]     at org.openlaszlo.sc.parser.Parser.jj_scan_token(Parser.java:10271)
     [exec]     at org.openlaszlo.sc.parser.Parser.jj_3_5(Parser.java:8325)
     [exec]     at org.openlaszlo.sc.parser.Parser.jj_2_5(Parser.java:7224)
     [exec]     at org.openlaszlo.sc.parser.Parser.CallExpression(Parser.java:1312)
     [exec]     at org.openlaszlo.sc.parser.Parser.PostfixExpression(Parser.java:1521)

I have placed a sample code in this url. The code works fine in OL 3.3 but not in 4.9 and 5.0. Any idea's as to why it's not working will be helpful.

http://forum.openlaszlo.org/showthread.php?p=48740#post48740

Solution

  • There are two problems in your code. First, the doublequote syntax of the defaultplacement attribute:

    <attribute name="defaultplacement" value="'insideview'"/>
    

    That's an old syntax, which is not required with recent versions of OpenLaszlo. The other problem is the usage of the $once{} constraint, which is not even needed - and which is causing the compiler exception.

    <attribute name="defaultplacement" value="$once{test.defaultplacement}"/>   
    

    But let me clarify what I mean using a simple code example:

    <canvas>
    
      <class name="blackbox" extends="view">
        <attribute name="bgcolor" value="black"/>
        <attribute name="defaultplacement" value="blackinner"/>
        <view name="blackinner" bgcolor="green"
              x="10" y="10" width="${parent.width-20}" height="${parent.height-20}">
    
        </view>
      </class>
    
      <class name="redbox" extends="view">
        <attribute name="bgcolor" value="red"/>
        <attribute name="defaultplacement" value="content"/>
        <blackbox name="content"
              x="10" y="10" width="${parent.width-20}" height="${parent.height-20}">
    
        </blackbox>
      </class>
    
    
      <redbox x="10" y="10" width="200" height="200">
        <view width="40" height="40" bgcolor="blue" />
      </redbox>
    
    </canvas>
    

    This example application defines a class blackbox, and a class redbox. The blackbox is just a blackbox with a green child view, which has an inset of 10 pixels.

    The redbox uses the blackbox class/tag as a child, with an inset of 20 pixels. The defaultplacement for the redbox refers to the blackbox instance, and the defaultplacement for the blackbox refers to the green child view of blackbox with the name 'blackinner'.

    The code then creates an instance of redbox, with a blue view (40x40 pixel) as the content. As you can see in this screenshot of the application, the blue view is automatically placed correctly inside the greenview of the blackbox.

    Screenshot of example application with defaultplacement working

    The original code of your application (I've put all classes into the canvas file for simplification) compiles without any problems in 5.0 (trunk), when the discussed changes are made:

    <canvas>
    
      <class name="myframe" extends="view">
        <attribute name="bgcolor" value="red"/>
        <attribute name="defaultplacement" value="insideview"/>
        <view x="5" y="5" width="${parent.width-10}" name='insideview'
              height="${parent.height-10}" 
              bgcolor="#FFFFCC"/>
      </class>
    
    
      <class name="answerMain" extends="view">
        <attribute name="defaultplacement" value="test"/>   
        <myframe name="test" width="220" height="20" />
      </class>
    
      <answerMain>
        <text> HI </text>
      </answerMain>
    
    </canvas>
    

    The OpenLaszlo compiler should definitely not exit with an exception in such a case, but unfortunately the compiler hasn't been maintained that well in the past two years.