java - How to access List's properties in Spring EL? -


el tries interpret property name list index , fails. how access list's normal bean properties if exist?

update

i had own class

public class directory extends abstractlist<file> {      ...      public date getinternetlastmodified() {        return internetlastmodified;     } 

as see class both list , has individual properties.

when wrote in xml:

${directory.internetlastmodified} 

i getting numberformatexception. interpreted this, since object list, el trying like

out.print(directory.get( string.valueof("internetlastmodified" ) ) 

so leads me ask question.

assuming internetlastmodified instance method, created simple directory class, , tried spelexpressionparser see happened.

public class directoryexamplesmain {      public static final void main(string[] args) {         expressionparser parser = new spelexpressionparser();         org.springframework.expression.expression exp = null;          directory dir = new directory();          // literal         exp = parser.parseexpression("internetlastmodified");         date d = exp.getvalue(dir, date.class);         system.out.format("internetlastmodified", d);       } } 

and result got internetlastmodified [fri may 03 15:40:44 cdt 2013]

if directory bean think need use "@directory.internetlastmodified" expression. can find examples in section 7.5 of reference manual.

here's easy way test that.

import java.util.date;  import org.springframework.expression.accessexception; import org.springframework.expression.beanresolver; import org.springframework.expression.evaluationcontext; import org.springframework.expression.expressionparser; import org.springframework.expression.spel.standard.spelexpressionparser; import org.springframework.expression.spel.support.standardevaluationcontext;  public class directoryexamplesmain {      public static final void main(string[] args) {         final expressionparser parser = new spelexpressionparser();      // bean references     final standardevaluationcontext context = new standardevaluationcontext();     context.setbeanresolver(         new beanresolver() {         @override         public object resolve(evaluationcontext arg0, string arg1)             throws accessexception {              return new directory();     }});      system.out.format("%s [%s]%n","@directory.internetlastmodified",  parser.parseexpression("@directory.internetlastmodified").getvalue(context)); } 

Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -