Saturday, October 3, 2015

PAW - New Tags

Since PAW Server 0.96 BeanShell tag handling in XHTML files has been improved. In addition PHP like tags are now supported.
In older PAW versions it was a bit cumbersome to write XHTML pages because BeanSHell and HTML could not be mixed. The following code would not have worked:

<bsh>if(i > 0) {</bsh>
<h3>TEST</h3>
<bsh>}</bsh>

This code now works in the new PAW version, because PAW does no longer execute BeanShell blocks separately but does build  complete BeanShell script representing the page that is executed as a whole.

The old tags <bsh> ... </bsh> still do work, but in addition PHP like <?bsh ... ?> tags are available.
Here is a short example:

<?bsh if(i > 0) { ?>
<h3>TEST</h3>
<?bsh } ?>

To make it easier to output BeanShell variables inside HTML code easier the short print tag <?= ... ?>  is now available:

<?bsh i = 7; { ?>
<b>Value of i = </b> <?=i ?>
<?bsh } ?>

Debugging

Sometimes BeanShell error output in XHTML pages might be hard to read and it sometimes makes development more complicated than it should be.

A BeanShell error output that is visible inside the HTML source looks like this:

<!--
BeanShell Error:

bsh.EvalError: Sourced file: inline evaluation of: ``$$.print("<html>\n<body>\n"); import de.fun2code.android.pawserver.AndroidInterf . . . '' : Attempt to resolve method: getProximity() on undefined variable or class name: sensorListener : at Line: 6 : in file: inline evaluation of: ``$$.print("<html>\n<body>\n"); import de.fun2code.android.pawserver.AndroidInterf . . . '' : sensorListener .getProximity ( ) 

-->

Now that the whole page is executed as one entity there is the possibility to show the generated code inside the HTML page source when an error occurred.
By default this feature is disabled (not everyone should see your code), but while developing it's a good idea to turn it on.

To enable the enhanced debug output, change the the value of the bsh.debug property inside the paw/con/handler.xml from false to true and restart the server.

<param name="bsh.debug" value="true" />

The above sample error message is now enhanced with the generated BeanShell code.

<!--
BeanShell Error:

bsh.EvalError: Sourced file: inline evaluation of: ``$$.print("<html>\n<body>\n"); import de.fun2code.android.pawserver.AndroidInterf . . . '' : Attempt to resolve method: getProximity() on undefined variable or class name: sensorListener : at Line: 6 : in file: inline evaluation of: ``$$.print("<html>\n<body>\n"); import de.fun2code.android.pawserver.AndroidInterf . . . '' : sensorListener .getProximity ( ) 

-->

<!--
Generated BeanShell Code:

  1    $$.print("<html>\n<body>\n");
  2    // Imports
  3    import de.fun2code.android.pawserver.AndroidInterface;
  4    import android.content.Context;
  5    import android.hardware.Sensor;
  6    sensorListener = AndroidInterface.getSensorListener();
* 7    proximity = sensorListene.getProximity();

-->

If possible the erroneous line is marked with an asterisk (*). This should make finding the error much easier.