cancel
Showing results for 
Search instead for 
Did you mean: 

Embed a View into a ViewContainerUIElement at runtime.

Former Member
0 Kudos

Hi,

I've been reading and looking for information about this topic but I couldn't find an example.

Basically I need to create Tabs dynamically (into a TabStrip) an embed (in each one) a new Interface View (of a Component Instance). This Component Instace is not the same every time, it depends on a runtime condition.

Thanks in advance.

Diego.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Valery,

I was trying with your code example but I didn't arrive to a solution. I don't understand where to put each part of your code and how to complete it.

Basically my problem is: how to get an instance of a "component interface view" to embed in a

ViewContainerUIElement already created at design time.

I'll appreciate any response or example,

Best regards,

Diego.

Former Member
0 Kudos

Diego,

I plan to post a blog entry regarding this issue later this week. There are will be 3 use cases covered, your question seems to be the simplest one and it's alreay developed

You may mail me to vsilaev AT gmail DOT com and I'll sent you complete WD project as example

Here is an extract from this sample.

1. You have component SimpleContainer and component InnerA

2. SimpleContainer has component usage of InnerA (createOnDemand)

3. SimpleContainer has window SimpleContaineCW with embedded view SimpleContainerCV. View has ID assigned in window designer vuMain

4. SimpleContainerCV has exactly one ViewContainerElement with any name (for this sample it's enough -- this affects how view container assignment is found);

5. InnerA has window InnerACW and corresponding interface view InnerACWInterfaceView

6. The following code in wdDoInit of component controller of SimpleContainer does the trick:


  public void wdDoInit()
  {
    /* Get window of itself (container) */
    /* Window name is unqualified name of window (without package) */
	final IWDWindowInfo         myWindow  = wdComponentAPI.getComponentInfo().findInWindows("SimpleContainerCW");
	/* Find view inside own window (container) */
	/* You have to assign id in WD window designer -- */
	/* Embedd view, go to "Properties", set id (vuMain in this case) */
	final IWDViewUsageInfo      vuiMain   = myWindow.getViewUsageByID("vuMain");
	/* Get the very first view container assignment (vca) */
	/* We know here it exists, sometimes it's necessary to create own dynamically */
	/* Every vca may have several usages */
	/* Only one is displayed, initially the "default" is diplayed */
	final IWDViewContainerAssignmentInfo vcaiMainArea 
		= (IWDViewContainerAssignmentInfo)vuiMain.getViewContainerAssignments().iterator().next();

	/* Create a (default) view usage for component usage interface */ 
	final IWDViewUsageInfo vuiInner = vcaiMainArea.createEmbeddedViewUsage();
	
	{
		/* Setup view usage with component usage information */
		final IWDComponentUsage     cuInner   = wdThis.wdGetInnerACUComponentUsage();
		final IWDComponentUsageInfo cuiInner  = cuInner.getComponentUsageInfo();
		vuiInner.setComponentUsage( cuiInner );
		/* Interface view name = unqualified_window_name + "InterfaceView"; */
		vuiInner.setView( cuiInner.getUsedComponent().findInInterfaceViews("InnerACWInterfaceView") );
	}
	/* Mark view usage as default */
	vcaiMainArea.setDefaultViewUsage( vuiInner );
  }

Valery Silaev

EPAM Systems

http://www.NetWeaverTeam.com/

Message was edited by: Valery Silaev

(added item regarding ViewContainerElement)

Former Member
0 Kudos

Diego,

Does the sample provided solve your problem?

If so -- please close the topic, otherwise I'll be glad to assist you further.

VS

Former Member
0 Kudos

Ok, this is an update for the case when you have to create ViewContainerUIElement dynamically i.e. [4] "SimpleContainerCV has exactly one ViewContainerElement with any name" no longer valid.

So

1. In controller code comment out code:


final IWDViewContainerAssignmentInfo vcaiMainArea 
  = (IWDViewContainerAssignmentInfo)vuiMain
      .getViewContainerAssignments()
        .iterator()
          .next();

2. Instead add the following code:


/* Create view container assignment */
final IWDViewContainerAssignmentInfo vcaiMainArea = vuiMain.createViewContainerAssignment();
	
{
  final IWDViewInfo viMain  
    = (IWDViewInfo)vuiMain.getView();
  final IWDViewContainerInfo vciViewContainer 
    = viMain.createViewContainer();
		
  /* Transfer the name to view controller to setup UI element */
  wdContext.currentContextElement()
    .setViewContainerName( vciViewContainer.getName() );
  vcaiMainArea.setViewContainer( vciViewContainer ); 
}

3. Map attribute "ViewContainerName" between view and component controllers (obviously, you have to create it in component controller)

4. Add the following code in wdDoMOdifyView:


if ( firstTime )
{
  final IWDUIElementContainer group 
    = (IWDUIElementContainer)view.getElement( "grInner" );
  group.destroyAllChildren();
    	
  final IWDViewContainerUIElement container 
    = (IWDViewContainerUIElement)view.createElement
      ( 
         IWDViewContainerUIElement.class, null 
      );
    	
  /* LINK UI CONTROL AND METAINFO */
  container.setViewContainer
  ( 
     wdContext.currentContextElement()
       .getViewContainerName() 
  );
  group.addChild( container );
}

Valery Silaev

EPAM Systems

http://www.NetWeaverTeam.com/

Answers (8)

Answers (8)

Former Member
0 Kudos

I'm having the same problem. How can I delete a componentUsage that I have created at runtime? The only interface I can access is the IWDComponentUsageInfo, but I need access to the IWDComponentUsage of the created componentUsage!

Thanks in advance,

Fabian

Former Member
0 Kudos

Dear Fabian,

did you solve your problem? if so, could you explain me how? I'm facing the same and I didn't get out of this...

Thank you in advance,

Stefano

Former Member
0 Kudos

Hi all,

this works perfectly, but how do I delete the component usage so that I can create a new component usage of the same type?

Thanks in advance,

Marion

Former Member
0 Kudos

Valery,

It works perfectly. Thank you again.

Best Regards,

Diego.

Former Member
0 Kudos

Hi Valery,

thanks a lot for your response, it was excellent. I was not at work last days so I could try it just today... and it works perfectly. One more thing about this topic:

I need to create de ViewContainerUIElement at runtime. Your example uses a ViewContainerUIElement created at design time. (Step 4. "SimpleContainerCV has exactly one ViewContainerElement with any name (for this sample it's enough -- this affects how view container assignment is found);")

Could you please explain me how to do it?

Best Regards,

Diego.

Former Member
0 Kudos

Hi all,

Thanks a lot for your help. I'll try with Valery's solution.

Regards,

Diego.

Former Member
0 Kudos

Hi Valery,

Once again, thanks a lot for that information. It surely does look complex :-). I hope we can expect a blog from you on this very soon. Valery, thanks for all those wonderful blogs & articles (It took me two whole days to decode your spell checker application and build a similar one. And since I didn't know anything about CMI classes, I had to import the jazzy project itself and use it directly)

Best Regards,

Nibu.

guru_subramanianb
Active Contributor
0 Kudos

Hi Diego,

I feel that dynamic programming scenario can be done with the UI elements on a view ie putting an input

field on click of a button or enabling a table UI on click of any event.

But ur scenario of adding a view to Viewcontainer UI element I guess is not feasible.

Regards,

Guru

Former Member
0 Kudos

Hi Diego,

As far as I know, embedding of views into ViewContainer UI element is not possible at runtime.

Best Regards,

Nibu.

Former Member
0 Kudos

Nibu,

This is possible, however it is very complex topic and deserves a tutorial on their own.

Here is my message where I explained how to dynamically arrange interface views of component usages in embeder view dynamically (warning: users reports about error with this code). Arranging views of same component even simpler and use same API.

Also important hint: view you are modifying should be invisible before modification!!! So we commonly create some Bootstrap empty view, link it via navigation to actual view with dynamic content, modify dynamic view in component controller and fire plug in wdDoInit of Bootstrap.

Valery Silaev

EPAM System

http://www.NetWeaverTeam.com

P.S. I can post another extract from my code, but I will not help with mysterious NPE you may encountered. Here only debugger helps