0

我正在尝试使用 java 代码刷新 jsf 组件。首先,我尝试使用这个:

FacesContext.getCurrentInstance().getPartialViewContext().getRenderIds().add("MyCompId");

但它会产生“UnsupportedOperationException”。然后,我尝试安装omnifaces 并使用Ajax.update("MyComp")。结果是一样的 :

org.apache.myfaces.view.facelets.el.ContextAwareELException: javax.el.ELException: java.lang.UnsupportedOperationException
    at org.apache.myfaces.view.facelets.el.ContextAwareTagMethodExpression.invoke(ContextAwareTagMethodExpression.java:108)
    at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:68)
    at javax.faces.component.UICommand.broadcast(UICommand.java:120)
    at javax.faces.component.UIViewRoot._broadcastAll(UIViewRoot.java:1041)
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:289)
    at javax.faces.component.UIViewRoot._process(UIViewRoot.java:1415)
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:765)
    at org.apache.myfaces.lifecycle.InvokeApplicationExecutor.execute(InvokeApplicationExecutor.java:38)
    at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:170)
    at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:357)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl._doFilterImpl(TrinidadFilterImpl.java:303)
    at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl.doFilter(TrinidadFilterImpl.java:208)
    at org.apache.myfaces.trinidad.webapp.TrinidadFilter.doFilter(TrinidadFilter.java:92)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)
Caused by: javax.el.ELException: java.lang.UnsupportedOperationException
    at org.apache.el.parser.AstValue.invoke(AstValue.java:291)
    at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:274)
    at org.apache.myfaces.view.facelets.el.ContextAwareTagMethodExpression.invoke(ContextAwareTagMethodExpression.java:96)
    ... 34 more
Caused by: java.lang.UnsupportedOperationException
    at java.util.AbstractCollection.add(AbstractCollection.java:221)
    at org.omnifaces.util.Ajax.update(Ajax.java:75)

