[jboss-user] [JBoss Seam] - problems with refreshing view after entity change

przadka do-not-reply at jboss.com
Thu Aug 30 05:36:23 EDT 2007


Hello,

I am a seam beginner and after 3 weeks of evaluation I am totally impressed by it. Right now I am developing a test application and I came across a problem which seems very easy but I coudnt find any solution on the forum.

What I have is a view with a form which displays entity beans (the view file was generated by seam-gen and modified). In the form I have a link which is binded to a session bean action.  In the session bean I change the currently displayed entity and than redirect back to the same view page. 

And now the problem: althought the entity is correctly changed (which can be seen in the database) the change cannot be seen in the view after we are done with the session bean. 

When I navigate to some other page and back to the view I can see changes so it has definately something do to with page refreshing.

Can anyone help? 

And here is my code, if anyone is interested

entity bean Research.java:


  | @Entity
  | public class Research implements Serializable {
  | 
  | 	private static final long serialVersionUID = 7974073555607550091L;
  | 	private Long id;
  | 	private String name;
  | 	private Client client;
  | 
  | 	private String researcherDescription;
  | 	private String dataTableName;
  | 	private String description;
  | 	private boolean active;
  | 
  | 	private Date dateCreated;
  | 
  | 	private ResearchConfiguration researchConfiguration;
  | 	
  |         private String dataFileName;
  | 	private InputStream dataFileData;
  | 
  | 	public Research() {
  | 		researchConfiguration = new ResearchConfiguration();
  | 		this.dateCreated = new Date(System.currentTimeMillis());
  | 	}
  | 
  | 	@Id
  | 	@GeneratedValue
  | 	public Long getId() {
  | 		return id;
  | 	}
  | 
  | 	public void setId(Long id) {
  | 		this.id = id;
  | 	}
  | 
  | 	@Length(max = 20)
  | 	@Column(unique=true)
  | 	public String getName() {
  | 		return name;
  | 	}
  | 
  | 	public void setName(String name) {
  | 		this.name = name;
  | 	}
  | 
  | 	@ManyToOne
  | 	public Client getClient() {
  | 		return client;
  | 	}
  | 
  | 	public void setClient(Client client) {
  | 		this.client = client;
  | 	}
  | 
  | 	public String getResearcherDescription() {
  | 		return researcherDescription;
  | 	}
  | 
  | 	public void setResearcherDescription(String researcherDescription) {
  | 		this.researcherDescription = researcherDescription;
  | 	}
  | 
  | 	@Column(unique=true)
  | 	public String getDataTableName() {
  | 		return dataTableName;
  | 	}
  | 
  | 	public void setDataTableName(String dataTableName) {
  | 		this.dataTableName = dataTableName;
  | 	}
  | 
  | 	public String getDescription() {
  | 		return description;
  | 	}
  | 
  | 	public void setDescription(String description) {
  | 		this.description = description;
  | 	}
  | 
  | 	@NotNull
  | 	public boolean isActive() {
  | 		return active;
  | 	}
  | 
  | 	public void setActive(boolean active) {
  | 		this.active = active;
  | 	}
  | 
  | 	public Date getDateCreated() {
  | 		return dateCreated;
  | 	}
  | 
  | 	public void setDateCreated(Date dateCreated) {
  | 		this.dateCreated = dateCreated;
  | 	}
  | 
  | 	@OneToOne(cascade = CascadeType.ALL)
  | 	public ResearchConfiguration getResearchConfiguration() {
  | 		if (researchConfiguration == null) {
  | 			researchConfiguration = new ResearchConfiguration();
  | 		}
  | 		return researchConfiguration;
  | 	}
  | 
  | 	public void setResearchConfiguration(
  | 			ResearchConfiguration researchConfiguration) {
  | 		this.researchConfiguration = researchConfiguration;
  | 	}
  | 
  | 
  | 	public String getDataFileName() {
  | 		return dataFileName;
  | 	}
  | 
  | 	public void setDataFileName(String dataFileName) {
  | 		this.dataFileName = dataFileName;
  | 	}
  | 
  | 	@Transient
  | 	public InputStream getDataFileData() {
  | 		return dataFileData;
  | 	}
  | 
  | 	public void setDataFileData(InputStream dataFileData) {
  | 		this.dataFileData = dataFileData;
  | 	}
  | 
  | 
  | 	public boolean isDataFileSet(){
  | 		return dataFileName!=null;
  | 	}
  | 	public void setDataFileSet(boolean dataFileSet){
  | 		
  | 	}
  | 	
  | }
  | 
  | 
  | 

