我正在使用聊天的 primefaces 示例,显然我在尝试打开频道时出现异常
I am using the primefaces example of the chat, apparently I have an exception when trying to open the channel
发生在加载页面时,另外parcer没有找到频道空间或无法读取某些字符。
<p:socket onMessage="handleMessage" channel="/{room}" autoConnect="false" widgetVar='subscriber' />
原因:
java.lang.IllegalArgumentException: [/context/primepush/{room}] is not a valid URL fragment. Consider encoding relevant portions of the URL with [class org.ocpsoft.urlbuilder.util.Encoder]
我的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.
错误发生是因为Rewrite/PrettyFaces无法解析对应的URL。这可能是因为您使用的是 2013 年以来非常旧的 Rewrite/PrettyFaces 版本。请更新到 3.4.1.Final。在最新版本中修复了一些关于 URL 解析的错误,我相信更新会解决您的问题。
解决方法是只写/room 没有亲戚并且连接创建正确
<p:socket onMessage="handleMessage" channel="/room" autoConnect="false" widgetVar='subscriber' />
发生在加载页面时,另外parcer没有找到频道空间或无法读取某些字符。
<p:socket onMessage="handleMessage" channel="/{room}" autoConnect="false" widgetVar='subscriber' />
原因:
java.lang.IllegalArgumentException: [/context/primepush/{room}] is not a valid URL fragment. Consider encoding relevant portions of the URL with [class org.ocpsoft.urlbuilder.util.Encoder]
我的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.
错误发生是因为Rewrite/PrettyFaces无法解析对应的URL。这可能是因为您使用的是 2013 年以来非常旧的 Rewrite/PrettyFaces 版本。请更新到 3.4.1.Final。在最新版本中修复了一些关于 URL 解析的错误,我相信更新会解决您的问题。
解决方法是只写/room 没有亲戚并且连接创建正确
<p:socket onMessage="handleMessage" channel="/room" autoConnect="false" widgetVar='subscriber' />