我对 PrimeFaces 手机非常陌生。我正在使用 PrimePush 技术开发一个移动聊天示例应用程序。
我在用
- primefaces-3.4.2.jar
- 大气兼容-jbossweb-1.0.8.jar
- 大气兼容tomcat-1.0.8.jar
- 大气兼容-tomcat7-1.0.8.jar
- 大气运行时-1.0.8.jar
我能够在 PrimeFaces 的桌面版本中运行 PrimePush 聊天。它运行良好,但如果我对移动版本使用相同的示例,JBoss 6.1.0 会出现以下异常:
java.lang.NullPointerException
com.sun.faces.application.ApplicationImpl.applyAnnotations(ApplicationImpl.java:1908)
com.sun.faces.application.ApplicationImpl.createComponentApplyAnnotations(ApplicationImpl.java:1857)
com.sun.faces.application.ApplicationImpl.createComponent(ApplicationImpl.java:1127)
org.jboss.weld.integration.webtier.jsf.ForwardingApplication.createComponent(ForwardingApplication.java:122)
com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.createComponent(ComponentTagHandlerDelegateImpl.java:446)
com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:144)
javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:114)
javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:94)
com.sun.faces.facelets.tag.jsf.core.FacetHandler.apply(FacetHandler.java:101)
javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:94)
com.sun.faces.facelets.tag.jsf.core.ViewHandler.apply(ViewHandler.java:156)
com.sun.faces.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:89)
javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:94)
com.sun.faces.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:79)
com.sun.faces.facelets.impl.DefaultFacelet.apply(DefaultFacelet.java:148)
com.sun.faces.application.view.FaceletViewHandlingStrategy.buildView(FaceletViewHandlingStrategy.java:734)
com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:96)
com.sun.faces.lifecycle.Phase.doPhase(Phase.java:97)
com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:135)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:309)
org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:67)
我的 Facelets 页面是:
<!DOCTYPE html>
<html>
<f:view 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:p="http://primefaces.org/ui"
xmlns:pm="http://primefaces.org/mobile" contentType="text/html"
renderKitId="PRIMEFACES_MOBILE">
<pm:page title="Chat">
<f:facet name="postinit">
<h:outputScript library="primefaces" name="push/push.js" />
<script type="text/javascript">
//<![CDATA[
function handleMessage(data) {
var chatContent = $(PrimeFaces.escapeClientId('chatForm:content'));
chatContent.append(data + '<br />');
//keep scroll
chatContent.scrollTop(chatContent.height());
}
//]]>
</script>
</f:facet>
<!-- Main View -->
<pm:view id="main" swatch="a">
<pm:header title="Chat">
</pm:header>
<pm:content>
<p:socket onMessage="handleMessage" channel="/chat"
widgetVar="subscriber" />
<p:growl id="growl" />
<h:form id="chatForm">
<p:outputPanel id="container">
<h:panelGroup rendered="#{chatView.loggedin}">
<p:outputPanel id="content"
style="width:100%;height:200px;overflow:auto" />
<p:separator />
<p:inputText value="#{chatView.globalMessage}"
styleClass="messageInput" />
<p:commandButton value="Send"
actionListener="#{chatView.sendGlobal}"
oncomplete="$('.messageInput').val('')" />
</h:panelGroup>
<h:panelGroup rendered="#{not chatView.loggedIn}">
<p:inputText id="username" value="#{chatView.username}">
<f:attribute name="placeholder" value="Username" />
</p:inputText>
<p:separator />
<p:commandButton value="Login" icon="refresh" update="container"
actionListener="# {chatView.login}" />
</h:panelGroup>
</p:outputPanel>
</h:form>
</pm:content>
</pm:view>
</pm:page>
</f:view>
</html>
我的支持bean是:
package test;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
public class ChatUsers {
private List<String> users;
@PostConstruct
public void init() {
this.users = new ArrayList<String>();
}
public List<String> getUsers() {
return users;
}
public void setUsers(List<String> users) {
this.users = users;
}
public void addUser(String user) {
this.users.add(user);
}
public void removeUser(String user) {
this.users.remove(user);
}
public boolean contains(String user) {
return this.users.contains(user);
}
}