Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Printing in JAVA Webdynpro

Hello All,

I am trying to print couple of tables from an iview. The tables data can go upto two pages. Both tables are in my same Iview. I followed the following blog but I could not get the print window to show up...

/people/sap.user72/blog/2006/05/04/enhancing-tables-in-webdynpro-java-150-custom-built-table-utilities

What I did as follows:

under my view implementation: I added following:

1)

public static void wdDoModifyView(IPrivateOutput_view wdThis, IPrivateOutput_view.IContextNode wdContext, com.sap.tc.webdynpro.progmodel.api.IWDView view, boolean firstTime)

{

//@@begin wdDoModifyView

if(firstTime) {

wdContext.currentContextElement().

setTableutility(new TableUtilities(wdContext.nodeZbapi_Op()));

}

//@@end

}

2) created a button...with an action...

3) under this action...I added my code as follows:

public void onActionprint(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )

{

//@@begin onActionprint(ServerEvent)

ArrayList al = new ArrayList();

al.add(wdContext.nodeZbapi_Op().currentZbapi_OpElement().FLDATE);

al.add(wdContext.nodeZbapi_Op().currentZbapi_OpElement().CARRID);

//wdContext.currentContextElement().setPrinttable((String)wdContext.currentContextElement().getTableutility().printTable(al,"Summary","SDN //Print Demo Table").get("url"));

wdContext.currentContextElement().getTableutility().

printTable(al,"testing","testing2");

//@@end

}

I could not find "setPrinttable" function so I modified the code as above compare to the blog.

Now if i click on the print button...it does not do anything...does not bring any print window or anything like that...

Anyone have any idea about this....

help is greatly appreciated....

Thanks....

replied

Hi,

Below is the code to open a HTML window from WDJava, with data from WDJava...

Inside DoInit()

IWDAttributeInfo attr1 =

wdContext.getNodeInfo().getAttribute("htmlfile");

ISimpleTypeModifiable mtype1 = attr1.getModifiableSimpleType();

IWDModifiableBinaryType btype1 = (IWDModifiableBinaryType) mtype1;

btype.setFileName(attr.getName() + ".html");

btype.setMimeType(WDWebResourceType.HTML);

_contentType = mtype;

Where htmlfile is a context attribute of type binary... and do a global declaration like this

ISimpleTypeModifiable _contentType = null; (This declaration can be done at the end of your view's coding between Begin Others and End Others)

Now,

inside on action print

public void onActionPrintData(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent, java.lang.String videoName )

{

//@@begin onActiondisplayVideo(ServerEvent)

byte[] content = new byte[4028];

try {

content = this.displayPrint().getBytes("UTF-8");

wdContext.currentContextElement().setHtmlfile(content);

wdContext.currentPrintElement().setAttrUrl(

_contentType.format(content));

//Where content is loaded with data from displayPrint() method, which is holding the HTML *page to be displayed to the user *

IWDWindow win =

wdThis

.wdGetAPI()

.getComponent()

.getWindowManager()

.createNonModalExternalWindow(WDWebResource

.getWebResource(content, WDWebResourceType.HTML)

.getURL(),"ShowVideo");

win.setWindowSize(445,460);

win.removeWindowFeature(WDWindowFeature.ADDRESS_BAR);

win.removeWindowFeature(WDWindowFeature.TOOL_BAR);

win.removeWindowFeature(WDWindowFeature.MENU_BAR);

//win.open();

win.show();

// wdComponentAPI.getMessageManager().reportSuccess("444444444444");

} catch (Exception e) {

wdComponentAPI.getMessageManager().reportException ("Unable to open window"+e,false);

}

//@@end

}

Now finally, design your HTML Page inside the method displayPrint() like this

public java.lang.String displayPrint( java.lang.String strVideoName )

{

//@@begin displayPrint()

String htmlcontent=null;

htmlcontent="content what you want to show in print window";

use script inside the html content to do a print... like window.print();

return htmlcontent;

//@@end

}

Regards,

Srinivas

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question