参考Oracle 文档, h:outputText 是否需要转换器?我应该使用f:setPropertyActionListener
而不是f:actionListener
吗?
单击 id 2564 确实显示在日志末尾:
INFO: SingletonNNTP..only once...
INFO: NNTP.loadMessages...
INFO: SingletonNNTP.connect..
INFO: SingletonNNTP.setIndex..2,562
INFO: SingletonNNTP.page..2,572
INFO: SingletonNNTP.setIndex..2,562
INFO: Initializing Mojarra 2.1.6 (SNAPSHOT 20111206) for context '/NNTPjsf'
INFO: WEB0671: Loading application [NNTPjsf] at [/NNTPjsf]
INFO: NNTPjsf was successfully deployed in 7,612 milliseconds.
INFO: Messages..
INFO: Messages..
INFO: MessageBean..
INFO: Messages.postConstruct..
INFO: SingletonNNTP..only once...
INFO: NNTP.loadMessages...
INFO: SingletonNNTP.connect..
INFO: SingletonNNTP.setIndex..2,562
INFO: SingletonNNTP.page..2,572
INFO: SingletonNNTP.setIndex..2,562
INFO: SingletonNNTP.getMessages..
INFO: Messages.getModel..
INFO: Messages.getModel..
INFO: Messages.getModel..
INFO: Messages..
INFO: Messages.postConstruct..
INFO: SingletonNNTP.getMessages..
INFO: Messages.getModel..
INFO: Messages.getModel..
INFO: Messages.getModel..
INFO: Messages.getModel..
INFO: Messages.getModel..
INFO: Messages.getModel..
INFO: Messages.getModel..
INFO: Messages.getModel..
INFO: Messages.getModel..
INFO: Messages.getModel..
INFO: MessageListener.processAction..
INFO: ..MessageListener.processAction
INFO: MessageBean..
INFO: MessageBean.postConstruct..
INFO: SingletonNNTP.setIndex..0
INFO: SingletonNNTP.getMessage..
INFO: MessageBean.setMessage..2564
INFO: MessageBean.setId..2564
INFO: MessageBean.getId..2564
INFO: MessageBean.setPrevious..2563
INFO: MessageBean.getId..2564
INFO: MessageBean.setNext..2565
INFO: MessageBean.setUrl..
INFO: MessageBean.setMessage..2556
INFO: Messages.getModel..
INFO: Messages.getModel..
INFO: Messages.getModel..
但是,它永远不会从 client.xhtml 导航到 message.xhtml。
MessageListener.processAction() 在这里应该扮演什么角色并不清楚,也不清楚它具体如何影响导航。
客户端.xhtml:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
template="./template.xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core">
<ui:define name="top">
<div style="float: left">
<h:form>
<h:commandLink action="#{messages.back()}">
<f:actionListener type="net.bounceme.dur.listeners.BackListener" />
<h:outputText value="..back"/>
</h:commandLink>
</h:form>
</div>
<div style="float: right">
<h:form>
<h:commandLink action="#{messages.forward()}">
<f:actionListener type="net.bounceme.dur.listeners.ForwardListener" />
<h:outputText value="..forward"/>
</h:commandLink>
</h:form>
</div>
</ui:define>
<ui:define name="content">
<h:dataTable value="#{messages.model}" var="m">
<h:column>
<f:facet name="id">
<h:outputText value="id" />
</f:facet>
<h:form>
<h:commandLink id="messageLink" action="#{messageBean.setMessage(m)}">
<f:actionListener type="net.bounceme.dur.listeners.MessageListener" />
<h:outputText value="#{m.messageNumber}"/>
</h:commandLink>
</h:form>
</h:column>
<h:column>
<f:facet name="subject">
<h:outputText value="subject" />
</f:facet>
<h:outputText value="#{m.subject}"></h:outputText>
</h:column>
<h:column>
<f:facet name="date">
<h:outputText value="date" />
</f:facet>
<h:outputText value="#{m.sentDate}"></h:outputText>
</h:column>
</h:dataTable>
</ui:define>
</ui:composition>
消息.java:
package net.bounceme.dur.beans;
import java.io.Serializable;
import java.net.URL;
import java.util.List;
import java.util.logging.Logger;
import javax.annotation.PostConstruct;
import javax.enterprise.context.ConversationScoped;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;
import javax.inject.Inject;
import javax.inject.Named;
import javax.mail.Message;
import net.bounceme.dur.nntp.SingletonNNTP;
@Named
@ConversationScoped
public class Messages implements Serializable {
private static final long serialVersionUID = 1L;
private static final Logger LOG = Logger.getLogger(Messages.class.getName());
private DataModel messagesDataModel = null;
private List<Message> messages = null;
@Inject
private MessageBean messageBean;
@PostConstruct
public void postConstruct() throws Exception {
LOG.info("Messages.postConstruct..");
SingletonNNTP nntp = SingletonNNTP.INSTANCE;
boolean debugNNTP = false;
messages = nntp.getMessages(debugNNTP);
messagesDataModel = new ListDataModel(messages);
}
public Messages() {
LOG.info("Messages..");
}
public DataModel getModel() throws Exception {
LOG.info("Messages.getModel..");
return messagesDataModel;
}
public void forward() throws Exception {
LOG.info("Messages.forward..");
}
public void back() throws Exception {
LOG.info("Messages.back..");
}
public MessageBean getMessageBean() {
return messageBean;
}
public void setMessageBean(MessageBean messageBean) {
this.messageBean = messageBean;
}
public void insert(Message message) {
LOG.info("Messages.insert..");
}
}