开发者

Evaluating the Macro value in java

Take this scenario,

In string buffer i append string continuously for example

 int a=10;
 sb.append("if("+a+">"+$b+"){\"checked\"}");

$b is a macro which assigned finally based upon the condit开发者_JAVA技巧ion satisfies string "checked" is added how to evaluate the if condition because while evaluate $b value comes as $b (which is finally replies as value) kindly help me.let me know if you have any doubts.

  public static String getStringUsingMacro(String source,HashMap hm)
      throws Exception{
WebMacro wm = new WM();
Context context=wm.getContext();

Iterator it=hm.keySet().iterator();
while(it.hasNext()){
    String key=(String)it.next();
    context.put(key,hm.get(key));
}


Template template2=new StringTemplate(wm.getBroker(),source);
template2.parse();
return template2.evaluateAsString(context);
}


It appears what you are trying to do is

if(a > b) 
    sb.append("checked");

or if b is something calculated dynamically.

int a = 10;
Future<Integer> b =
if(a > b.get()) 
    sb.append("checked");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