the session bean ResearchManagerBean.java:


  | @Stateful
  | @Name("researchManager")
  | public class ResearchManagerBean implements ResearchManager {
  | 
  | 	@Logger
  | 	private Log log;
  | 
  | 	@In
  | 	FacesMessages facesMessages;
  | 
  | 	@In(required = false) @Out
  | 	Research research;
  | 
  | 	@PersistenceContext
  | 	private EntityManager em;
  | 
  | 	@Destroy
  | 	@Remove
  | 	public void destroy() {
  | 	}
  | 
  | 	@Override
  | 	@Begin(join = true)
  | 	public String selectResearch(Research research) {
  | 		if (research == null){
  | 			log.info("Research object is null! Cannot select!");
  | 			return null;
  | 		}
  | 		else
  | 			research = em.merge(research);
  | 			return "research";
  | 	}
  | 
  | 	@Override
  | 	@End
  | 	public String removeData(Research research) {
  | 		if (research == null){
  | 			log.info("Research object is null! Cannot remove!");
  | 			return null;
  | 		}
  | 		else {
  | 			research = em.merge(research); 
  | 			em.createNativeQuery("DROP  TABLE `"+research.getDataTableName()+"`").executeUpdate();
  | 			log.info("Table "+research.getDataTableName()+" dropped");
  | 			log.info("Removing data from research!");
  | 			research.setDataFileData(null);
  | 			research.setDataFileName(null);
  | 			research.setDataFileSet(false);
  | 			research.setDataTableName(null);
  | 			facesMessages
  | 			.add("Data removed");	
  | 			em.persist(research);
  | 			em.flush();
  | 			return "removed";
  | 		}
  | 	}
  | 
  | 	@End
  | 	public String addDataFile() {
  | 
  | 		if (research == null){
  | 			log.info("Research null! Something bad happened...");
  | 			return null;
  | 		}
  | 		else {
  | 			em.merge(research);
  | 			log
  | 					.info("New data set for #{research.name} : #{research.dataFileName}");
  | 			facesMessages
  | 					.add("New data set for #{research.name} : #{research.dataFileName}");
  | 			return "dataadded";
  | 
  | 		}
  | 	}
  | 
  | 	public Research getResearch() {
  | 		return research;
  | 	}
  | 
  | 	public void setResearch(Research research) {
  | 		this.research = research;
  | 	}
  | 
  | }
  | 

the view research.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.ajax4jsf.org/rich"
  | 	template="layout/template.xhtml">
  | 
  | 	<ui:define name="body">
  | 
  | 		<h:messages globalOnly="true" styleClass="message" />
  | 
  | 		<h:form id="researchForm">
  | 
  | 			<rich:panel>
  | 				<f:facet name="header">research</f:facet>
  | 
  | 				<s:decorate id="nameDecoration" template="layout/edit.xhtml">
  | 					<ui:define name="label">Name</ui:define>
  | 					<h:inputText id="name" required="true"
  | 						value="#{research.name}" />
  | 				</s:decorate>
  | 
  | 				<s:decorate id="clientDecoration" template="layout/edit.xhtml">
  | 					<ui:define name="label">Client:</ui:define>
  | 					<h:selectOneMenu value="#{research.client}"
  | 						required="true" id="client">
  | 						<s:selectItems value="#{clientList.resultList}" var="client"
  | 							label="#{client.name}" noSelectionLabel="Please Select..." />
  | 						<s:convertEntity />
  | 					</h:selectOneMenu>
  | 				</s:decorate>
  | 
  | 				<s:decorate id="descriptionDecoration" template="layout/edit.xhtml">
  | 					<ui:define name="label">Description:</ui:define>
  | 					<h:inputTextarea id="description" rows="5" cols="65"
  | 						value="#{research.description}" />
  | 				</s:decorate>
  | 
  | 				<s:decorate id="activeDecoration" template="layout/edit.xhtml">
  | 					<ui:define name="label">Is active:</ui:define>
  | 					<h:selectBooleanCheckbox id="active" required="true"
  | 						value="#{research.active}" />
  | 				</s:decorate>
  | 
  | 				<s:decorate id="researcherDescriptionDecoration"
  | 					template="layout/edit.xhtml">
  | 					<ui:define name="label">Researcher description:</ui:define>
  | 					<h:inputTextarea id="researcherDescription" rows="5" cols="65"
  | 						value="#{research.researcherDescription}" />
  | 				</s:decorate>
  | 
  | 				<s:decorate id="dataFileNameDecoration" template="layout/edit.xhtml">
  | 					<ui:define name="label">Used data file name:</ui:define>
  | 					<h:inputText id="dataFileName" immediate="true" enabled="false"
  | 						value="#{research.dataFileName}" disbled="true" readonly="true"/>    
  | 					<h:commandLink id="addDataFile" value="Add data >>"
  | 						action="#{researchManager.selectResearch(research)}" 
  | 						immediate="true" rendered="#{!research.dataFileSet}"/>
  | 					<h:commandLink id="removeDataFile" value="Remove data >>"
  | 						action="#{researchManager.removeData(research)}" 
  | 						immediate="true" rendered="#{research.dataFileSet}" />						
  | 				</s:decorate>
  | 				
  | 				<div style="clear: both" />
  | 				
  | 			</rich:panel>
  | 
  | 			<div class="actionButtons"><h:commandButton id="save"
  | 				value="Save" action="#{researchHome.persist}"
  | 				rendered="#{!researchHome.managed}" /> <h:commandButton id="update"
  | 				value="Save" action="#{researchHome.update}"
  | 				rendered="#{researchHome.managed}" /> <h:commandButton id="delete"
  | 				value="Delete" action="#{researchHome.remove}"
  | 				rendered="#{researchHome.managed}" /> <s:button propagation="end"
  | 				id="done" value="Done" view="/researchList.xhtml" /></div>
  | 
  | 		</h:form>
  | 
  | 	</ui:define>
  | 
  | </ui:composition>
  | 
  | 

