Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Printing non-visible objects

    Hi,

    I'm trying to use SmartGWT's inbuilt printing support to print objects spanned on multiple tabs in TabSet. My first tab contains a DynamicForm for editing the item's details and in addition of this I have a few tabs with ListGrid's containing data related to the item. I have a print button to print all details of the item which is implemented with Canvas.printComponents(Object[]).

    It seems that the printing fails because the hidden tabs have not yet been drawn or refreshed when calling Canvas.printComponents. If I manually go through the tabs (and they get drawn) and afterwards click print it works ok. I've tried a few workarounds in line of

    Code:
    if(!tab2Grid.isDrawn())
        tab2Grid.draw();
    if(!tab3Grid.isDrawn())
        tab3Grid.draw();
    Canvas.printComponents(...);
    ...
    This actually kind of works but what gets printed out with grids is wrong. It seems to print the actual outlook of the widgets instead of the print html which I'm expecting. Is there a way to "initialize" the tab grid widgets before calling printComponents so that they work as expected in the print out ?

    Thanks!
    Marko

    #2
    Forgot environment details, I'm using smartgwt-2.5-nightly20110604 and tested this with Mac's Chrome & Safari.

    --
    Marko

    Comment


      #3
      Your general approach (ensuring all components are drawn, then printing) is fine. How do you mean it prints the "outlook" of the components?

      Comment


        #4
        Hi,

        > How do you mean it prints the "outlook" of the components?

        The object I explicitly call .draw() on prints out with the actual outlook as if I've printed out the page directly from the browser (it prints out the "real" html instead of "print html" for some reason). This happened only rarely - not always.

        In addition I noticed that when printing out hidden SectionStack items the SectionStack Section headers won't print out. If I manually activate the tab where the SectionStack resides and then print the section stack prints with section headers ok.

        Comment


          #5
          We can't see a possible cause for either problem. Can you create a runnable test to demonstrate either one?

          Comment


            #6
            Hi,

            Here you go:

            Code:
            public class SectionStackTest implements EntryPoint {
            
                private VLayout viewport;
            
                private SectionStack tab1stack, tab2stack, tab3stack;
                
                public void onModuleLoad() {
                    // our viewport
                    viewport = new VLayout();
                    viewport.setWidth100();
                    viewport.setHeight100();
            
                    TabSet tabs = new TabSet();
                    
                    Tab tab1 = new Tab("tab1");
                    tab1stack = getTestStack("ts1");
                    tab1.setPane(tab1stack);
                    
                    Tab tab2 = new Tab("tab2");
                    tab2stack = getTestStack("ts2");
                    tab2.setPane(tab2stack);
            
                    Tab tab3 = new Tab("tab3");
                    tab3stack = getTestStack("ts3");
                    tab3.setPane(tab3stack);
            
                    tabs.setTabs(tab1, tab2, tab3);
            
                    Button printButton = new Button("Print with draws");
                    printButton.addClickHandler(new ClickHandler() {
                        public void onClick(ClickEvent clickEvent) {
                            if(!tab2stack.isDrawn())
                                tab2stack.draw();
                            if(!tab3stack.isDrawn())
                                tab3stack.draw();
                            Canvas.printComponents(new Object[] { tab1stack, tab2stack, tab3stack });
                        }
                    });
            
                    Button printNoDrawButton = new Button("Print with no draws");
                    printNoDrawButton.addClickHandler(new ClickHandler() {
                        public void onClick(ClickEvent clickEvent) {
                            Canvas.printComponents(new Object[] { tab1stack, tab2stack, tab3stack });
                        }
                    });
                    
                    viewport.addMember(tabs);
                    viewport.addMember(printButton);
                    viewport.addMember(printNoDrawButton);
                    viewport.draw();
                }
                
                public SectionStack getTestStack(String n) {
                    SectionStack s = new SectionStack();
                    s.setTitle(n);
                    SectionStackSection ss = new SectionStackSection(n + "section");
                    ss.setItems(new Label(n + " section stack content"));
                    s.addSection(ss);
                    return s;
                }
            }
            Tested with 2.5 2011-07-07 nightly. The printout is quite random and hard to describe so I'll suggest you'll try it out yourself.

            br,
            Marko

            Comment


              #7
              Thanks for the test case. We've fixed these issues (fixes will be present in the up coming 2.5 release)

              Comment

              Working...
              X