开发者

How to programmatically or dynamically add ajax listener to JSF 2 component?

开发者 https://www.devze.com 2023-03-29 11:10 出处:网络
How to programmatically or dynamically add ajax listener to JSF 2 component? I tried: ... FacesContext facesContext = FacesContext.getCurrentInstance();

How to programmatically or dynamically add ajax listener to JSF 2 component?

I tried:

  ...
  FacesContext facesContext = FacesContext.getCurrentInstance();
  AjaxBehavior dragStart = (AjaxBehavior)facesContext.getApplication().createBehavior(AjaxBehavior.BEHAVIOR_ID);
  dragStart.addAjaxBehaviorListener(new DragEnterListener());
  dragStart.setTransient(true);
  component.addClientBehavior("dragstart", dragStart);
  ...

  public class DragEnterListener implements AjaxBehaviorListener {

    @Override
    public void processAjaxBehavior(AjaxBehaviorEvent event) throws AbortProcessingException {
      System.out.println("AjaxListener CALLED!!! ");
    }
  开发者_运维知识库}

But thid doesn't work. In page I've got this JS exception:

serverError: class java.lang.IllegalStateException  
cz.boza.formcreator.FormModel$DragEnterListener

I found this example in RichFaces: http://community.jboss.org/message/611571

But in plain JSF 2 in AjaxBehavior class there is no

addAjaxBehaviorListener(MethodExpression methodExpression) 

there is only

addAjaxBehaviorListener(ValueExpression valueExpression) 

I'm trying to solve this for many days.

Please help.

Thank you very much.


OK, so I made more research and found that if the component in which I wan't to add ajax listener is also added dynamically (from java - like parant.getChildren().add(component)) into the page, everything works fine.

But if component in which I wan't to add ajax listener is is added statically (in jsp - like <h:panelGroup binding="#{bean.component}">) into the page, aforementioned weird exception is thrown:

serverError: class java.lang.IllegalStateException
cz.boza.formcreator.FormModel$DragEnterListener

I will try to ask this question in JSF forum. May be it's a bug in Mojara.

0

精彩评论

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