4

I'm trying to listen event from components contained in DynaForm of primefaces-extensions, so developer can do dynamically do some custom stuff. At the end I would like to be able to do this:

<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>

What I want to do:

Whenever the key defined in my:ajax match the controlKey of a pe:dynaFormControl, I want to attach the my:ajax client behavior to the p:inputText.

Problems encountered:

At first, I did all of this in DynaFormRenderer#encodeBody, quite convenient since var is put in the EL context. But I ended up having this exception (similar to this 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)

Then I tried to do just like o:moveComponent from Omnifaces using PreRenderViewEvent, but var is not available at this moment, in fact, calling DynaForm#getValue() always return null.

Do you have any suggestions how properly attach client behavior dynamically when var comes in the picture?

More infos: Mojarra 2.2.15 & Tomcat 8

Rapster
  • 484
  • 1
  • 5
  • 23
  • Did you manage to solve this? If you can elaborate slightly more on what you are trying to do I might be able to help. Could you explain how `my:ajax` is defined and how it differs from `f:ajax` ? I can see the addition of the `key` attribute but beyond that I would be guessing as to what it actually does... – Adam Waldenberg Jul 31 '19 at 02:06
  • You'll be able to see my progress here: https://github.com/primefaces-extensions/primefaces-extensions.github.com/issues/706 `my:ajax` is meant to be set dynamically, it won't be attached to the parent (dynaForm in this case). You better have a good understanding of how dynaForm works if you wanna understand what I'm trying to do. – Rapster Jul 31 '19 at 08:15
  • I think I see what you are trying to do... With that said, I don't know the implementation details of `pe:dynaForm` - if there is a limitation or behavior missing in a component that could also cause side effects of its own. However, you might be able to use the `preRenderComponent` event and define it under `my:ajax` - it should give you access to more of the component tree when the event happens. If not, I can take a closer look together with PrimeFaces Extensions later. – Adam Waldenberg Jul 31 '19 at 10:43

0 Answers0