[jboss-user] [JBoss Seam] - Question - Can't save outjected DataModelSelection until 2nd

jfrankman do-not-reply at jboss.com
Sat Oct 20 21:22:55 EDT 2007


I had a problem where I selected an item outjected from a SFSB's datamodel to an edit page and when I tried to save it  my changes would not be saved on the first attempt. No errors occurred, but the changes I entered on my edit page would not get saved to the DB. Debugging the application showed that the object injected from the edit page did not contain the changes made on the form. However, after the first attempt everything worked fine. 

I solved the problem and was able to eliminate this behavior by setting the dataModel to null (transmittals=null;) in the editClientTransmittal method. I don't understand why this problem happened in the first place and why modifying the editClientTransmittals method solved the problem. I would appreciate it if anyone could look at this example and help me understand:

I had the following SFSB using the Datamodel:

@Stateful
  | @Name("officeTransmittalAction")
  | @Scope(ScopeType.SESSION)
  | public class OfficeTransmittalsActionImpl implements OfficeTransmittalsAction {
  | 
  | 	
  | 	@In(create=true) private ClientTransmittalService clientTransmittalService;
  | 
  | 	@DataModelSelection("transmittals")
  | 	@In(required=false) @Out(required=false) 
  | 	private ClientTransmittalVO clientTransmittal;
  | 	
  | 	@DataModel
  | 	List<ClientTransmittalVO> transmittals;
  | 	
  | 	@Factory("transmittals")
  | 	public void findTransmittals()
  | 	{
  | 		transmittals=clientTransmittalService.findTransmittalsByOfficeAndDate(worker.getOffice(), transdate);
  | 	}
  | 
  | 	@Begin(join=true)
  | 	public String editClientTransmittal()
  | 	{
  | 		return "";
  | 	}
  | 
  | 	@Begin(join=true)
  | 	public void saveClientTransmittal()
  | 	{
  | 		clientTransmittalService.saveClientTransmittal(clientTransmittal);
  | 		transmittals=null; //refresh data model
  | 	}
...

My List Page (transMaster.xhtml) is:
		<rich:dataTable id="transmittals" value="#{transmittals}" var="clientTransmittal" >
  | 			<h:column>
  | 				<f:facet name="header">
  | 					<h:outputText value="Transmittal ID">
  | 					</h:outputText>
  | 				</f:facet>									
  | 				<h:outputText value="#{clientTransmittal.id}" />
  | 			</h:column>
  | 			<h:column>
  | 				<f:facet name="header">
  | 					<h:outputText value="Last Name" />
  | 				</f:facet>
  | 				<h:outputText value="#{clientTransmittal.clientlastname}" />		
  | 			</h:column>
  | 			<h:column>
  | 				<f:facet name="header">
  | 					<h:outputText value="First Name" />
  | 				</f:facet>
  | 				<h:outputText value="#{clientTransmittal.clientfirstname}" />		
  | 			</h:column>
  | 			<h:column>
  | 				<f:facet name="header">
  | 					<h:outputText value="Receipt Number" />
  | 				</f:facet>
  | 				<h:outputText value="#{clientTransmittal.receiptnumber}" />	
  | 				<rich:spacer />	
  | 			</h:column>
  | 						<h:column>
  | 							<f:facet name="header">
  | 								<h:outputText value="Action" />
  | 							</f:facet>
  | 							
  | 							<s:link value="Edit" action="#{officeTransmittalAction.editClientTransmittal}">
  | 							</s:link>
  | 						</h:column>			
  | 		</rich:dataTable>	
  | 

My Edit page (officeTransmittalEdit.xhtml) was as follows:

  | 	<ui:define name="body">
  | 
  | 		<h:messages globalOnly="true" styleClass="message" id="globalMessages" />
  | 
  | 		<h:form id="countytrans" styleClass="edit">
  | 			<s:validateAll>
  | 				<rich:panel>
  | 					<f:facet name="header">Edit Transmittal</f:facet>
  | 					<s:decorate id="idDecoration" template="layout/edit.xhtml">
  | 						<ui:define name="label">id</ui:define>
  | 						<h:inputText id="id" required="true" readonly="true"
  | 							value="#{clientTransmittal.id}">
  | 							<a:support event="onblur" reRender="idDecoration" />
  | 						</h:inputText>
  | 					</s:decorate>
  | 
  | 					<s:decorate id="clientfirstnameDecoration"
  | 						template="layout/edit.xhtml">
  | 						<ui:define name="label">Client First Name</ui:define>
  | 						<h:inputText id="clientfirstname" size="50" maxlength="50"
  | 							value="#{clientTransmittal.clientfirstname}">
  | 							<a:support event="onblur" reRender="clientfirstnameDecoration" />
  | 						</h:inputText>
  | 					</s:decorate>
  | 
  | 					<s:decorate id="clientlastnameDecoration"
  | 						template="layout/edit.xhtml">
  | 						<ui:define name="label">Client Last Name</ui:define>
  | 						<h:inputText id="clientlastname" size="50" maxlength="50"
  | 							value="#{clientTransmittal.clientlastname}">
  | 							<a:support event="onblur" reRender="clientlastnameDecoration" />
  | 						</h:inputText>
  | 					</s:decorate>
  | 
  | 				</rich:panel>
  | 
  | 				<div class="actionButtons1">
  | 					<h:commandButton
  | 						action="#{officeTransmittalAction.saveClientTransmittal}"
  | 						id="saveTransButton2" value="Save TransmittalMaster">
  | 					</h:commandButton>
  | 				</div>
  | 			</s:validateAll>
  | 		</h:form>
  | 	</ui:define>

My navigation rules:
        <navigation from-action="#{officeTransmittalAction.editClientTransmittal}">
  |        		<redirect view-id="/officeTransmittalEdit.xhtml"/>
  |         </navigation>
  | 	<navigation
  | 		from-action="#{officeTransmittalAction.saveClientTransmittal}">
  | 		<redirect view-id="/transMaster.xhtml" />
  | 	</navigation>

I experience a problem where my "clientTransmittal" object would not save on the first try. I would open the list page, choose to edit the transmittal, make a change, and click the save button. One the first try, the injected clientTransmittal would not contain any of the changes made on the form. The second time I brought up the edit page the injected clientTransmittal would contain the changes made on the form. I sensed that the datamodel was not getting updated, but I did not understand why. As an experiment I changed the edit method from:

	@Begin(join=true)
  | 	public String editClientTransmittal()
  | 	{
  | 		return "";
  | 	}

To:

	@Begin(join=true)
  | 	public String editClientTransmittal()
  | 	{
  | 		transmittals=null; //refresh data model
  | 		return "";
  | 	}

When I did this I no longer experienced the problem. Why would setting the dataModel object to null fix this problem?

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

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



More information about the jboss-user mailing list