小编sof*_*ood的帖子

在EL中动态调用方法,从String中计算

我有一个提交按钮.此提交按钮具有"操作"属性.但是这个action属性应该总是调用另一个函数(某种泛型).所以我想动态调用一个函数.这是因为我需要重用这个组件.我只是不知道action属性需要哪种Type(Method,String等?)以及如何正确引用想要的"BeanWithMethodToCall".

@Named
@SessionScoped
public class BeanWithMethodToCall{

   @Inject
   private BeanWhichIsCalledFromEL elBean;

   public void methodToCall(){
      //do something
   }

   public void someLogic(){
      // here the wanted method is set on the bean which is later on called from el
      elBean.setMethodToCall("methodToCall");
   }
}

@Named
@SessionScoped
public class BeanWhichIsCalledFromEL{

   // i don't know the correct type of this :S
   private String method;

   public void setMethodToCall(String method){
      this.method = method;
   }

   // i don't know the correct return type of this :S
   public String getMethodToExecute(){
      //this …
Run Code Online (Sandbox Code Playgroud)

jsf el dynamic commandbutton methodexpression

3
推荐指数
1
解决办法
994
查看次数

标签 统计

commandbutton ×1

dynamic ×1

el ×1

jsf ×1

methodexpression ×1