我正在使用聊天的primefaces示例,显然我在尝试打开频道

时间:2017-02-27 15:05:01

标签: jsf primefaces xhtml prettyfaces

在加载页面时发生,除了parcer没有找到频道房间或者无法读取某些字符。

<p:socket onMessage="handleMessage" channel="/{room}" autoConnect="false" widgetVar='subscriber' />

引起:

  

java.lang.IllegalArgumentException:[/ context / primepush / {room}]不是有效的URL片段。考虑使用[class org.ocpsoft.urlbuilder.util.Encoder]编码URL的相关部分

我的web.xml

<servlet>
        <servlet-name>Push Servlet</servlet-name>
        <servlet-class>org.primefaces.push.PushServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
        <async-supported>true</async-supported>
    </servlet>
    <servlet-mapping>
        <servlet-name>Push Servlet</servlet-name>
        <url-pattern>/primepush/*</url-pattern>
    </servlet-mapping>

在我的豆子里

 public void login(BLogin log) {
RequestContext requestContext = RequestContext.getCurrentInstance();
         username=log.getLogNombres()+" "+log.getLogApellidos();
        if(users.contains(username)) {
            //loggedIn = false;
            //FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Username taken", "Try with another username."));
            //requestContext.update("growl");
           // requestContext.execute("PF('subscriber').connect('/" + username + "')");
            loggedIn = true;
        }
        else{
            users.add(username);
            requestContext.execute("PF('subscriber').connect('/" + username + "')");
            loggedIn = true;
        }
    }

我的xhtml

<f:metadata>
            <f:event type="preRenderView" listener="#{chatView.login(bLoginController.getbLogin())}" />
        </f:metadata>
            <p:growl id="growl" showDetail="true"/>
            <p:socket onMessage="handleMessage" channel="/{room}" autoConnect="false" widgetVar='subscriber' />
            <script type="text/javascript">
                function handleMessage(message) {
                    var chatContent = $(PrimeFaces.escapeClientId('form:public')),
                            text = (message.user) ? message.user + ':' + message.text : message.text;

                    chatContent.append(text + '<br />');

                    //keep scroll
                    chatContent.scrollTop(chatContent.height());

                    if (message.updateList) {
                        updateList();
                    }
                }
            </script>

我试试

        <p:socket onMessage="handleMessage" channel="/%7Broom%7D"  

和其他错误

16:16:21,998 SEVERE [javax.enterprise.resource.webcontainer.jsf.application] (default task-16) Error Rendering View[/pages/home.xhtml]: java.lang.IllegalStateException: No parameter [room] was set in the pattern [/context/primepush/{room}]. Call address.set("room", value); or remove the parameter from the pattern.

2 个答案:

答案 0 :(得分:0)

发生错误是因为Rewrite / PrettyFaces无法解析相应的URL。这可能是因为你从2013年开始使用非常旧版本的Rewrite / PrettyFaces。请更新到3.4.1.Final。在最新版本中有一些关于URL解析的错误修正,我确信更新将解决您的问题。

请参阅: https://github.com/ocpsoft/rewrite/issues/224

答案 1 :(得分:0)

解决方案是只在没有亲属的情况下写/房间,并且连接是正确创建的

<p:socket onMessage="handleMessage" channel="/room" autoConnect="false" widgetVar='subscriber' />