cancel
Showing results for 
Search instead for 
Did you mean: 

wdDoModifyView + how many times it executed ?

Former Member
0 Kudos

Hello friends,

is wdDoModifyView only executes only once, or always when the control comes back in view....

regards,

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

HI,

It would be executed every time an action is fired and even when control comes back unlike wdDoInit() which is executed only once during its entire life cycle.

Regards,

Murtuza

Former Member
0 Kudos

then why not my table is updated ?

I mean first times things goes good, but second time the result table in view is not updated.....

Any idea what's going wronge ?

Regards,

Former Member
0 Kudos

Hi,

Check if you have put the entire code within the

if(firstTime)

block.

Regards,

Satyajit.

Former Member
0 Kudos

Hi,

If you have written your code in

if(firstTime)

{

//your code

}

then it will be executed only once if you want it to be executed always then remove that if clause.

Regards,

Murtuza

Former Member
0 Kudos

I have removed the firsttime statement, and now I am getting this error:

com.sap.tc.webdynpro.services.exceptions.WDRuntimeException: View: Cannot add element with duplicate ID "Matnr" of type com.sap.tc.webdynpro.clientserver.uielib.standard.impl.TableColumn

so is it possible that i do clear the result table, everytime before filling the table ?

Regards,

Former Member
0 Kudos

so you are trying to add columns dynamically.

If you want that only at the first time then write that portion of code within

if(firstTime)

{

//creation of table columns

}

//rest of the code outside the if block that you need to execute everytime.

Regards,

Murtuza

Former Member
0 Kudos

how do u come to know if I am creating table dynmically ?

Secondlly I tried with following, but same exception:

tv.removeAllColumns();

Actually the table columns need to be modify each time, ....if it helps I can past the code as well

Regards,

Former Member
0 Kudos

Hi,

please copy your code here as that would be helpful.

Regards,

Murtuza

Former Member
0 Kudos

okey,

//@@begin wdDoModifyView

IWDMessageManager mm = wdThis.wdGetAPI().getComponent().getMessageManager();

IWDTable tv = (IWDTable)view.getElement("resultTable");

tv.bindDataSource(wdContext.currentContextElement().getApplication());

int size = wdThis.wdGetFieldControllerController().wdGetContext().nodeZfld_Name().size();

int size_fld = wdThis.wdGetDownloadControllerController().wdGetContext().nodeZvar_Fld().size();

String omit_field = "";

ArrayList omit_list = new ArrayList();

for (int a = 0; a < size_fld; a ++ ) {

omit_field = wdThis.wdGetDownloadControllerController().wdGetContext().nodeZvar_Fld().getZvar_FldElementAt(a).getAttributeValue("Fieldname").toString();

omit_list.add(a, omit_field);

}

// if (firstTime)

// {

tv.removeAllGroupedColumns();

for (int i = 0; i < size; i++)

{

String fieldName =

wdThis

.wdGetFieldControllerController()

.wdGetContext()

.nodeZfld_Name()

.getZfld_NameElementAt(i)

.getFieldname()

.toLowerCase();

String rangeType =

wdThis.wdGetFieldControllerController().wdGetContext().nodeZfld_Name().getZfld_NameElementAt(i).getDdtext();

if (rangeType.compareToIgnoreCase("to") != 0)

{

String fieldText =

wdThis.wdGetFieldControllerController().wdGetContext().nodeZfld_Name().getZfld_NameElementAt(i).getDdtext();

fieldName = WDUtil.getJavaNameForAbapFieldName(fieldName);

String attrName = wdContext.currentContextElement().getApplication() + "." + fieldName;

String testfield = fieldName.toUpperCase();

if ( omit_list.contains(testfield)) {

//mm.reportSuccess("this is omit field" + testfield);

} else {

//tv.removeAllColumns();

IWDTableColumn column = (IWDTableColumn)view.createElement(IWDTableColumn.class, fieldName);

IWDTextView textView = (IWDTextView)view.createElement(IWDTextView.class, null);

IWDCaption caption = (IWDCaption)view.createElement(IWDCaption.class, null);

column.setTableCellEditor(textView);

column.setHeader(caption);

textView.bindText(attrName);

caption.setText(fieldText);

tv.addColumn(column);

}

// if (fieldName.equalsIgnoreCase("VBELN")) {

//

// mm.reportSuccess("This is vbeln");

// } else {

// IWDTableColumn column = (IWDTableColumn)view.createElement(IWDTableColumn.class, fieldName);

// IWDTextView textView = (IWDTextView)view.createElement(IWDTextView.class, null);

// IWDCaption caption = (IWDCaption)view.createElement(IWDCaption.class, null);

// column.setTableCellEditor(textView);

// column.setHeader(caption);

// textView.bindText(attrName);

// caption.setText(fieldText);

// tv.addColumn(column);

// //}

// if (fieldName.equalsIgnoreCase("VBELN")) {

//WDVisibility visibility = (WDVisibility)column.getVisible();

//column.setVisible(WDVisibility.NONE);

}

// column.setHeader(caption);

// textView.bindText(attrName);

// caption.setText(fieldText);

// tv.addColumn(column);

// }

}

