简体   繁体   中英

a4j:commandLink is erasing javascript from xhtml

As the title shows, when i click on the a4j:commandLink, the method executes perfectly and updates the table i need.

the problems is that the js of the page is disappearing after the a4j:commandLink post to the bean.

Edit: to bit a more clear, when i mean that the js disappears, what happens is that when i look for the javascript of the page in the Mozilla firebug, it doesn't show it. Is this normal? what am I doing wrong? Any best approach for this?

the code is:

<h:panelGroup id="examplePanel" >
<h:panelGroup rendered="#{not empty exampleBean.list}">
<table id="listDataTable" width="100%" cellspacing="0" 
    cellpadding="0" border="0" style="margin-left: 0pt; width: 716px;">
    <thead>
        <tr>
            <th>col1</th>
            <th>col2</th>
            <th>col3</th>                               
            <th class="shortCol">col4</th>
        </tr>       
    </thead>
    <tbody>
    <a4j:repeat value="#{exampleBean.list}" rowKeyVar="itStatus" var="item">
        <tr>
            <td>
                <h:outputText value="#{exampleBean.exampleShow(item)}" />
            </td>
            <td>
                <h:outputText value="#{exampleBean.exampleShow(item)}" />
            </td>
            <td>
                <h:outputText value="#{exampleBean.exampleShow(item)}" />
            </td>                  
            <td>
                <h:commandLink action="#{exampleShow(item)}" ></h:commandLink>
            </td>                               
        </tr>           
    </a4j:repeat>
    </tbody>
</table>
</h:panelGroup>
</h:panelGroup>
<h:outputLabel value="* #{locale.name}:" />
<h:inputText value="#{exampleBean.exampleName}"
disabled="#{not exampleBean.edit}" id="exampleName" />

<div class="button search">
**<a4j:commandLink action="#{exampleBean.objetToTable}" value="#{locale.create}" render="exampleTurnPanel" ></a4j:commandLink>**
</div>  

before this, i was using ah:commandLink with af:ajax inside. But with this, the bean did not have the values, as the POST is never done. correct?

<h:commandLink action="#{exampleBean.objetToTable}"                     value="#{locale.create}">
<f:ajax execute="examplePanel" render="examplePanel" onevent="setExampleTableCss"/>                             </h:commandLink>

REGARDS.

I'm not sure what exactly do you mean by disappearing JavaScript, but note that your <a4j:commandLink> updates exampleTurnPanel without refreshing the whole page. It means that new content of exampleTurnPanel is not affected by any JavaScript that you executed when loading the page.

If you have some JavaScript code that should affect contents of exampleTurnPanel , then you should place it inside exampleTurnPanel , in order to make it run at every update of the panel. Alternatively, you can explicitly call it after update using oncomplete attribute of <a4j:commandLink> .

In case of <h:commandLink> you need <f:ajax event = "action" ... /> , though it shouldn't be different from <a4j:commandLink> (note, however, onevent="setExampleTableCss" in <f:ajax> - don't you need it in oncomplete of <a4j:commandLink> ?).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM