Entity auto update problem with conversation
rohit1183 May 18, 2012 2:33 PMThe scenario is simple. I have a page where it displays list of properties (called Lead) in rich datatable. User clicks on the id of any property and the application takes the user to the lead details page. From this page user can update the details and click update button.
There are some drop downs on the page on which I have <a4j:support event="onchange".... tag because with the change on value, I need to rerender a dependent drop down list. What is happening is when user changes the value in the drop down, I see in back ground an update statement getting fired. What I want is that the entity should update only when user clicks on Update button. I have tried using MANUAL flush mode in @Begin but it does not work. Here are some snippets:
package com.cox.mdu.action; import java.util.Date; import java.util.List; import javax.ejb.Remove; import javax.ejb.Stateful; import org.jboss.seam.ScopeType; import org.jboss.seam.annotations.Begin; import org.jboss.seam.annotations.End; import org.jboss.seam.annotations.Factory; import org.jboss.seam.annotations.In; import org.jboss.seam.annotations.Logger; import org.jboss.seam.annotations.Name; import org.jboss.seam.annotations.Out; import org.jboss.seam.annotations.Scope; import org.jboss.seam.annotations.security.Restrict; import org.jboss.seam.log.Log; import org.jboss.seam.security.Identity; import com.cox.mdu.dao.DwellTypeLocalDAO; import com.cox.mdu.dao.ExecutivesLocalDAO; import com.cox.mdu.dao.LeadLocalDAO; import com.cox.mdu.model.DwellType; import com.cox.mdu.model.Executives; import com.cox.mdu.model.Lead; import com.cox.mdu.model.Site; import com.cox.mdu.model.ui.TabPanel; @Stateful @Name("leadsDetailsAction") @Scope(ScopeType.CONVERSATION) @Restrict("#{identity.hasRole('CorporateUser') or identity.hasRole('SiteUser')}") public class LeadsDetailsAction implements LeadsDetailsActionLocal { @In(create = true) private LeadLocalDAO leadDAO; private Lead lead; @Begin(join = true) public void selectLead(Lead lead) { setLead(lead.getLeadId()); } @Begin(join = true) public void addLead(){ lead = new Lead(); } @End public void add() { lead.setCreateDate(new Date()); lead.setCreatedBy(identity.getCredentials().getUsername()); lead.setModifiedDate(new Date()); lead.setModifiedBy(identity.getCredentials().getUsername()); leadDAO.save(lead); } @Restrict("#{identity.hasRole('Administrator')}") @Begin(join = true, nested = true) @End public void update() { lead.setModifiedDate(new Date()); lead.setModifiedBy(identity.getCredentials().getUsername()); leadDAO.update(lead); } public void setLead(int leadId) { // Make sure we are connected to the data base and need to be able to access all the related Entities this.lead = leadDAO.getById(leadId); } public Lead getLead() { return lead; } }
When the update button is clicked, the update method is called. I want the changes to persist only then. Currently even if user changes the option from the drop down which has
a4j:support tag, the update is fired.
I have tried using manual mode in all @Begin in the above snippet. When user clicks on a lead id, selectLead method is called.