<a4j:commandButton> didnt work after some time
elenaveretilo Jul 8, 2010 4:02 AMHi all! I need your brilliant minds again)
There is a problem: I get the <rich:modalPanel> with <a4j:commandButton> (this button save the value), and it works fine if I go to the page first. But if I go th that page twice or after some time this button doesn't work. What I do wrong?
Here is the code of page and my bean:
/**
*
*/
package no.sfront.sales;
import java.util.Calendar;
import java.util.List;
import java.util.Set;
import java.util.HashSet;
import java.util.Date;
import java.util.Collections;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.event.ValueChangeEvent;
import javax.faces.model.SelectItem;
import no.sfront.torque.generated.StoreSales;
/**
* @author Elena Veretilo
*
*/
public class SetStoreSalesBean
{
public final static int LAST_YEAR = 1950;
private List<SelectItem> companyDepartments;
private List<SelectItem> departmentStores;
private List<StoreSales> storeSales;
private StoreSales selectedStoreSale;
private int currentDepartment;
private int currentStore;
private Date currentDate;
private Double currentStoreValue;
private Double currentStoreBudget;
private StoreSalesUtils storeSalesUtils;
private Calendar calendar;
private boolean addNewValueVisible;
private int storeSalesSize;
private Set <Integer>rowsToUpdate;
// Constructor
public SetStoreSalesBean()
{
storeSalesUtils = StoreSalesUtils.getInstance();
this.companyDepartments = storeSalesUtils.createCompanyDepartmentsList();
this.departmentStores = storeSalesUtils.createDepartmentStoresList(1);
// this.storeSales = storeSalesUtils.createStoreValuesList(1);
// this.storeSales.clear();
this.addNewValueVisible = false;
this.rowsToUpdate = new HashSet<Integer>();
this.calendar = Calendar.getInstance();
this.currentDate = this.calendar.getTime();
}
public static SetStoreSalesBean getInstance() {
FacesContext facesContext = FacesContext.getCurrentInstance();
return (SetStoreSalesBean) facesContext.getApplication()
.getELResolver().getValue(facesContext.getELContext(), null,
"setStoreSalesBean");
}
public void saveStoreSales(ActionEvent event)
{
Calendar c = Calendar.getInstance();
c.setTime(this.currentDate);
int diff = c.get(Calendar.YEAR) - LAST_YEAR;
System.out.println("diff = " + diff + "; this.calendar.YEAR = " + c.get(Calendar.YEAR));
int currMonth = diff * 12 + (c.get(Calendar.MONTH) + 1);
System.out.println("currMonth = " + currMonth + "; (c.get(Calendar.MONTH) + 1) = " + (c.get(Calendar.MONTH) + 1));
Double currValue = this.getCurrentStoreValue();
Double currBudget = this.getCurrentStoreBudget();
int storeId = this.getCurrentStore();
storeSalesUtils.saveStoreSales(storeId, currMonth, currValue, currBudget);
this.storeSales = null;
this.storeSales = storeSalesUtils.createStoreValuesList(storeId);
this.storeSalesSize = this.storeSales.size();
this.setAddNewValueVisible(false);
this.clear(event);
}
public void updateStoreSales(ActionEvent event)
{
this.selectedStoreSale.setValue(this.currentStoreValue);
this.selectedStoreSale.setBudgetValue(this.currentStoreBudget);
storeSalesUtils.updateStoreSales(this.selectedStoreSale);
rowsToUpdate = Collections.singleton(storeSales.indexOf(this.selectedStoreSale));
/*
// for updating all rows if needed
for (int i = 0; i < this.storeSales.size(); i++)
{
storeSalesUtils.updateStoreSales(this.storeSales.get(i));
}
this.storeSales = null;
this.storeSales = storeSalesUtils.createStoreValuesList(this.getCurrentStore());
this.storeSalesSize = this.storeSales.size();
*/
this.setCurrentStoreValue(0.0);
this.setCurrentStoreBudget(0.0);
}
public void changeStoreSale(ActionEvent event)
{
this.currentStoreValue = this.selectedStoreSale.getValue();
this.currentStoreBudget = this.selectedStoreSale.getBudgetValue();
}
public void addNewValue(ActionEvent event)
{
this.setAddNewValueVisible(true);
System.out.println("this.addNewValueVisible = " + this.addNewValueVisible);
}
public void clear(ActionEvent event)
{
this.setCurrentStoreValue(0.0);
this.setCurrentStoreBudget(0.0);
// this.setAddNewValueVisible(false);
}
public void loadCurrentDepartment(ValueChangeEvent event){
Integer id = (Integer)event.getNewValue();
System.out.println("--------- departmentId = " + id);
this.setCurrentDepartment(id);
this.departmentStores = null;
this.departmentStores = storeSalesUtils.createDepartmentStoresList(id);
this.storeSales = null;
}
public void loadCurrentStore(ValueChangeEvent event){
Integer id = (Integer)event.getNewValue();
System.out.println("--------- storeId = " + id);
this.setCurrentStore(id);
this.storeSales = null;
this.storeSales = storeSalesUtils.createStoreValuesList(id);
this.storeSalesSize = this.storeSales.size();
}
public void loadCurrentDate(ValueChangeEvent event){
Date tempDate = (Date)event.getNewValue();
this.setCurrentDate(tempDate);
}
}