6 Replies Latest reply on Aug 14, 2008 4:41 PM by tomek szzzaaos

    EntityManager and popup

    tomek szzzaaos Newbie

      Hi,


      having problem with EntityManager resolving to null, but its a bit odd.



      @Stateful
      @Name("cart")
      @Scope(value=ScopeType.SESSION)
      public class ShoppingCartBean implements Serializable, ShoppingCart, PopupCloseListener{
      
           @In(required=true)
           private EntityManager entityManager;
      
              @In
              private Popup popup;
      
              public ShoppingCartBean(){
                     popup.addCloseListener(this);
              }
      
              public void popupClosed(PopupDialogBean dialog) {
                     //here entityManager is empty
              }
      
              public void removeLine() {
                     //entityManager works fine here 
              }
      }
      



      it only happens in the method popupClosed which is called from another seam component, should I expect the entityManager be not null, is it normal behavior?


      I know it might look bit odd but I can't find other way to implement the modal popup panel(Icefaces) with facelets, could anyone point me to right example?


      Thank you,
      Tomek

        • 1. Re: EntityManager and popup
          Joshua Jackson Master

          How does your facelets page code look like?

          • 2. Re: EntityManager and popup
            tomek szzzaaos Newbie

            Thanks for your replay, ok Lets try... :)


            The main-template.xhtml contains header, footer, content part and the ice:panelPopup, so thats allow to block hole page instead of just one part.


            In the content template(below) there is a leftmenu (which might include  shopping cart and search box),
            and the main
            content which contains the main part of the page which could be product details(or ex. search results).


            main-template.xhtml:


            <html xmlns="http://www.w3.org/1999/xhtml"
                    ...>
                    <head>...</head>
            
                    <body>
                            <ice:form rendered="#{!empty cart}">
                                 <ice:panelPopup styleClass="panelPopup"
                                            modal="#{popup.dialog.modal}"
                                            rendered="true"
                                            visible="#{popup.dialog.visible}">
                                       
                                        //simple yes/no question here
            
                                 </ice:panelPopup>
                            </ice:form>
                            <div class="page">
                                    <div class="header">      
                                            <ui:include src="header.xhtml">
                                                    <ui:param name="projectName" value="Webshop" />
                                            </ui:include>                             
                                    </div>
                                    
                                    <div class="content">                             
                                            <ui:insert name="content" />
                                    </div>
                            
                                    <div class="footer">
                                            <ui:include src="footer.xhtml" />
                                    </div>
                            </div>
                    </body>
            </html>




            and the content-template.jspx looks like:


            <div xmlns="http://www.w3.org/1999/xhtml"
                 xmlns:ui="http://java.sun.com/jsf/facelets" style="height:100%"
                 xmlns:ice="http://www.icesoft.com/icefaces/component">
                
                    
                    <div class="left_content">
                            <ice:form partialSubmit="true">
                                    <div class="left_content_header">#{leftContentHeader}</div>
                                    <ui:insert name="left_content"/>
                            </ice:form>
                    </div>
                    <div class="center_content">                      
                            <ice:form partialSubmit="true" enctype="multipart/form-data">
                                    <div class="center_content_header">#{contentHeader}</div>
                                    <ui:insert name="center_content"/>
                            </ice:form>
                    </div>                            
                    
                    <div id="sidebar">                                
                            <ui:insert name="sidebar" />
                    </div>
                     
            </div>



            and the part where Im trying to display the popup from:




            <ui:composition xmlns="http://www.w3.org/1999/xhtml"
                    ...
                    template="layout/main-template.xhtml">
                    
                    
                    <ui:define name="content">
            
                            <ui:decorate template="layout/content-template.jspx">
                                    
                                    <ui:define name="left_menu">
                                            <ui:include src="ui-components/search-box.xhtml"></ui:include>
                                            <ui:include src="ui-components/cart-box.xhtml" />
                                    </ui:define>
                                    
                                    <ui:define name="main_content">
                                         //search results, product info etc.
                                         //the popup panel is called from here and would be great if I could add it here
                                            <div class="stock_display">
                                                    <ice:panelGrid columns="1">                                       
                                                            <ice:panelGrid columns="2">
                                                                    <s:graphicImage styleClass="image"
                                                                            rendered="#{not empty stock.image.activeFullsizeImage}" 
                                                                            value="#{stock.image.activeFullsizeImage}"
                                                                            alt="#{stock.image.description}">
                                                                    </s:graphicImage>
                                             ...
                                    </ui:define>
            ...
            </ui:composistion>


            • 3. Re: EntityManager and popup
              judy guglielmin Novice

              You might try the property clientOnly for the panelPopup and set it to true.(this is new with ICEfaces1.7.1)


              This performs better in standard jsf request scope (for Seam).  But also, it is also not such a great idea to put the partialSubmit to true on the form itself.  It's better practice to place it only on the components you really need to validate,etc via ajax. Do you have other beans which are bypassing the interceptors active at this time?  This can also affect injection when using ICEfaces.

              • 4. Re: EntityManager and popup
                tomek szzzaaos Newbie

                It took me a while to be able to answer to your question, cos I'm just starting with seam.


                Anyway I have no other beans bypassing the interceptors. Other thing is that not only EntityManager is null, but any other seam component injected using @In is null as well, apart of @Logger private Log log.
                So I'm doing something wrong, could try anyone to spot the problem?



                Here are my popup classes:


                @Name("popup")
                @Scope(value=ScopeType.SESSION)
                public class PopupAction implements Popup, Serializable  {
                
                     private PopupDialogBean popupDialog;
                     
                     public PopupAction() {
                          popupDialog = new PopupDialogBean();
                     }
                     
                     public PopupDialogBean getDialog() {
                          return popupDialog;
                     }
                
                     public void setDialog(PopupDialogBean popupDialog) {
                          this.popupDialog = popupDialog;
                     }
                     
                }




                public class PopupDialogBean implements Serializable {
                
                     public enum Type{
                          YES_NO,
                          OK
                     }
                     
                     private static final long     serialVersionUID     = -7871399779158178271L;
                     private boolean visible;
                     private boolean modal;
                     private boolean draggable;
                        private boolean autoCentre;
                        private String text;
                        private String header;
                        private boolean booleanResponse;
                        private Type type;
                     
                     private Set<PopupCloseListener> closeListeners;
                     
                
                     public PopupDialogBean() {
                          closeListeners = new HashSet<PopupCloseListener>(); 
                     }
                     
                     public void close() {
                          visible = false;
                          for(PopupCloseListener listener: closeListeners) {
                               listener.popupClosed(this);
                          }
                        }
                
                     public void addCloseListener(PopupCloseListener l) {
                          closeListeners.add(l);
                     }
                
                     public void removeCloseListener(PopupCloseListener l) {
                          closeListeners.remove(l);
                     }
                     
                     public boolean booleanResponse() {
                          return booleanResponse;
                     }
                
                        //getters and setters removed
                }


                • 5. Re: EntityManager and popup
                  judy guglielmin Novice

                  Some of the ajax functions with ICEfaces bypass the interceptors, but you will get the injection on the creation of the bean.  You could copy them on initialization into other attributes in an init method.  This doesn't have to be a session-scoped bean by the way:-


                  @Create
                  public void init(){
                  //put your stuff from your contstructor here and check the values of your
                  // injected attributes.  You can also copy them into other non-injected class 
                  //attributes 
                  }
                  


                  If you want more detailed assistance, you could always post a simple sample of your app to the ICEfaces forum

                  • 6. Re: EntityManager and popup
                    tomek szzzaaos Newbie

                    Thanks for help, will post to the ICEfaces forum for the further help.


                    Best regards,
                    Tomek