我尝试重现此处找到的相同示例:http: //showcase.omnifaces.org/utils/Ajax。我的 XHTML:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:c="http://java.sun.com/jsp/jstl/core">
<f:view  contentType="text/html">
    <h:body id="body">
        <h:form id="form">
            <div id="contentStyle">    
                <h:panelGroup styleClass="blocLsMsgErr" id="messages">
                    <h:panelGroup styleClass="lsMsgErr">
                        <h:dataTable var="facesMessage"
                            value="#{messagesComponent.listeCustomFacesMessage1}">
                            <h:column>
                                <h:graphicImage alt="icon"
                                    value="/images/messages/#{facesMessage.severity}_icon.png" />
                            </h:column>
                            <h:column>
                                <h:outputLink rendered="#{not empty facesMessage.id}"
                                    styleClass="titre #{facesMessage.severity}"
                                    onclick="document.getElementById('#{facesMessage.id}').focus();return false;">
                                    <h:outputText value="#{facesMessage.summary} " />
                                </h:outputLink>
                                <h:outputText rendered="#{empty facesMessage.id}"
                                    styleClass="titre #{facesMessage.severity}"
                                    value="#{facesMessage.summary} " />
                            </h:column>
                            <h:column>
                                <h:outputText styleClass="#{facesMessage.severity}"
                                    value=" -1- " />
                            </h:column>
                            <h:column>
                                <h:outputText styleClass="#{facesMessage.severity}"
                                    value="#{facesMessage.detail}" />
                            </h:column>
                        </h:dataTable>

                        <h:panelGrid columns="1">
                            <ui:repeat value="#{messagesComponent.listeCustomFacesMessage2}"
                                var="facesMessage">
                                <h:graphicImage alt="icon"
                                    value="/images/messages/#{facesMessage.severity}_icon.png" />
                                <h:outputLink rendered="#{not empty facesMessage.id}"
                                    styleClass="titre #{facesMessage.severity}"
                                    onclick="document.getElementById('#{facesMessage.id}').focus();return false;">
                                    <h:outputText value="#{facesMessage.summary} " />
                                </h:outputLink>
                                <h:outputText rendered="#{empty facesMessage.id}"
                                    styleClass="titre #{facesMessage.severity}"
                                    value="#{facesMessage.summary} " />
                                <h:outputText styleClass="#{facesMessage.severity}"
                                    value=" -2- " />
                                <h:outputText styleClass="#{facesMessage.severity}"
                                    value="#{facesMessage.detail}" />
                                <br />
                            </ui:repeat>
                        </h:panelGrid>

                        <h:panelGrid columns="4">
                            <c:forEach items="#{messagesComponent.listeCustomFacesMessage3}"
                                var="facesMessage">
                                <h:graphicImage alt="icon"
                                    value="/images/messages/#{facesMessage.severity}_icon.png" />
                                <h:outputLink rendered="#{not empty facesMessage.id}"
                                    styleClass="titre #{facesMessage.severity}"
                                    onclick="document.getElementById('#{facesMessage.id}').focus();return false;">
                                    <h:outputText value="#{facesMessage.summary} " />
                                </h:outputLink>
                                <h:outputText rendered="#{empty facesMessage.id}"
                                    styleClass="titre #{facesMessage.severity}"
                                    value="#{facesMessage.summary} " />
                                <h:outputText styleClass="#{facesMessage.severity}"
                                    value=" -3- " />
                                <h:panelGroup>
                                    <h:outputText styleClass="#{facesMessage.severity}"
                                        value="#{facesMessage.detail}" />
                                    <br />
                                </h:panelGroup>
                            </c:forEach>
                        </h:panelGrid>

                    </h:panelGroup>
                </h:panelGroup>

                <ui:insert name="content" />

                <h:commandButton styleClass="button"
                    value="#{messages.boutonSuivant}" id="buttonNext"
                    action="#{testBean.nextPage}">
                    <f:ajax />
                </h:commandButton>
            </div>
            <h:commandButton value="submit" action="#{testBean.update}">
                <f:ajax />
            </h:commandButton>
        </h:form>
    </h:body>
</f:view>
</html>

我的豆子:

import javax.inject.Named;

import org.omnifaces.util.Ajax;
import org.springframework.context.annotation.Scope;

@Named
@Scope("session")
public class TestBean {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    public void update() {
        System.out.println("Ajax update");
        Ajax.update("messages");
        System.out.println("Ajax update OK");
    }

    public String nextPage() {

        if (!this.validationChampsPagePersonne()) {
            return null;

        }

        return "next";
    }

    private boolean validationChampsPagePersonne() {
    //doing a FacesContext.getCurrentInstance().addMessage(null, facesMessage);
    }

}

其他信息:我正在使用 myfaces api 和实现(版本 2.1.11)、trinidad 2.1.0、tomahawk2 1.1.14、primefaces 3.5

任何想法?

谢谢

4

1 回答 1

1

MyFaces 不可能是原因,它一直在 MyFaces 中为我们和其他任何人工作。然而,我们从未真正使用过 Trinidad,所以我查看了 Trinidad 源代码。它似乎Collections#emptySet()在没有渲染 ID 时返回。然而,这是不可变的!这完全解释了您面临的异常。

这是特立尼达的一个相当惊人的错误。javadoc清楚地表明返回的集合必须是可变的。

Collection使用请求参数 name 从当前请求返回一个客户端标识符PARTIAL_RENDER_PARAM_NAME。如果没有这样的请求参数,则返回一个空Collection。这些客户端标识符用于标识将在请求处理生命周期的呈现阶段处理的组件。返回Collection是可变的。

如果您喜欢 Trinidad,请将其作为错误报告给 Trinidad 人。否则只是摆脱它。如果您已经在使用 PrimeFaces(和 Tomahawk),我认为没有任何理由使用它。

于 2013-05-17T02:11:22.050 回答