开发者

Modify dynamically JSF snippets by h:commandlink

开发者 https://www.devze.com 2023-03-17 15:26 出处:网络
I have a h:commandlink control in page1. the control uses f:ajax to call to the following h:panelgroup :

I have a h:commandlink control in page1. the control uses f:ajax to call to the following h:panelgroup :

I have a h:panelgroup control in page2 (a snippet), which has a ui:include within it. I h开发者_JS百科ave a h:panelgroup control in page3 (a snippet), which has a ui:include within it.

Now according to the choices made on page1, I would like to switch the snippets by clicking on the h:commandlink control.

I have a BIG problem there: it seems that only if I click twice on the commandlink, only then the snippet changes - and not on one click.

I have tried to remove the f:ajax to render the panelgroup, and still it does not work...


There are two potential causes of this problem.

  1. The <f:ajax> is fully re-rendering another <h:form> than where it is sitting in. This way the view state of the other form will get lost which would require invoking the action on the other form twice before it really get executed.

    The solution is to not re-render the other <h:form>, but only some container component in that form. E.g.

    <h:form id="otherForm">
        <h:panelGroup id="content">
            ...
        <h:panelGroup>
    </h:form>
    

    with

    <f:ajax render=":otherForm:content" />
    

  2. When there's a rendered attribute on the <h:commandLink> or any of its parent components, then it must evaluate true during the apply request values phase of the postback request in order to get JSF to invoke the bean action associated with the <h:commandLink> during the invoke action phase of that request. Perhaps the bean is request scoped and/or some odd/illogical flow inside the bean caused that the rendered attribute is not properly been preserved.

    Best is to maintain those rendered conditions in a @ViewScoped bean and let its action methods return void or null so that the bean lives as long as you're interacting with the same view. Change the rendered conditions during action methods only and not inside setters/getters or something.

0

精彩评论

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