update fields of conditionally rendered form

南楼画角 提交于 2019-12-13 04:44:32

问题


my problem is, that I want to render form2 conditionally. This collides with a ajax update event of another form1, which should trigger the rendering of form2.

<h:form id="form1">
    <h:selectOneMenu id="selectedGroupId" label="#{msgs.group_group}" value="#{groupBean.selectedGroupId}">
        <p:ajax event="change" listener="#{groupBean.selectGroupEvent}" update=":form1"/>
        <f:selectItems value="#{groupBean.availableGruppen}" />
    </h:selectOneMenu>
</h:form>

<h:form id="form2" rendered="#{not empty groupBean.groupDto}">
  <p:panelGrid id="groupEditGrid">  
    ...
  </p:panelGrid>
</h:form>

Is there a way of doing this without putting the render condition inside a component of form2?

Thanks
Jonny


回答1:


You cannot update a component that is not on your page. But you could wrap your form in a h:panelGroup that is not rendered contitionally and update the wrapper instead.

Example:

<h:form id="form1">
    <h:selectOneMenu id="selectedGroupId" label="#{msgs.group_group}" 
                     value="# {groupBean.selectedGroupId}">
        <p:ajax event="change" listener="#{groupBean.selectGroupEvent}"
                update=":formWrapper"/>
        <f:selectItems value="#{groupBean.availableGruppen}" />
    </h:selectOneMenu>
</h:form>

<h:panelGroup id="formWrapper>
  <h:form id="form2" rendered="#{not empty groupBean.groupDto}">
    <p:panelGrid id="groupEditGrid">  
      ...
    </p:panelGrid>
  </h:form>
</h:panelGroup>


来源:https://stackoverflow.com/questions/10346260/update-fields-of-conditionally-rendered-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!