0

JXPath search in list of bean for rateCode value by empty iterator.

I have list of beans where i want to fetch all items having rateCode=R1 following is my code.

class MyBean{
private String rateCode;

public String getRateCode(){
return this.rateCode;
}

public void setRateCode(String rateCode){
this.rateCode=rateCode;
}
}
List<MyBean> list = loadTestData();
JXPathContext ctx =  JXPathContext.newContext(list);
Iterator iter = authSrcContext.iterate("*[rateCode='R1']");

while(iter.hasNext()){
    Object bp = iter.next();
    MyBean bean = (MyBean)bp;

}
d-man
  • 57,473
  • 85
  • 212
  • 296

1 Answers1

0

Assuming the fact you don't use ctx but authSrcContext is a typo, you need a dot to reference the current list, in this case.

JXPathContext ctx =  JXPathContext.newContext(list);
Iterator<Object> iter = ctx.iterate(".[rateCode='R1']");
JP Moresmau
  • 7,388
  • 17
  • 31