繁体   English   中英

a4j:commandLink在reRender之后停止工作

[英]a4j:commandLink stops working after being reRender

我创建了这个测试用例来隔离我的问题。 一旦轮询执行ajax更新,就不会执行a4j:commandLink操作。 如果我们在轮询的reRender之前关闭modalPanel,则执行它。

有什么建议吗? 提前致谢。

test.xhtml:

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
xmlns:a4j="http://richfaces.org/a4j" xmlns:rich="http://richfaces.org/rich" xmlns:fn="http://java.sun.com/jsp/jstl/functions" xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:fnc="http://eyeprevent.com/fnc">
<a4j:outputPanel id="testing">
<rich:modalPanel id="examinationPanel" autosized="true" width="450" rendered="#{test.condition2}">
    <f:facet name="header">
        <h:outputText value="View Examination Images" />
    </f:facet>
    <f:facet name="controls">
        <h:panelGroup>

            <a4j:form>

                <a4j:commandLink action="#{test.close}">
                    <h:graphicImage value="/images/modal/close.png" id="hideExaminationPanel" styleClass="hidelink" />
                </a4j:commandLink>
            </a4j:form>
            <rich:componentControl for="examinationPanel" attachTo="hideExaminationPanel" operation="hide" event="onclick" />

        </h:panelGroup>
    </f:facet>


    <a4j:form>

        <h:panelGrid columns="1" id="timeoutText">
            <h:outputText id="remainingtime" value="condition1" rendered="#{test.condition1}" />
            <h:outputText id="timer" value="condition2" rendered="#{test.condition2}" />

        </h:panelGrid>

        <a4j:poll id="poll" interval="5000" enabled="#{test.poll}" reRender="poll,timeoutText" />



    </a4j:form>
</rich:modalPanel>

链接

TestBean.java

import org.apache.log4j.Logger;
public class TestBean {
private boolean condition1=false;
private boolean condition2=true;
private boolean poll=true;

public void close(){
Logger.getLogger("com.eyeprevent").info("here!");
poll=false;
condition1=true;
condition2=false;

}

public boolean isCondition1() {
return condition1;
}

public void setCondition1(boolean condition1) {
this.condition1 = condition1;
}

public boolean isCondition2() {
return condition2;
}
public void setCondition2(boolean condition2) {
this.condition2 = condition2;
}
public boolean isPoll() {
return poll;
}
public void setPoll(boolean poll) {
this.poll = poll;
}
} 

TestBean是会话作用域。 Richfaces版本3.3.2.SR1

而且在Chrome 5.0.322.2 dev中也没有出现modalPanel。 它在FF和IE7下完成。

尝试以下任意组合:

  • <a4j:form>移到模态面板之外
  • domElementAttachment (模态面板)属性设置为formparent
  • 尝试使用<h:form>

尝试以下代替<a4j:commandLink>

<h:graphicImage value="/images/modal/close.png" styleClass="hidelink"
            onclick="#{rich:component('examinationPanel')}.hide()" id="close" />

并在modalPanel上使用onhide="notifyClose()" ,其中使用<a4j:jsFunction>定义notifyClose() 这是一种解决方法,但可能有效。

这是可行的解决方案。 我接受Bozho的回答是有效的,因为他提出了在这里实现的解决方法,但我只是在这里发布完整的解决方案以防任何人遇到同样的问题。

test.xhtml:

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
xmlns:a4j="http://richfaces.org/a4j" xmlns:rich="http://richfaces.org/rich" xmlns:fn="http://java.sun.com/jsp/jstl/functions" xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:fnc="http://eyeprevent.com/fnc">
<a4j:outputPanel id="testing">
<rich:modalPanel id="examinationPanel" autosized="true" width="450" rendered="#{test.condition2}" onhide="stopTimer('false')">
    <f:facet name="header">
        <h:outputText value="View Examination Images" />
    </f:facet>
    <f:facet name="controls">
        <h:panelGroup>
            <a4j:form>
                <a4j:commandLink action="#{test.close}">
                    <h:graphicImage value="/images/modal/close.png" id="hideExaminationPanel" styleClass="hidelink" />
                </a4j:commandLink>
            </a4j:form>
            <rich:componentControl for="examinationPanel" attachTo="hideExaminationPanel" operation="hide" event="onclick" />
        </h:panelGroup>
    </f:facet>
    <a4j:form>
        <h:panelGrid columns="1" id="timeoutText">
            <h:outputText id="remainingtime" value="condition1" rendered="#{test.condition1}" />
            <h:outputText id="timer" value="condition2" rendered="#{test.condition2}" />
        </h:panelGrid>
        <a4j:poll id="poll" interval="5000" enabled="#{test.poll}" reRender="poll,timeoutText" />
    </a4j:form>
</rich:modalPanel>
</a4j:outputPanel>
<h:form>
<a4j:commandLink oncomplete="#{rich:component('examinationPanel')}.show()" reRender="testing">Link</a4j:commandLink>
<a4j:jsFunction name="stopTimer" actionListener="#{test.close}">
    <a4j:actionparam name="param1" assignTo="#{test.poll}" />
</a4j:jsFunction>
</h:form>
</html>

a4j:jsFunction保持在modalPanel标记之外是很重要的。

TestBean.java:

import javax.faces.event.ActionEvent;
import org.apache.log4j.Logger;

public class TestBean {
    private boolean condition1 = false;
    private boolean condition2 = true;
    private boolean poll = true;

    public void close(ActionEvent event) {
        Logger.getLogger("com.eyeprevent").info("here!");
        poll = false;
        condition1 = true;
        condition2 = false;
    }

    public boolean isCondition1() {
        return condition1;
    }

    public void setCondition1(boolean condition1) {
        this.condition1 = condition1;
    }

    public boolean isCondition2() {
        return condition2;
    }

    public void setCondition2(boolean condition2) {
        this.condition2 = condition2;
    }

    public boolean isPoll() {
        return poll;
    }

    public void setPoll(boolean poll) {
        this.poll = poll;
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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