Page 1 of 1

express. evaluation fails using ProductImpl and MyProducImpl

Posted: Fri Nov 22, 2013 10:46 am
by Theo Schumacher
Hello
I have extended the ProductImpl into SeaProductImpl adding a field compuzzProduct_UID which is a reference to an external database.
When creating a new product, the admin UI asks me to select one of the following product types: Product, Product Bundle and SeaProductImpl. I choose SeaProductImpl and I can create a product with this new field.

I have then changed the template catalog/product.html to show the new field just below the manufacturer name:

<div id="maker" th:text="*{manufacturer}"></div>
<div id="maker" th:text="*{compuzzProduct_UID}"></div>

When executing the page in the DemoSite on a Product of Type SeaProductImpl, everything is fine and the new info is shown.
When I do the same on a product of type 'ProductImpl' (like a T-shirt), I get the following stack trace:

HTTP ERROR 500
Problem accessing /merchandise/hawt_like_a_habanero_mens. Reason:

Exception evaluating SpringEL expression: "compuzzProduct_UID" (catalog/product:23)

Caused by:
org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating SpringEL expression: "compuzzProduct_UID" (catalog/product:23)
at org.thymeleaf.spring3.expression.SpelVariableExpressionEvaluator.evaluate(SpelVariableExpressionEvaluator.java:109)
at org.thymeleaf.standard.expression.SelectionVariableExpression.executeSelectionVariable(SelectionVariableExpression.java:107)
at org.thymeleaf.standard.expression.SimpleExpression.executeSimple(SimpleExpression.java:407)
at org.thymeleaf.standard.expression.Expression.execute(Expression.java:229)


This seams quit logical to me as the ProductImpl does not know about that new field.
How can I instruct thymeleaf to test if the current product is of type SeaProductImpl and to remove the tag when it has a different type ?

Thxs for any help or idea

Re: express. evaluation fails using ProductImpl and MyProducImpl

Posted: Fri Nov 22, 2013 10:53 am
by phillipuniverse
Since you're using th:object in a parent element (since you're using the *{} notation) you can do this:

Code: Select all

<div id="maker" th:unless="${#object instanceof T(org.broadleafcommerce.core.catalog.domain.ProductImpl)}" th:text="*{compuzzProduct_UID"></div>

Re: express. evaluation fails using ProductImpl and MyProducImpl

Posted: Fri Nov 22, 2013 10:53 am
by Theo Schumacher
Hi all
found the solution in the same product.html file just below:

<div id="compuzzProduct" th:if="${#object instanceof T(eu.seacloud.core.catalog.domain.SeaProductImpl)}">
<div id="compuzz_uid" th:text="*{compuzzProduct_UID}"></div>
</div>

maybe it helps somebody else
Theo