How to render a component outside datatable by ajax?

我们两清 提交于 2020-01-02 23:22:10

问题


I have a <h:dataTable> with a <h:commandLink> in a column and a <h:outputext> outside the <h:dataTable> which I need to render by the command link.

<h:form>
       <h:dataTable value="#{userControl.lista}" var="c">

           <h:column>
               <f:facet name="header" >
                   <h:outputText styleClass="leftColumn" value="Nombre"/>
               </f:facet>
                    #{c.nombre}
           </h:column>

           <h:column>
               <f:facet name="header" >
                   Usuario
               </f:facet>
               <h:commandLink actionListener="#{userControl.setAdmin_user(c.user)}" value="#{c.user}">
                    <f:ajax  render="output" />
               </h:commandLink>                  
           </h:column>       

       </h:dataTable>


       <h:outputText id="output" value="#{userControl.admin_user}"/>
</h:form>

It does not work. If I move the <h:outputText> inside the same column, then it works.

How is this caused and how can I solve it?


回答1:


The client ID as you currently have in the <f:ajax render> does not start with the default NamingContainer separator character : and is therefore relative to the current NamingContainer component, which is in your case the <h:dataTable>. So it will work only when the outputtext component is also in the same datatable.

You need to refer the outputtext component by an absolute client ID instead. For starters who do not have memorized all NamingContainer components yet, the easiest way to find it out is to check the id attribute of the generated HTML element in the webbrowser. Open the page in webbrowser and do View Source and locate the <span> element generated by <h:outputText id="output"> and take exactly this ID and prefix it with : to make it absolute to the view root.

E.g.

<span id="formId:output">

where formId is the ID of any <h:form> for the case the outputtext is enclosed in a <h:form>. If you don't have specified a fixed ID for the <h:form>, then JSF will autogenerate one. You'd like to specify a fixed ID then like <h:form id="formId">.

So the <f:ajax render> should look like this then

<f:ajax render=":formId:output" />


来源:https://stackoverflow.com/questions/10935987/how-to-render-a-component-outside-datatable-by-ajax

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