使用var组件动态添加客户端行为

时间:2019-05-26 10:45:25

标签: jsf primefaces-extensions

我正在尝试从primefaces-extensions的DynaForm中包含的组件中侦听事件,因此开发人员可以动态地执行一些自定义操作。最后,我希望能够做到这一点:

<pe:dynaForm id="dynaForm" value="#{dynaFormController.model}" var="data" controlKey="#{data.name}">
    <pe:dynaFormControl type="input" for="txt">
        <p:inputText id="txt" value="#{data.value}" required="#{data.required}" />
    </pe:dynaFormControl>

    <my:ajax event="keyup" listener="#{controller.authorSelected}" key="author"/>
</pe:dynaForm>

我想做什么:

只要my:ajax中定义的键与pe:dynaFormControl的controlKey相匹配,我就想将my:ajax客户端行为附加到p:inputText

遇到的问题:

首先,我在DynaFormRenderer#encodeBody中进行了所有这些操作,这很方便,因为var被放在EL上下文中。但是我最终遇到了这个异常(类似于https://github.com/javaserverfaces/mojarra/issues/4365):

java.lang.NullPointerException
    at javax.faces.component.UIComponentBase.restoreBehaviors(UIComponentBase.java:2228)
    at javax.faces.component.UIComponentBase.restoreBehaviorsState(UIComponentBase.java:2203)
    at javax.faces.component.UIComponentBase.restoreState(UIComponentBase.java:1623)
    at javax.faces.component.UIOutput.restoreState(UIOutput.java:286)
    at javax.faces.component.UIInput.restoreState(UIInput.java:1422)
    at com.sun.faces.application.view.FaceletPartialStateManagementStrategy$2.visit(FaceletPartialStateManagementStrategy.java:379)
    at com.sun.faces.component.visit.FullVisitContext.invokeVisitCallback(FullVisitContext.java:151)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1689)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
    at javax.faces.component.UIForm.visitTree(UIForm.java:371)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
    at com.sun.faces.application.view.FaceletPartialStateManagementStrategy.restoreView(FaceletPartialStateManagementStrategy.java:366)
    at com.sun.faces.application.StateManagerImpl.restoreView(StateManagerImpl.java:138)
    at com.sun.faces.application.view.ViewHandlingStrategy.restoreView(ViewHandlingStrategy.java:123)
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.restoreView(FaceletViewHandlingStrategy.java:591)
    at com.sun.faces.application.view.MultiViewHandler.restoreView(MultiViewHandler.java:151)
    at javax.faces.application.ViewHandlerWrapper.restoreView(ViewHandlerWrapper.java:353)
    at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:199)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:123)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:658)

然后,我尝试使用PreRenderViewEvent从Omnifaces进行o:moveComponent的操作,但是var目前不可用,实际上,调用DynaForm#getValue()总是返回null。

您有任何建议如何在图片var出现时动态地正确附加客户端行为?

更多信息:Mojarra 2.2.15和Tomcat 8

0 个答案:

没有答案