and the pages.xml


  | <!DOCTYPE pages PUBLIC
  |           "-//JBoss/Seam Pages Configuration DTD 1.2//EN"
  |           "http://jboss.com/products/seam/pages-1.2.dtd">
  | 
  | <pages no-conversation-view-id="/home.xhtml"
  | 	login-view-id="/login.xhtml">
  | 
  | 	<page view-id="*">
  | 		<navigation>
  | 			<rule if-outcome="home">
  | 				<redirect view-id="/home.xhtml" />
  | 			</rule>
  | 		</navigation>
  | 	</page>
  | 
  | 	<page view-id="/addData.xhtml">
  | 
  | 		<navigation from-action="#{researchManager.addDataFile}">
  | 			<rule if-outcome="dataadded">
  | 				<end-conversation />
  | 				<redirect view-id="/research.xhtml">
  | 					<param name="researchId"
  | 						value="#{researchManager.research.id}" />
  | 				</redirect>
  | 			</rule>
  | 		</navigation>
  | 
  | 	</page>
  | 
  | 
  | 	<page view-id="/research.xhtml">
  | 
  | 		<navigation
  | 			from-action="#{researchManager.removeData(research)}">
  | 			<end-conversation />
  | 			<redirect view-id="/research.xhtml">
  | 				<param name="researchId"
  | 					value="#{researchManager.research.id}" />
  | 			</redirect>
  | 		</navigation>
  | 
  | 		<navigation
  | 			from-action="#{researchManager.selectResearch(research)}">
  | 			<redirect view-id="/addData.xhtml" />
  | 		</navigation>
  | 
  | 	</page>
  | 
  | 
  | 	<exception
  | 		class="org.jboss.seam.framework.EntityNotFoundException">
  | 		<redirect view-id="/error.xhtml">
  | 			<message>Not found</message>
  | 		</redirect>
  | 	</exception>
  | 
  | 	<exception class="javax.persistence.EntityNotFoundException">
  | 		<redirect view-id="/error.xhtml">
  | 			<message>Not found</message>
  | 		</redirect>
  | 	</exception>
  | 
  | 	<exception class="javax.persistence.OptimisticLockException">
  | 		<end-conversation />
  | 		<redirect view-id="/error.xhtml">
  | 			<message>
  | 				Another user changed the same data, please try again
  | 			</message>
  | 		</redirect>
  | 	</exception>
  | 
  | 	<exception class="org.jboss.seam.security.AuthorizationException">
  | 		<redirect>
  | 			<message>You don't have permission to do this</message>
  | 		</redirect>
  | 	</exception>
  | 
  | 	<exception class="org.jboss.seam.security.NotLoggedInException">
  | 		<redirect view-id="/login.xhtml">
  | 			<message>Please log in first</message>
  | 		</redirect>
  | 	</exception>
  | 
  | 	<exception>
  | 		<redirect view-id="/error.xhtml">
  | 			<message>Unexpected error, please try again</message>
  | 		</redirect>
  | 	</exception>
  | 
  | </pages>
  | 


best regards!
michal przadka

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4079506#4079506

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4079506



More information about the jboss-user mailing list