Search code examples
javaif-statementexpressiontapestry

Tapestry use Java expression into <t:if> component


I'm a beginner in tapestry and I was wondering If it is possible to use a java expression as test into an component

I've been trying this way but it's not working

<t:loop source="pathologies" value="valueFromCda">
  <t:if test="valueFromCda instanceof String">

the error is the following one :

Could not convert 'valueFromCda instanceof StrucDocList' into a component parameter binding: Error parsing property expression 'valueFromCda instanceof StrucDocList': line 1:0 no viable alternative at input 'valueFromCda'

valueFromCda and pathologies are properties in my controller:

@Property
private Object valueFromCda;

@Property
private List<Object> pathologies;

Thank you for your answers ! have a good afternoon ;)


Solution

  • The "test" parameter expects a property-binding by default. Tapestry will look for a property "valueFromCda instanceof String" or a POJO-like getter ("isXXX" for boolean return types is also ok) "getValueFromCda instanceof String", which it can’t find because there’s no such property or method in your page/component.

    Instead you should write one like this:

    tml

    <t:if test="valueInstanceOfString">
    

    component

    public boolean isValueInstanceOfString() {
        return valueFromCda instanceof String;
    }