0 Replies Latest reply on Feb 28, 2011 7:39 AM by dhanaraja rajendiran

    New TopicCannot create Seam component, scope is not active

    dhanaraja rajendiran Newbie
      Hi i am getting Cannot create Seam component, scope is not active

      warning messages in my console....

      this is my action class-->>

      package com.sec.ezeeAdmin.officeManagement;

      import java.util.ArrayList;
      import java.util.Date;
      import java.util.HashMap;
      import java.util.Iterator;
      import java.util.List;
      import java.util.Map;

      import javax.persistence.EntityManager;

      import org.jboss.seam.ScopeType;
      import org.jboss.seam.annotations.AutoCreate;
      import org.jboss.seam.annotations.Begin;
      import org.jboss.seam.annotations.FlushModeType;
      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Out;
      import org.jboss.seam.annotations.Scope;
      import com.sec.ezeeAdmin.User;
      import com.sec.ezeeAdmin.configure.AdmOffices;
      import com.sec.ezeeAdmin.service.StockService;

      @Name("stocksAction")
      @Scope(ScopeType.CONVERSATION)
      public class StockAction {
           @In(create= true)
           EntityManager entityManager;
           
           @In
           User user;
           private Date date=new Date();
           
           
           
           private AdmItems admItem ;
           private int recordsPerPage=10;
           private String defaultTab = "general";
           private List<AdmItems> itemsList;
           Map<AdmOffices, Boolean> officesForRequest;
           public Map<AdmOffices, Boolean> getOfficesForRequest() {
                return officesForRequest;
           }

           public void setOfficesForRequest(Map<AdmOffices, Boolean> officesForRequest) {
                this.officesForRequest = officesForRequest;
           }

           public List<AdmItems> getItemsList() {
                return itemsList;
           }

           public void setItemsList(List<AdmItems> itemsList) {
                this.itemsList = itemsList;
           }

           public String getDefaultTab() {
                return defaultTab;
           }

           public void setDefaultTab(String defaultTab) {
                this.defaultTab = defaultTab;
           }

           public int getRecordsPerPage() {
                return recordsPerPage;
           }

           public void setRecordsPerPage(int recordsPerPage) {
                this.recordsPerPage = recordsPerPage;
           }

           public AdmItems getAdmItem() {
                return admItem;
           }

           public void setAdmItem(AdmItems admItem) {
                this.admItem = admItem;
           }
           
           public List<AdmItems> retrieveStockList()
           {
                StockService ss=new StockService(entityManager);
                return ss.retrieveStockList();
           }
           public void activeDeactive(AdmItems stocks) {          
                
                entityManager.flush();
           }
           
           
           public String editStocks(AdmItems stocks){
                System.out.println("i am in the edit");
                this.admItem=stocks;
                this.defaultTab = "general";
                //this.admItem = stocks;
                //this.admItem.setStartdate(date);
                this.selectItems(stocks);
                
                return "add-edit-stocks";
           }
           
           
           public void selectItems(AdmItems item) {
                this.itemsList = null;
                this.admItem=item;
                this.officesForRequest = new HashMap<AdmOffices, Boolean>();
                for(AdmOffices office:this.retrieveOffices() ) {
                     if(this.admItem.getOffices()!= null){
                          System.out.println("not null"+admItem.getOffices());
                          if(hasStockInList(this.admItem.getOffices(), office.getId())) {
                               officesForRequest.put(office, true);
                          } else {
                               officesForRequest.put(office, false);
                          }
                     }
                     else{
                          officesForRequest.put(office, false);
                     }
                     
                }
           }
           
           public List<AdmOffices> retrieveOffices(){
                StockService ss= new StockService(entityManager);
                System.out.println("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"+ss.retrieveOffices().size());
                return ss.retrieveOffices();
           }
           
           public boolean hasStockInList(List<AdmOffices> list , long id){
                System.out.println("i am in the has stock list");
                for(AdmOffices office : list){
                     if(office.getId() == id){
                          return true;
                     }
                }
                return false;
           }
           
           @Begin(nested = true , flushMode = FlushModeType.MANUAL)
           public String addI(){
                this.admItem= new AdmItems();
                System.out.println("i am in the ljdslfkjasldf");
                this.defaultTab = "general";
                this.selectItems(admItem);
                return "add-edit-stocks";
           }
           
           public void confirmStocks(){
                 System.out.println("inside confirm mekjhasdfkjh");
                     this.confirmOffices();

                     if(this.admItem.getId() == 0){
                          this.admItem.setCreatedUser(user.getUsername());                     
                          this.admItem.setCreatedDate(date);     
                          entityManager.persist(this.admItem);
                     }
                     else {
                               this.admItem.setModifiedDate(date);
                               this.admItem.setModifiedUser(this.user.getUsername());
                               entityManager.merge(this.admItem);
                     }
                     entityManager.flush();
           }
           
           public void confirmOffices() {
                List<AdmOffices> selectedList = new ArrayList<AdmOffices>();
                Iterator<AdmOffices> iter = this.officesForRequest.keySet().iterator();
                while(iter.hasNext()) {
                     AdmOffices office = iter.next();
                     if(this.officesForRequest.get(office).equals(true)) {
                          selectedList.add(office);
                     }
                }
                this.admItem.setOffices(selectedList);
           }
           public String can_button()
             {
                  return "stockspage";
             }
      }

      this is my jsp page-->>

      <!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.org/rich"
           xmlns:a="http://richfaces.org/a4j" template="../../template.jsp">

           <ui:define name="body">

                <div class="page_title"><h:outputText value="Add or Edit Stocks" />
                </div>
                <h:form id="stockForm">
                     <h:panelGroup id="stockPanel">
                          <s:validateAll>
                               <rich:tabPanel switchType="client" selectedTab="#{stocksAction.defaultTab}">
                                    <rich:tab name="general" value="general"
                                         label="#{messages['tab.generalData'] }">
                                         <table>
                                              <tr>
                                                   <td class="required-field"><h:outputText
                                                        value="#{messages['rich.name'] }" /></td>
                                                   <td><s:decorate id="nameDecId">
                                                        <table cellspacing="0" cellpadding="0">
                                                             <tr>
                                                                  <td><h:inputText id="nameFieldId" maxlength="50"
                                                                       value="#{stocksAction.admItem.name}" label="Name"
                                                                       style="width: 360px;" required="true" /></td>
                                                             </tr>
                                                             <tr>
                                                                  <td><s:message errorClass="error" /></td>
                                                             </tr>
                                                        </table>
                                                   </s:decorate></td>
                                              </tr>
                                              <tr>
                                                   <td class="non-required-field"><h:outputText
                                                        value="#{messages['rich.itemCode'] }" /></td>
                                                   <td><s:decorate id="CodeDecId">
                                                        <table cellspacing="0" cellpadding="0">
                                                             <tr>
                                                                  <td><h:inputText id="code"
                                                                       value="#{stocksAction.admItem.code}" /></td>
                                                             </tr>
                                                             <tr>
                                                                  <td><s:message errorClass="error" /></td>
                                                             </tr>
                                                        </table>
                                                   </s:decorate></td>
                                              </tr>
                                              <tr>
                                                   <td class="non-required-field"><h:outputText
                                                        value="#{messages['rich.startDate'] }" /></td>
                                                   <td><s:decorate id="dateDecId">
                                                        <table cellspacing="0" cellpadding="0">
                                                             <tr>
                                                                  <td><rich:calendar id="startDate"
                                                                       value="#{stocksAction.admItem.startdate}"
                                                                       label="Start Date" inputStyle="width: 130px;"
                                                                       required="true" /></td>
                                                             </tr>
                                                             <tr>
                                                                  <td><s:message errorClass="error" /></td>
                                                             </tr>
                                                        </table>
                                                   </s:decorate></td>
                                              </tr>
                                              <tr>
                                                   <td class="non-required-field"><h:outputText
                                                        value="#{messages['rich.initialCount'] }" /></td>
                                                   <td><h:inputText
                                                        value="#{stocksAction.admItem.initialCount}" /></td>
                                              </tr>
                                         </table>
                                    </rich:tab>
                                    <rich:tab label="#{messages['title.officeLocations']}"
                                         name="OfficeLocation" value="OfficeLocation">
                                         <rich:dataTable id="officeLocList" var="office"
                                              value="#{stocksAction.retrieveOffices()}" width="100%"
                                              rowClasses="rich-table-oddRow,rich-table-evenRow"
                                              columnClasses="align-left">
                                              <rich:column width="10">
                                                   <h:selectBooleanCheckbox
                                                        value="#{stocksAction.officesForRequest[office]}" />
                                              </rich:column>
                                              <h:column>
                                                   <h:outputText value="#{office.city.name}" />
                                              </h:column>
                                         </rich:dataTable>
                                    </rich:tab>
                               </rich:tabPanel>
                          </s:validateAll>
                     </h:panelGroup>
                     <br />
                     <h:panelGroup>
                          <a:commandButton value="#{messages['button.confirm']}"
                               title="#{messages['button.confirm']}"
                               action="#{stocksAction.confirmStocks()}" />
                          <h:commandButton action="#{stocksAction.can_button()}"
                               immediate="true" value="#{messages['button.cancel']}"
                               title="#{messages['button.cancel']}" />
                     </h:panelGroup>
                </h:form>
           </ui:define>
           <ui:define name="verticalMenu">
                <ui:include src="../../menus/inventory.jsp" />
           </ui:define>
      </ui:composition>


      this is my pojo-->>

      package com.sec.ezeeAdmin.officeManagement;

      import java.util.ArrayList;
      import java.util.Date;
      import java.util.List;

      import javax.persistence.CascadeType;
      import javax.persistence.Column;
      import javax.persistence.Entity;
      import javax.persistence.EnumType;
      import javax.persistence.Enumerated;
      import javax.persistence.FetchType;
      import javax.persistence.GeneratedValue;
      import javax.persistence.Id;
      import javax.persistence.JoinColumn;
      import javax.persistence.JoinTable;
      import javax.persistence.ManyToMany;
      import javax.persistence.ManyToOne;
      import javax.persistence.OneToMany;
      import javax.persistence.Table;
      import javax.persistence.UniqueConstraint;
      import org.hibernate.validator.Length;
      import org.hibernate.validator.NotNull;
      import org.hibernate.validator.Pattern;
      import org.jboss.seam.annotations.Name;

      import com.sec.ezeeAdmin.configure.AdmOffices;


      @Entity
      @Table(name="adm_items")
      @Name("admItems")
      public class AdmItems {

           
           private long id;
           private String name;
           private String code;
           private Date startdate;
           private int initialCount;
           private String createdUser;
           private Date createdDate;
           private String modifiedUser;
           private Date modifiedDate;
           private boolean active;
           private boolean history;
           private AdmItems parentItemId;
           private List<AdmOffices> offices;
           private List<AdmItems> historyItems;
           
           
           
           @Id@GeneratedValue
           @NotNull
           @Column(name="item_id", length=20)
           public long getId() {
                return id;
           }
           public void setId(long id) {
                this.id = id;
           }
           
           @Column(name="item_name")
           @Length(max=100)
           @NotNull
           public String getName() {
                return name;
           }
           public void setName(String name) {
                this.name = name;
           }
           
           @Length(max=5)
           @Column(name="item_code")
           public String getCode() {
                return code;
           }
           public void setCode(String code) {
                this.code = code;
           }
           
           @Column(name="start_date")
           @NotNull
           public Date getStartdate() {
                return startdate;
           }
           public void setStartdate(Date startdate) {
                this.startdate = startdate;
           }
           @Column(name="initial_count")
           @NotNull
           public int getInitialCount() {
                return initialCount;
           }
           public void setInitialCount(int initialCount) {
                this.initialCount = initialCount;
           }
           @Column(name="created_user")
           @NotNull
           @Length(max=30)
           public String getCreatedUser() {
                return createdUser;
           }
           public void setCreatedUser(String createdUser) {
                this.createdUser = createdUser;
           }
           @Column(name="created_date")
           @NotNull
           public Date getCreatedDate() {
                return createdDate;
           }
           public void setCreatedDate(Date createdDate) {
                this.createdDate = createdDate;
           }
           @Column(name="modified_user")
           @Length(max=30)
           public String getModifiedUser() {
                return modifiedUser;
           }
           public void setModifiedUser(String modifiedUser) {
                this.modifiedUser = modifiedUser;
           }
           @Column(name="modified_date")
           public Date getModifiedDate() {
                return modifiedDate;
           }
           public void setModifiedDate(Date modifiedDate) {
                this.modifiedDate = modifiedDate;
           }
           @Column(name="history")
           public boolean isHistory() {
                return history;
           }
           public void setHistory(boolean history) {
                this.history = history;
           }
           @ManyToOne(fetch = FetchType.LAZY)
           @JoinColumn(name="parent_item_id")
           public AdmItems getParentItemId() {
                return parentItemId;
           }
           public void setParentItemId(AdmItems parentItemId) {
                this.parentItemId = parentItemId;
           }
           @ManyToMany(targetEntity=AdmOffices.class)
           @JoinTable(
                     name="adm_item_offices",
                     joinColumns = @JoinColumn(name = "item_id"),
                     inverseJoinColumns = @JoinColumn(name = "office_id"),
                     uniqueConstraints = @UniqueConstraint(columnNames = {"item_id", "office_id"}))
           public List<AdmOffices> getOffices() {
                return offices;
           }
           public void setOffices(List<AdmOffices> offices) {
                this.offices = offices;
           }
           
           @OneToMany(targetEntity=AdmItems.class, mappedBy="parentItemId", cascade={CascadeType.REMOVE})
           public List<AdmItems> getHistoryItems() {
                return historyItems;
           }
           public void setHistoryItems(List<AdmItems> historyItems) {
                this.historyItems = historyItems;
           }
           public AdmItems clone() {
                try {
                     AdmItems admItems = (AdmItems) super.clone();               
                     admItems.setHistoryItems(new ArrayList<AdmItems>());
                     admItems.setId(0);
                     return admItems;
                } catch (CloneNotSupportedException ex) {
                     return null;
                }
           }
           
           public AdmItems createClone() {
                try {
                     AdmItems admItems = (AdmItems) super.clone();               
                     admItems.setHistoryItems(new ArrayList<AdmItems>());
                     return admItems;
                } catch (CloneNotSupportedException ex) {
                     return null;
                }
           }
           
           @Column(name="active")
           public boolean isActive() {
                return active;
           }
           public void setActive(boolean active) {
                this.active = active;
           }
      }


      Any one please help me out from this problem