cancel
Showing results for 
Search instead for 
Did you mean: 

Control visibility

Former Member
0 Kudos

Hi All,

I have 10 Tables in my view, Now, according to the R/3 values I have to control the visibility of the control.

For example, if R/3 returns 3, Then I havew to show only 3 tables in the view.

So, How to control the visibility of the Tables in an view depending upon the R/3 values.

Quick reply will be appreciated...

Regards/Guru

Accepted Solutions (0)

Answers (5)

Answers (5)

Former Member
0 Kudos

Hi Kumara

Create 10 context attributes in the view's context in which u are having those 10 tables.Right Click in one of the attribute and click on properties option to get the properties window.Change the type of the attribute to Visibility by clicking on the

Local Dictionary --> uielementdefinitions.Change the type of the rest of the attribute.Write the code for setting the visibility of individual table according to the condition as follows

wdContext.currentContextElement().setCtx_Table1Visibility(WDVisibility.NONE);

OR

wdContext.currentContextElement().setCtx_Table1Visibility(WDVisibility.VISIBLE);

xxxxxxxxxxxxxxxxxxxxxxxx.

Message was edited by:

Armin Reichert

abhijeet_mukkawar
Active Contributor
0 Kudos

hi,

could you solve this problem?

regards,

abhijeet

former_member189631
Active Contributor
0 Kudos

Hi Kumara,

this is disuccussed in this Link..

Please gothough this ,

https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webdynpro/creating...

See from 32nd Page of this Tutorial.

Regards,

Ramganesan K.

former_member189631
Active Contributor
0 Kudos

Hi KumaraGuru,

Please create a context attribute say "TblVisiblity". The type

of this should be "visibility". and then Map them with ur

Table property "Visibility".

U can set the visibility by write the code to set the visibility for ur table,

Its thr in "Quiz Application Tutorial ".

Regards,

Ramganesan K.

Former Member
0 Kudos

Hi,

I know how to set the visibility of the UI elements.

But Iw ant to know how to loop the UI elements in a view...

example:

Tab1

-


Table1

-


Visble

-


Table2

-


Visible

-


Table 3

-


Visible

for(int i=0; i<wdcontext.nadeTablesize.Size();i++) //Assume that my Table size is 5 which is taken from BAPI, So, I have to display 5 Tables out of 10 Tables in the View

