DataModelSelection value not injected
kinghoward Sep 7, 2010 8:36 PMI cannot get selected value injected into field marked by @DataModelSelection. I copied and modified an example from seam tutorials messages
example.
The @DataModelSelection field is called message
, and it is always null, even after i clicked on the commandLink
link.
Can someone help me to spot why no value is ever injected into message
?
here are my classes:
---------------------------------------------
import static org.jboss.seam.ScopeType.EVENT; import java.io.Serializable; import org.jboss.seam.annotations.Name; import org.jboss.seam.annotations.Scope; @Name("message") @Scope(EVENT) public class Message implements Serializable { public Message(){ this.title = ""; this.text = ""; this.read = false; } public Message(String title, String text, boolean read){ this.title = title; this.text = text; this.read = read; } private String title; private String text; private boolean read; public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getText() { return text; } public void setText(String text) { this.text = text; } public boolean isRead() { return read; } public void setRead(boolean read) { this.read = read; } }
---------------------------------------------
import java.util.List; import javax.ejb.Local; @Local public interface MessageManager { public void findMessages(); public void select(); public void delete(); public void destroy(); public Message getMessage(); public void setMessage(Message message); public List<Message> getMessageList(); public void setMessageList(List<Message> messageList); }
---------------------------------------------
import static org.jboss.seam.ScopeType.SESSION; import java.io.Serializable; import java.util.ArrayList; import java.util.List; import javax.ejb.Remove; import javax.ejb.Stateful; import org.jboss.seam.ScopeType; import org.jboss.seam.annotations.Destroy; import org.jboss.seam.annotations.Factory; import org.jboss.seam.annotations.Name; import org.jboss.seam.annotations.Out; import org.jboss.seam.annotations.Scope; import org.jboss.seam.annotations.datamodel.DataModel; import org.jboss.seam.annotations.datamodel.DataModelSelection; @Stateful @Scope(SESSION) @Name("messageManager") public class MessageManagerBean implements Serializable, MessageManager { @DataModel(scope=ScopeType.PAGE) private List<Message> messageList; @DataModelSelection @Out(required=false) private Message message; @Factory("messageList") public void findMessages() { System.out.println("in findMessages(), by factory, making messages"); messageList = new ArrayList<Message>(); Message first = new Message("First", "This is a great message", true); messageList.add(first); Message second = new Message("Second", "This is an average message", false); messageList.add(second); } public void select() { if (message!=null){ message.setRead(true); System.out.println("in select(), for message: " + message.getTitle()); } else{ System.out.println("in select(), NULL message"); } } public void delete() { if (message!=null) { System.out.println("deleting message: " + message.getTitle()); for(int i=0;i<messageList.size(); i++){ if(((Message)messageList.get(i)).getTitle().equalsIgnoreCase(message.getTitle())){ messageList.remove(i); } } message=null; } System.out.println("in delete(), but message is NULL"); } public List<Message> getMessageList() { return messageList; } public void setMessageList(List<Message> messageList) { this.messageList = messageList; } public Message getMessage() { return message; } public void setMessage(Message message) { this.message = message; System.out.println("set message to: " + message.getTitle()); } @Remove @Destroy public void destroy() {} }
---------------------------------------------------
here is my view class, it is called messages.xhtml:
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:s="http://jboss.com/products/seam/taglib" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:rich="http://richfaces.org/rich" xmlns:p="http://jboss.com/products/seam/pdf" xmlns:a="http://richfaces.org/a4j" template="layout/template.xhtml"> <ui:define name="body"> <h:form id="messageForm"> <rich:panel> <h:outputText value="No datastore to display: #{messageManager.messageList.size}" rendered="#{messageManager.messageList.size == 0}" /> <h:outputText value="Total number of messages: #{messageManager.messageList.size}" rendered="#{messageManager.messageList.size != 0}" /> <h:dataTable id="messages" var="msg" value="#{messageManager.messageList}" rendered="#{messageManager.messageList.size>0}"> <h:column> <f:facet name="header"> <h:outputText value="Read" /> </f:facet> <h:selectBooleanCheckbox id="read" value="#{msg.read}" disabled="true" /> </h:column> <h:column> <f:facet name="header"> <h:outputText value="Title" /> </f:facet> <h:commandLink id="link" value="#{msg.title}" action="#{messageManager.select}" /> </h:column> <h:column> <s:button id="delete" value="Delete" action="#{messageManager.delete}" /> </h:column> </h:dataTable> <h3><h:outputText id="title" value="#{message.title}"/></h3> <div><h:outputText id="text" value="#{message.text}"/></div> </rich:panel> </h:form> </ui:define> </ui:composition>
---------------------------------------------