How to disable expression evaluation in thymol-lite?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

How to disable expression evaluation in thymol-lite?

Jaizkibel
Hi Jim,

I replaced thymol 1.1 with thymol-lite 2.0

Now i get an error message when using this code to include a fragment:

<table class="resultTable withBorder"
               th:include="share/fragments::qdDataTable(${meta}, ${result}, ${testForm.debug})"></table>

The message says:
ThError: while evaluating expression: testForm: null , debug:debug

This happens because testForm gets only defined on the server side.
When viewing the prototype, i dont need any expression evaluation.
So how can i disable it?

Regards,
Jaizkibel
Reply | Threaded
Open this post in threaded view
|

Re: How to disable expression evaluation in thymol-lite?

jjbenson
Administrator
Hi Jaizkibel,

  There is no built-in mechanism for turning off expression processing.

  You could try overloading the expression parser entry point like this:
 
    thymol.ready(function () {
      thymol.configurePreExecution(function () {
        thymol.getParsedExpr = function() {
          return "";
        }
      });
    });

  .. but this may be a step too far and stop other sections of your pages from working properly.

  If you don't have too many expressions with unresolved nested property references ( like "testForm.debug" ), the easiest way of working around your problem would be to simply create dummy values for the missing expression terms.

  In this case, "testForm=true" would be enough, and the minimal syntax for achieving this would be to use a script tag like this:

      <script type="text/javascript" src="http://cdn.jsdelivr.net/thymol/2.0.0/thymol.min.js" data-thymol-src="thymol-lite.min.js" data-thymol-parameters="?&testForm=true"></script>

  Please note the use of "?&" in the data-thymol-parameters attribute, this is needed to work-around a current issue with embedded parameter parsing.

  Kind Regards,

    Jim

Reply | Threaded
Open this post in threaded view
|

Re: How to disable expression evaluation in thymol-lite?

Jaizkibel
Hi Jim,

Thanks for your advice, fixed this.
Now I'm running into the next problem:

<div class="errors" th:attrappend="class=${#fields.detailedErrors().size() > 0 ? '' : ' invisible'}">
   ...
</div>

stops Thymol with this debug message "TypeError: Cannot read property 'apply' of undefined"

This even does not work with thymol-full.

How should i define #fields?
Reply | Threaded
Open this post in threaded view
|

Re: How to disable expression evaluation in thymol-lite?

jjbenson
Administrator
Hi Jaizkibel,

  The Thymeleaf #fields expression object is part of the Thymeleaf Spring support library.

  As an expression object, it's not part of thymol-lite, and as a Spring extension, it's not part of thymol-full either!

  To get this to work, you'll have to add a custom Thymol extension (dialect). N.B. thymol-lite does support custom dialects and hence also supports custom expression objects!

  Here is a bare-bones version of a dialect that provides some minimal responses to some of the methods in the Thymeleaf implementation:

  var fieldsObject = function() {

    var thExpressionObjectName = "#fields";

    function hasErrors(target) {
      return false;
    }

    function hasGlobalErrors() {
      return false;
    }

    function errors(target) {
      return [];
    }

    function globalErrors() {
      return [];
    }

    function detailedErrors() {
      return [];
    }

    return {
      thExpressionObjectName : thExpressionObjectName,
      hasErrors : hasErrors,
      hasGlobalErrors : hasGlobalErrors,
      errors : errors
      globalErrors : globalErrors
      detailedErrors : detailedErrors
    };

  };

  thymol.ready(function() {
    thymol.configurePreExecution(function() {
      thymol.addDialect({
        prefix : 'th',
        objects : [
          fieldsObject
        ]
      });
    });
  });

  Hopefully, this will help you make progress.

  Kind Regards,

    Jim
Reply | Threaded
Open this post in threaded view
|

Re: How to disable expression evaluation in thymol-lite?

Jaizkibel
Hi Jim,

I will try out the custom dialect solution, but at the moment i am cheating by adding "attrappend" to the thDisable list.
Tried to disable the "field" attribute as well but got this error message:

cannot disable unknown attribute "field"

Is this a bug?
Reply | Threaded
Open this post in threaded view
|

Re: How to disable expression evaluation in thymol-lite?

jjbenson
Administrator
Hi Jaizkibel,

  Disabling th:attrappend is another way of getting that one problematic template to work. However, this solution would not be suitable if your template were to contain other occurences of  th:attrappend that need to be processed.

  The error raised when you try to disable th:field is not a bug. The th:field, th:errors and th:errorclass attributes are part of Thymeleaf "SpringStandard" dialect and not the "Standard" dialect. The "out-of-the-box" Thymol libraries only implement the Standard dialect and not the SpringStandard one.

  Interestingly, the only way to "turn off" the errors raised by th:field etc, is to implement the missing attributes (using a custom dialect) and then disable them!

  Kind Regards,

    Jim