{

// Now tell me how to loop the each Table node, to set the visibility as True...

{

abhijeet_mukkawar
Active Contributor
0 Kudos

hi,

craete 10 tables and with id like table1, table2, ...so on...

in WDModify write following code...

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

{

IWDTable tab = (IWDTable) view.getElement("Table"+i);

tab.setVisible(WDVisibility.VISIBLE)

} // !!!!! Do not set hardcoded property values in wdDoModifyView() - use context data binding instead, Bertram

i hope this will solve your problem

regards,

abhijeet

Message was edited by:

abhijeet mukkawar

Message was edited by:

abhijeet mukkawar

Message was edited by:

Bertram Ganz

former_member189631
Active Contributor
0 Kudos

To hide a table:

wdContext.getContext.currentContextElement.setTble1Visibility(Visibility.None);

To Show a Table:

wdContext.getContext.currentContextElement.setTble1Visibility(Visibility.visible);

Like this u have to write the code to set the visibility for a table.

Regards,

Ramganesan K.

sid_sunny
Contributor
0 Kudos

Hi Kumara

You can write this in wdDoModiy

IWDTable a = (IWDTable)view.getElement("Table3");

a.setVisible(WDVisibility.VISIBLE);

Regards

Sid

Former Member
0 Kudos

Hi Abhijeet,

I have implemented ur code, But I am getting null pointer Exception:

I have declared

<b> static IWDView myView;</b> - in view.java

<b>>>>> NO: NEVER EVER reference the view object in a static variable. All running application instances will then point to the same view object, Bertram Ganz</b>

and created a method called visible. in the Wddomodifyview i have set

myview=view;

wdthis.visible;

visible()

{

for(int j=0;j<=6;j++)

{

IWDTable tables= (IWDTable)myView.getElement("Table"+j);

tables.setVisible(WDVisibility.VISIBLE);

}

}

I am not getting the table element with the given id's. I have checked my table id's... it starts from Table0,Table1,Table2..Table20.

Regards/Guru

Message was edited by:

Bertram Ganz

sid_sunny
Contributor
0 Kudos

Hi Kumara,

First of I think this solution I suggested you in the other forum and not abhijeet.

and regarding your error:

you are not passing the value of "view" to "visible" method. Define a method as suggested by me in your other thread.

and pass the value of wdDoModify view to this method and dont forget to define the methos as static.

Regards

Sid

abhijeet_mukkawar
Active Contributor
0 Kudos

hi,

is your 'myview' getting set properly, i think that is not getting set properly

otherwise instead of that directly use 'view'

IWDTable tab = (IWDTable) view.getElement(<table name>);

same code is working fine for me.

regards,

abhijeet

Message was edited by:

abhijeet mukkawar

Former Member
0 Kudos

Hi Abhijeet,

Yes, I am getting the Set Property in my "myview". When I try to do it Wddomodify....

I have specified...

IWDTable tables = (IWDTable)myView.getElement("Table1"); - "Tables1 is the ID of my first Table.

tables.setVisible(WDVisibility.NONE);

It throws an exception as "Null Pointer Exception"

Regards/Guru

abhijeet_mukkawar
Active Contributor
0 Kudos

hi,

sorry for the delay,

now follow the steps,

declare

static IWDView myview; in global scope, ie at the end of view in @begins and @end

<b>>>>> NO: NEVER EVER reference the view object in a static variable. All running application instances will then point to the same view object, Bertram Ganz</b>

initialise this as

myview = view; in wdmodify.

call from whereever you want give call to your method visible() having following code,

for(int i = 1;i<bapireturn;i++)

{

IWDTable tab = (IWDTable)myview.getElement("Table"+i);

tab.setVisible(WDVisibility.NONE);

}

here you do not need to pass view as an argument since it is declares as static in global scope.

it will solve you problem

regards

Message was edited by:

abhijeet mukkawar

Message was edited by:

abhijeet mukkawar

Message was edited by:

Bertram Ganz

BeGanz
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hello,

<b>Never ever keep a reference to an object passed to the wdDoModifyView() method in a static member variable.</b>

Please take a Java book of your choice and find out what "<b>static</b>" really means.Now let's have a look at a newly generated wdDoModifyView method. I have marked the passage with >>>>>> that explains that you should not keep references to a UI element and access them from your event handler. We thought that making wdDoModifyView() static would stop people from following this way of programming which is strongly discouraged in Web Dynpro. However, those, who are not very accustomed with the details of the Java language may now be led astray and just make their variables "static". This, of course, wreaks havoc in a multi user environment, because all running application instances share the same static member.

I don't think it is too helpful to understand the details of multi-threaded programming and why one small change seems to repair the problem. Rather, we should focus on the correct way to do it, which is quite easy.

<b>SOLUTION: create 10 separate context value attributes of type WDVisibility and bind every table UI element instance to one of these attributes.</b> Just apply data binding but do implement "error-code".

Best regards, Bertram

  /**
   * Hook method called to modify a view just before rendering.
   * This method conceptually belongs to the view itself, not to the
   * controller (cf. MVC pattern).
   * >>>>>>> It is made static in order to discourage a way of programming that
   * >>>>>>> routinely stores references to UI elements in instance fields
   * >>>>>>> for access by the view controller's event handlers etc.
   * >>>>>>> The Web Dynpro programming model recommends to restrict access to
   * >>>>>>> UI elements to code executed within the call to this hook method!
   *
   * @param wdThis generated private interface of the view's controller as
   *        provided by Web Dynpro; provides access to the view controller's
   *        outgoing controller usages etc.
   * @param wdContext generated interface of the view's context as provided
   *        by Web Dynpro; provides access to the view's data
   * @param view the view's generic API as provided by Web Dynpro;
   *        provides access to UI elements
   * @param firstTime indicates whether the hook is called for the first time
   *        during the lifetime of the view
   */
  //@@end
  public static void wdDoModifyView(IPrivateBusinessPartnerSearch wdThis, IPrivateBusinessPartnerSearch.IContextNode wdContext, com.sap.tc.webdynpro.progmodel.api.IWDView view, boolean firstTime)
  {
    //@@begin wdDoModifyView
    //@@end
  }

Former Member
0 Kudos

STOP!

Don't define a static reference for holding the view or view element instances. This will not work.

Use context attributes and data binding instead of accessing the table instance.

Armin

sid_sunny
Contributor
0 Kudos

Hi Kumara

Did you search before asking this question on forum. I guess not.

Its a very basic question I suggest you find it yourself it will help you learn more rather directly asking in forums.

By the way you can do this buy controlling the visibility property of the Table UI element.

Regards

Sid