cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamically generate the Column header

Former Member
0 Kudos

Hi friends,

I am using Binary Cache method for Export to Excel. I am using a separate method for generating the column headers. My question is : Is there a way to put the attribute names from the node directly instead of the one I am currently using.

public java.util.Map getOrderColumnInfos( )

{

//@@begin getOrderColumnInfos()

// Returns Header for the Table to be passed on to method toExcel()

Map columnInfosMap = new LinkedHashMap();

columnInfosMap.put(

IPrivateABC.ISearchResultstoExcelElement.ATTRIBUTE1,

"Name");

columnInfosMap.put(

IPrivateABCSearchResultstoExcelElement.ATTRIBUTE2,

"Reference");

columnInfosMap.put(

IPrivateABC.ISearchResultstoExcelElement.ATTRIBUTE3,

"Created By");

columnInfosMap.put(

IPrivateABC.ISearchResultstoExcelElement.ATTRIBUTE4,

"Input Date");

return columnInfosMap;

//@@end

}

Instead of putting the header texts, I want the attribute names to be displayed on the Excel file headers. Please let me know if this is possible.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Avik,

Use the below code to get dynamically the attribute.

Iterator itr = wdContext.node<YourNode>().getNodeInfo().iterateAttributes();
		 int count=0;
		 while(itr.hasNext())
		{
			 Object attr = itr.next();
			 String attrname1 = null;
			 String attrname = attr.toString();
	
			 StringTokenizer str = new StringTokenizer(attrname, " .");
			 while(str.hasMoreTokens()){
				  attrname1 = str.nextToken();
	
		 }
		 attrname1 = attrname1.replace(')',' ').trim();
}

With Regards,

Laksh

Former Member
0 Kudos

and why not just like this?


for (Iterator attributes = nodeInfo.iterateAttributes(); attributes.hasNext() ; )
{
  IWDAttributeInfo attribute = (IWDAttributeInfo) attributes.next();
  String attributeName = attribute.getName();
}

Is the Web Dynpro API really so difficult to understand?

Armin

Former Member
0 Kudos

I agree with you Armin. WebDynpro API is Simple.

With Regards,

Laksh.

Answers (4)

Answers (4)

Former Member
0 Kudos

Hello AVIK SANYAL

Please, Could you share your solution with us ?

Former Member
0 Kudos

Hello Rasim,

The idea was to create the Column headers dynamically. This means basically at runtime the Application would recognize what is there in the screen and use it for Column headers. This involved reading the from the View Table->The Table Column Element-> The header and saving those values in a Context. This context is then mapped to the Excel Custom Controller and then all we have to do is read from the context, Convert to XML (The usual way that is.... )

And ...There it is....!!!!

Bit hectic to code this than the obvious Map and stuff. But it saves a lot of headache for future additions/deletions of columns to the table.

Sample Code :


  public void populateExcelColumnsFromView( java.lang.String tableName, com.sap.tc.webdynpro.progmodel.api.IWDView view )
  {
    //@@begin populateExcelColumnsFromView()

		//Created By : AVIK SANYAL Date : 28 March 2008
		//This method will fetch the header names from the Table in the View and set the 
		// Attributes in nodeExcelTableColumns(). These nodes are mapped to 
		//Excel Custom Controller and hence used to set the Column headers for the Excel File. 
		IWDTable searchTable = (IWDTable) view.getElement(tableName);
		wdContext.nodeExcelTableColumns().invalidate();
		String tableDataSource = searchTable.bindingOfDataSource();
		wdContext.currentContextElement().setDataSource(tableDataSource);

		for (int i = 0; i < searchTable.numberOfGroupedColumns(); i++) {
			//			Read the Column
			IWDTableColumn col =
				(IWDTableColumn) searchTable.getGroupedColumn(i);
			IWDTableCellEditor TCE = col.getTableCellEditor();
			IWDCaption header = col.getHeader();
			//			This will check if the column is visible in the View only then it will 
			//			go for further processing.
			if (WDVisibility.VISIBLE.equals(col.getVisible())) {
				IExcelTableColumnsElement columnElement =
					wdContext
						.nodeExcelTableColumns()
						.createExcelTableColumnsElement();
				//			If the header is not null then set the header as in the View
				if (header != null) {
					columnElement.setHeading(header.getText());
				} else {
				}
				//			Add the column name to the nodeExcelTableColumns()
				//This checks the type of column in the View and then take the value.
				if (TCE != null) {
					if (TCE instanceof IWDTextView) {
						IWDTextView element = (IWDTextView) TCE;
						columnElement.setBinding(element.bindingOfText());
						wdContext.nodeExcelTableColumns().addElement(
							columnElement);
					}
				}
			}
		}
    //@@end
  }

Former Member
0 Kudos

Thank You. I found a solution.

Former Member
0 Kudos

Thanks friends, Your inputs were very helpful.

Regards

Avik

Former Member
0 Kudos

Hi,

I want the attribute names to be displayed on the Excel file headers. Please let me know if this is possible

To get the attribute name use as follows



wdContext.node<YourNode>().getNodeInfo().getAttribute("Your Attribute").getName()
	  wdContext.getNodeInfo().getAttribute("Your Attribute").getName()

Regards

Ayyapparaj

Former Member
0 Kudos

OK That's fine Ayappa. But how to get them dynamically and map it to ColumnInfos. The reason is, a lot of changes are taking place and it becomes difficult to map them over and over again.

Former Member
0 Kudos

What is this map supposed to contain? Attribute name to column title mappings? For all attributes in the node or only a subset?

Armin