Question

I'm using Scala and Lift for a single-page web app. I frequently replace portions of the page with new contents inside a Comet block. In one of these cases I'm getting this error message:

Error locating template: /template-editContext.html Message: :13:31: name expected, but char ' ' cannot start a name

The error occurs when Lift is trying to process the file shown in the error message /template-editContext.html which looks like this:

<div id="editContext">
    <script>
        var contextFields = [];

        function parseFieldNames(fieldNames) {
            console.log("[parseFieldNames] got: " + fieldNames);
            contextFields = fieldNames.split(",");

            var x = document.createElement("SELECT");
            x.setAttribute("id", "contextFieldSelector");
            document.getElementById("addContextFieldSet").appendChild(x);

            for(var i = 0; i < contextFields.length; i++) {
                var z = document.createElement("option");
                z.setAttribute("value", contextFields[i]);
                var t = document.createTextNode(contextFields[i]);
                z.appendChild(t);
                document.getElementById("contextFieldSelector").appendChild(z);
            }
        }

        $(document).ready(function () {
            $("#addContextForm").dialog({
                autoOpen: false,
                modal: true,
                buttons: {
                    "Add field": function() {
                        var selector = document.getElementById("fieldSelector");
                        var newField = contextFields[selector.selectedIndex];
                        console.log("[Add field] adding " + newField);
                    },
                    "Create context": function () {
                        $(this).dialog("close");
                    },
                    Cancel: function () {
                        $(this).dialog("close");
                    }
                },
                close: function () {
                    console.log("[close] closing.");
                }
            });

            $("#addContextButton")
                .button()
                .click(function (event) {
                    event.preventDefault();
                    getFieldList();
                    $("#addContextForm").dialog("open");
                });
            $("#modifyContextButton")
                .button()
                .click(function (event) {
                    event.preventDefault();
                    console.log("[modifyContextButton.click] Yo.");
                });
            $("#deleteContextButton")
                .button()
                .click(function (event) {
                    event.preventDefault();
                    console.log("[deleteContextButton.click] Yo.");
                });
        });
    </script>

    <div id="editContextStuff" class="lift:ContextTable.addEditContextCallbacks">
        <span id="getFieldList"></span>
        <span id="getFieldProperties"></span>
    </div>

    <div id="addContextForm" title="Add new context">
        <form>
            <fieldset id="addContextFieldSet">
                <label for="name">Name</label>
                <input type="text" name="name" id="name" class="text ui-widget-content ui-corner-all"/>
            </fieldset>
        </form>
    </div>
</div>
Was it helpful?

Solution

The Scala xml parser is complaining that your template is not valid xml. You can try setting

LiftRules.htmlProperties.default.set((r: Req) =>
  new Html5Properties(r.userAgent))

Which will use an HTML5 parser instead, or you can work out the xml issues. It could be that your script contents aren't wrapped in CDATA blocks. To make them valid xml use:

<script>
<![CDATA[
  // your script contents
]]>
</script>

That will indicate to the xml parser that what falls between the script tags is non-xml character data and shouldn't be parsed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top