Referencing Oracle docs, does h:outputText require a Converter here? Should I be using f:setPropertyActionListener instead of f:actionListener?
Clicking id 2564 does show at the end of the logs:
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..
However, it never navigates away from client.xhtml to message.xhtml.
What role MessageListener.processAction() should have here isn’t clear, nor how it impacts navigation specifically.
client.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>
Messages.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..");
}
}
In order to navigate to a different page on a POST request, the action method needs to return the view ID of the page where you need to navigate to. Something like this:
with
This will go to
someViewId.xhtml.The action listeners have no influence on navigation. They are intented to preprocess/prepare stuff before invoking the real action, if necessary. Looking at your code snippet, you seem to not entirely understand how to use actions and action listeners. You seem to confuse action listeners with actions. The jobs which you’re doing in the action listener methods should actually be done in the action methods.
In your particular case, for example this
needs to be replaced by
with
This will navigate to
message.xhtmlwhen the action is finished.This has nothing to do with conversion. Converters are just to convert between a
Stringand a complex Java object so that complex Java objects can be presented in HTML or can be processed as HTTP request parameters which can be strings only.See also: