Cryptic Error Messages

5 views
Skip to first unread message

Mat Jaggard

unread,
Nov 18, 2011, 10:51:44 AM11/18/11
to Cambridge Template Engine
I'm finding the error messages produced by Cambridge to be
particularly unhelpful.

In my particular case, I got the error "Error parsing expression: $
{user.userId}"
but it turned out that the problem was with a:else...

This works...
<option value="${user.userId}" a:else >

this fails...
<option a:else value="${user.userId}">

It's not just that this seems to be a bug (correct me if I'm wrong but
I can't find it in the documentation) - the error reporting generally
isn't good and so it took me ages to work out why the expressions I
was using didn't work. I thought it was because of my use of a
Map.Entry. Even just printing which line of ExpressionParser caused
the problem would help. The stack trace printing at the moment doesn't
actually show where the problem is.

Erdinc Yilmazel

unread,
Nov 18, 2011, 11:10:58 AM11/18/11
to cambridge...@googlegroups.com
Hi Mat,

I appreciate if you can send me a template file (a snippet) that causes this error and I will look at it.
I will be on vacation next week, but when I come back I am going to start spending a lot of time on this project.
I have been very busy in past 3 months with something else but now it is over and I will focus my energy to
enhancing developer experience, documentation etc.

Erdinc

Matthew Jaggard

unread,
Nov 18, 2011, 11:22:00 AM11/18/11
to cambridge...@googlegroups.com
Cool, thank you very much.

My template is this...

<!--$extends skeleton.html-->
<div id="bodyarea">
<h1>${actionName} an Index</h1>
<div a:if="error">${error}</div>
<form action="${base_url}${action}" method="POST">
Name:<br/>
<input a:if="edit" autofocus="autofocus" type="text" name="${action}" value="${indexName}" readonly="readonly" />
<input a:else autofocus="autofocus" type="text" name="${action}" value="${indexName}" /><br/>
<h2>Access</h2>
<label for="${allowed_users_param}">Allowed Users:</label><br/>
<span a:if="edit">(you are automatically allowed access)</span>
<select multiple="multiple" size="${size}" name="${allowed_users_param}">
<a:span a:foreach="userDetails.keySet()" a:as="user">
<option a:if="userDetails[user]" value="${user.userId}" selected="selected">${user.nickname}</option>
<option value="${user.userId}" a:else >${user.nickname}</option>
</a:span>
</select><br/>
<small>Admin users are always allowed access</small><br/>
<input a:foreach="usersUsedToBeAllowed" a:as="user" type="hidden" value="${user}" />
<input a:if="edit" type="submit" value="Update"/>
<input a:else type="submit" value="Create"/>
</form>
</div>

and my template contains quite a lot of fields but the relevant one is a Map<User,Boolean> to say if the user is allowed access to the item in question.

It's actually all working now, but it stops working with the error I gave if I swap the attributes a:each and value="${user.userId}"

Many thanks,
Mat.

Matthew Jaggard

unread,
Nov 18, 2011, 11:57:15 AM11/18/11
to cambridge...@googlegroups.com
I've also just noticed that these lines...

<input a:if="edit" type="submit" value="Update"/>
<input a:else type="submit" value="Create"/>

Are producing this output...

<input value="Create" />

Thanks,
Mat.

Erdinc Yilmazel

unread,
Nov 18, 2011, 12:03:01 PM11/18/11
to cambridge...@googlegroups.com
Can you make it print the value of edit and have a look?

You can either put ${edit} somewhere on the page or put <!--$debug --> somewhere.

Erdinc

Matthew Jaggard

unread,
Nov 18, 2011, 12:07:35 PM11/18/11
to cambridge...@googlegroups.com
Sure. It's false...

java.lang.Boolean edit false


Thanks,
Mat.

Matthew Jaggard

unread,
Nov 18, 2011, 12:39:02 PM11/18/11
to cambridge...@googlegroups.com
Also, I tried to iterate through a Map using the entrySet

a:foreach="myMap.entrySet" a:as="entry"
then
${entry.key}

but I got an error about not being able to access public final fields. Why can't I access public final fields?

(By the way, I have already fixed this by using keySet instead of entrySet and then myMap[key] to get the value)

Thanks,
Mat.

Jeff Schnitzer

unread,
Nov 18, 2011, 1:57:14 PM11/18/11
to cambridge...@googlegroups.com
Matt, you might find it easier to use JEXL as the expression language.  That's what Jon and I use now after tying several of the others, and it helps a lot.  Full method calls, you can pass parameters, etc.

Jeff

Erdinc Yilmazel

unread,
Nov 30, 2011, 11:31:23 PM11/30/11
to cambridge...@googlegroups.com
Matt which version are you using? Can you try building the latest from trunk? I've tried all these now using the latest code and could not reproduce it. I will update the downloadable package soon.

Thanks,

Erdinc
Reply all
Reply to author
Forward
0 new messages