[jboss-user] [JBoss Seam] - Re: IllegalArgumentException: Stack must not be null

laksu do-not-reply at jboss.com
Thu Jan 3 14:34:31 EST 2008


/*
  |  * CategoryActionBean.java
  |  *
  |  * Created on July 11, 2007, 3:45 PM
  |  *
  |  * To change this template, choose Tools | Template Manager
  |  * and open the template in the editor.
  |  */
  | 
  | package datassist.payroll.action;
  | 
  | 
  | import datassist.payroll.entity.ChildValuesPresentException;
  | import datassist.payroll.entity.NotFocusedException;
  | import datassist.payroll.entity.value.Value;
  | import java.util.Date;
  | import java.util.List;
  | import org.jboss.seam.ScopeType;
  | import org.jboss.seam.annotations.Name;
  | import org.jboss.seam.annotations.Out;
  | import org.jboss.seam.annotations.In;
  | import org.jboss.seam.annotations.Begin;
  | import org.jboss.seam.annotations.End;
  | import org.jboss.seam.annotations.Scope;
  | import datassist.payroll.entity.Category;
  | import datassist.payroll.entity.variable.Variable;
  | import java.io.Serializable;
  | import org.hibernate.Session;
  | import org.jboss.seam.annotations.FlushModeType;
  | import org.jboss.seam.annotations.Logger;
  | import org.jboss.seam.core.Events;
  | import org.jboss.seam.faces.FacesMessages;
  | import org.jboss.seam.log.Log;
  | 
  | 
  | @Name("categoryAction")
  | @Scope(ScopeType.CONVERSATION)
  | public class CategoryAction implements Serializable {
  |     
  |     public CategoryAction() {
  |         
  |     }
  |     private static final String updateState="update";
  |     private static final String correctState="correct";
  |     
  |     @In(create=true)
  |     private Session hibernateSession;
  |     
  |     @In(value="facesMessages")
  |     FacesMessages messages;
  |     
  |     @Out @In(required=false)
  |     Category category;
  |     
  |     public String state;
  |     private Date lastEffectiveDate=new Date();
  |  
  |     @Begin(flushMode=FlushModeType.MANUAL)
  |     public String nevv(String categoryType){
  |         category = new Category();
  |         logger.debug("nevv:categoryType ="+categoryType);
  |         category.setType(categoryType);
  |         category.edit();
  |         category.sortValues();
  |         return "categoryDefine";
  |     }
  |     
  |     @Begin(flushMode=FlushModeType.MANUAL)
  |     public String nevvBelow(CategoryNode selection) {
  |         category = new Category();
  |         Category parent = selection.value;
  |         logger.debug("nevvBelow:Category below=" + parent);
  |         hibernateSession.refresh(parent);
  |         category.setType(parent.getType());
  |         category.setParentCategory(parent);
  |         category.edit();
  |         logger.debug("nevvBelow Category below another category is created");
  |         return "categoryDefine";
  |     }
  |     
  |     @Begin(flushMode=FlushModeType.MANUAL)
  |     public String correct(CategoryNode selection){
  |         logger.trace("CategoryAction edit selection:"+selection.getValue());
  |         category=selection.getValue();
  |         hibernateSession.refresh(category);
  |         category.edit();
  |         state=correctState;
  |         System.out.println("categoryaction correct state:"+state);
  |         return "categoryEdit";
  |     }
  |     
  |     @Begin(flushMode=FlushModeType.MANUAL)
  |     public String update(CategoryNode selection){
  |         logger.trace("CategoryAction edit selection:"+selection.getValue());
  |         category=selection.getValue();
  |         hibernateSession.refresh(category);
  |         category.edit();
  |         category.sortValues();
  |         state=updateState;
  |         System.out.println("categoryaction update state:"+state);
  |         category.setOldValues(category.getCopyOfValues(category.getCurrentValues()));
  |         return "categoryEdit";
  |     }
  |     //@Begin(flushMode=FlushModeType.MANUAL)
  |     public String show(CategoryNode selection){
  |         logger.trace("CategoryAction show selection:"+selection.getValue());
  |         category=selection.getValue();
  |         hibernateSession.refresh(category);
  |         category.show();
  |         return "categoryEdit";
  |     }
  |     @Begin(flushMode=FlushModeType.MANUAL)
  |     public String define(CategoryNode selection){
  |         logger.trace("CategoryAction define selection:"+selection);
  |         category=selection.getValue();
  |         hibernateSession.refresh(category);
  |         category.edit();
  |         return "categoryDefine";
  |     }
  |     
  |     
  |     @End
  |     public String save(){
  |         System.out.println("categoryAction save method state:"+state);
  |         logger.debug("About to saveOrUpdate category:"+category);        
  |         category.stripUnusedValues();        
  |         if (isUpdateState())
  |             category.arrangeValues(lastEffectiveDate);
  |         hibernateSession.saveOrUpdate(category);
  |         Category parent=category.getParentCategory();
  |         if (parent!=null && !parent.getChildCategories().contains(category))
  |             parent.addToChildCategories(category);
  |         
  |         hibernateSession.flush();
  |         logger.debug("category saved:"+category);
  |         messages.add("Category was saved successfully");
  |         Events.instance().raiseEvent("categoryTreeRefresh");
  |         category.blur();
  |         return "categoryTree";
  |     }
  |     
  |     @End
  |     public String cancel(){
  |         Events.instance().raiseEvent("categoryTreeClearSelection");
  |         hibernateSession.evict(category);
  |         hibernateSession.flush();
  |         Events.instance().raiseEvent("categoryTreeRefresh");
  |         category.blur();
  |         return "categoryTree";
  |     }
  |     
  |     public void addVariable(){
  |         logger.trace("Adding variable. variableName:"+getVariableName()+" variableType:"+getVariableType());
  |         try {
  |             List<Variable> varList=category.getAllVariables();
  |             if (varList!=null){
  |                 for (Variable var:varList){
  |                     if (var.getName().equals(getVariableName())){
  |                         messages.add("Variable name was already used");
  |                         return;
  |                     }
  |                 }
  |             }
  |             Variable variable =(Variable)(Class.forName("datassist.payroll.entity.variable."+getVariableType()).newInstance());
  |             variable.setName(getVariableName());
  |             variable.setLabel(getVariableLabel());
  |             variable.setDescription(getVariableDescription());
  |             category.addToVariables(variable);
  |             System.out.println("Variable is created : "+variable);
  |             category.resetVariables();
  |         } catch (ClassNotFoundException ex) {
  |             ex.printStackTrace();
  |         } catch (IllegalAccessException ex) {
  |             ex.printStackTrace();
  |         } catch (InstantiationException ex) {
  |             ex.printStackTrace();
  |         } catch (NotFocusedException ex){
  |             ex.printStackTrace();
  |         }
  |     }
  |     
  |     public void removeVariable(Variable variableDelete) throws ChildValuesPresentException,NotFocusedException{
  |         System.out.println("CategoryAction.removeVariable started");
  |         if (category.checkValuesExistsForOtherCategories(variableDelete)){
  |             messages.add("Used category cannot be deleted");
  |         }else{
  |             
  | // TODO: reWrite
  |             Value valueDelete  = variableDelete.getCategory().getCurrentValue(variableDelete);
  |             category.getValues().remove(valueDelete);
  |             category.getVariables().remove(variableDelete);
  |             category.getAllVariables().remove(variableDelete);
  |             category.resetVariables();
  |             category.getVariables().remove(variableDelete);
  |             hibernateSession.delete(variableDelete);
  |             hibernateSession.flush();
  |             hibernateSession.refresh(category);
  |             category.focus();
  |             
  |         }
  |         System.out.println("CategoryAction.removeVariable finished");
  |     }
  |     
  |     public void showChanges(){
  |         logger.trace("Showing changes");
  |     }
  |     
  |     
  |     @Logger
  |     Log logger;
  |     
  |     private String variableName;
  |     private String variableType;
  |     private String variableLabel;
  |     private String variableDescription;
  |     
  |     public String getVariableName() {
  |         logger.trace("unitCategoryAction.getVariableName is called");
  |         return variableName;
  |     }
  |     
  |     public void setVariableName(String variableName) {
  |         logger.trace("unitCategoryAction.setVariableName is called");
  |         this.variableName = variableName;
  |     }
  |     
  |     public String getVariableType() {
  |         return variableType;
  |     }
  |     
  |     public void setVariableType(String variableType) {
  |         this.variableType = variableType;
  |     }
  |     
  |     public String getVariableLabel() {
  |         return variableLabel;
  |     }
  |     
  |     public void setVariableLabel(String variableLabel) {
  |         this.variableLabel = variableLabel;
  |     }
  |     
  |     public String getVariableDescription() {
  |         return variableDescription;
  |     }
  |     
  |     public void setVariableDescription(String variableDescription) {
  |         this.variableDescription = variableDescription;
  |     }
  |     
  |     public boolean isUpdateState(){
  |         if (state==null){
  |             state="";
  |             return false;
  |         }
  |         return (getState().equals(updateState));
  |     }
  |     
  |     public String getState() {
  |         return state;
  |     }
  |     
  |     public void setState(String state) {
  |         this.state = state;
  |     }
  |     
  |     public Date getLastEffectiveDate() {
  |         return lastEffectiveDate;
  |     }
  |     
  |     public void setLastEffectiveDate(Date lastEffectiveDate) {
  |         this.lastEffectiveDate = lastEffectiveDate;
  |     }
  | }
  | 

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

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



More information about the jboss-user mailing list