saveColumns = tv.getColumns();

// }

if (rebuildScreen)

{

IWDTableColumn[] tcArray = saveColumns;

tv.removeAllColumns();

Map hMap = new HashMap();

for (int x = 0; x < tcArray.length; x++)

{

IWDTableColumn tc = (IWDTableColumn)tcArray[x];

String tcID = tc.getId();

for (int i = 0; i < size; i++)

{

boolean omit =

wdThis.wdGetFieldControllerController().wdGetContext().nodeZfld_Name().getZfld_NameElementAt(i).getOmit();

String dispSeq =

wdThis

.wdGetFieldControllerController()

.wdGetContext()

.nodeZfld_Name()

.getZfld_NameElementAt(i)

.getDispseq();

String fieldName =

wdThis

.wdGetFieldControllerController()

.wdGetContext()

.nodeZfld_Name()

.getZfld_NameElementAt(i)

.getFieldname();

String rangeType =

wdThis.wdGetFieldControllerController().wdGetContext().nodeZfld_Name().getZfld_NameElementAt(i).getDdtext();

if (rangeType.compareToIgnoreCase("to") != 0)

{

fieldName = WDUtil.getJavaNameForAbapFieldName(fieldName);

if (tcID.equals(fieldName) && dispSeq.trim().length() > 0 && omit == false)

{

hMap.put(dispSeq, tcArray[x]);

}

}

}

}

Map sortedMap = new TreeMap(hMap);

Iterator iter = sortedMap.entrySet().iterator();

while (iter.hasNext())

{

Map.Entry entry = (Map.Entry)iter.next();

IWDTableColumn tc = (IWDTableColumn)entry.getValue();

tv.addColumn(tc);

}

tv.setFirstVisibleRow(0);

wdContext.currentContextElement().setTableSorter(new TableSorter(tv, wdThis.wdGetSortAction(), null));

}

rebuildScreen = false;

//@@end

Regards,

Former Member
0 Kudos

Hi,

Keep the code same.

Just write this at the first line in your wdDoModifyView()

view.resetView();

Regards,

Murtuza

Former Member
0 Kudos

gr8 man it worked.....

Can you be more descrptive, how it works, or could you please recommand me some documentation to understand better the web dynpro architecture or so.... I am java/abap developer and new to web dynpro...

points awarded

Regards,

Former Member
0 Kudos

The problem with your previous code was that modify view was called more than once and again and again it was trying to create a column with the same name and thus it resulted into an error.

When we reset the view all the dynamically created contents will be removed and thus even if modify view is called again it will allow you to create those columns with the same name.

But man this is not a good approach as wdDoModifyView is called manier times and everytime you are creating those columns dynamically it should generally be within if(firstTime) block so that those creation won't take place again and again.

But your requirement asked it to be created everytime.

So this is how it works.

Regards,

Murtuza

Former Member
0 Kudos

you know how it work in adhoc projects, once you created for one requirements and then later add ons

So it was first created only to display the columns, and thus firsttime statement was working fine, and now I have to adjust new customer requirement and that's why all this

any way suggest anyother approach how to do so, like instead of omitting fields in wdDomodifyview...

Seconly any good documenation which you would like to refer to understand the arch or so....

Regards,

Former Member
0 Kudos

But for any dynamic coding, you can do it only in wdDoModifyView() so no other way out. Just you can fine tune it as per your business requirement.

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/74cda090-0201-0010-6b91-f85b2489...

Cheers,

Murtuza

Former Member
0 Kudos

We had the same requirement for one of our applications. Initially we created columns dynamically but the performance was so slow. users did not like it. So alternatively we created some max number of columns at design time and depending on the data we hide or show a specific column. Performance was lot better.

Hope it helps

Regards

Firasath

Former Member
0 Kudos

hello Firasath,

Thanks for your reply, actually we cant fix the columns, as the user is provided an option to set the VARIANT ,and based on this variant we have to display the columns ...

Any way, thanks for your response...

Regards,

Answers (1)

Answers (1)

Former Member
0 Kudos

wdDoModifyView() is always executed when a view is displayed

This method should only be used for modifying the view, i.e. adding/removing/rearranging UI elements.

You should not use this method to set UI element properties that also may be manipulated using data binding. Data binding is the preferred way for setting property values or changing selections