cancel
Showing results for 
Search instead for 
Did you mean: 

insert linktoaction in Webdynpro

Former Member
0 Kudos

hi

I wanted to ask you that I'm using webdynpro recently and I have to do a program that does something like that

I enter the LinkToAction automatically according to the cycle for.ti make an example so it is easier

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

/ / Put the LinkToAction

/ / Put the LinkToAction.Text

)

can do something like that???

Regards

Banana

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Friend,

You can Do by this way..


for (int = 0; i <10; i + +) (
/ / Put the LinkToAction
	  IWDLinkToAction link =wdContext.node<valueNode>)
         .create<valueNode>Element().get<ValueAttributeofTypeLinkTOAction>();
	  link.setContextMenuId("linkToAction");
	 
	  link.setOnAction(IWDAction);
	  link.setVisible(value)
// Keep setting the properties for desired relsult.
/ / Put the LinkToAction.Text
	 link.setText("SomeText");
)

Regards

Jeetendra.

Former Member
0 Kudos

Thanks for letting me Dreams4Desires responded

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

/ / Put the LinkToAction

IWDLinkToAction link = wdContext.nodeClassi().createProvElement().getVarLinkToAction();

link.setContextMenuId (linkToAction ");

link.setOnAction (IWDAction);

link.setVisible (value);

/ / Keep setting the desired properties for relsult.

/ / Put the LinkToAction.Text

link.setText (SomeText ");

)

but the error is

-Type mismatch:cannot convert from String to IWDLinkToAction -> IWDLinkToAction link = wdContext.nodeClassi().createProvElement().getVarLinkToAction();

-The method setContextMenuId (String) is undefined for the type IWDLinkToAction -> link.setContextMenuId (linkToAction ");

-IWDAction not be resolved -> link.setOnAction (IWDAction);

-value can not be resolved -> link.setVisible (value);

The Value Node is:

Prov

The Value Attribute is:

VarLinkToAction -> type String()

I did import these 2:

import com.sap.tc.webdynpro.clientserver.uielib.standard.api.IWDLinkToAction;

import com.sap.tc.webdynpro.progmodel.api.IWDAction;

Can you help?

Thanks

Former Member
0 Kudos

Hi friend

You have Created the variable VarLinkToAction of type String please Create it as IWDLinkToAction type you can do that by Going to java Native Type There you can Find IWDLinkToAction type.

And One More thing The IWDAction type you have to put some Action There which you want to use through the Link to action.

It May be IprivateView.On_action_<Some Action >.

Regards

Jeetendra

Former Member
0 Kudos

Thank you!

The first error is resolved

I now remain only these three errors:

-The method setContextMenuId (String) is undefined for the type IWDLinkToAction -> link.setContextMenuId (linkToAction ");

-IWDAction not be resolved -> link.setOnAction (IWDAction);

-value can not be resolved -> link.setVisible (value);

Can you help me?

Thanks

Banana

Former Member
0 Kudos

Hi friend,


-The method setContextMenuId (String) is undefined for the type IWDLinkToAction -> link.setContextMenuId (linkToAction ");

* link.setContextMenuId("LinkToAction"); // It will work You have left the (") thing before LinkToAction String.
-IWDAction not be resolved -> link.setOnAction (IWDAction); // See the Previous Post
-value can not be resolved -> link.setVisible (value); //  link.setVisible(WDVisibility.VISIBLE); it will work.

Regards

Jeetendra.

Former Member
0 Kudos

Hi,

Use the following code in the action where you need to create Link to Action.

IWDView view = wdContext.currentContextElement().getVa_View();

IWDTransparentContainer root = (IWDTransparentContainer)view.getRootElement();

IWDLinkToAction la = (IWDLinkToAction) view.createElement(IWDLinkToAction.class, "la_Test");

la.setOnAction(this.wdComponentAPI.getAction("<YourAction>"));

la.setEnabled(true);

la.setText("Do Test Action");

la.setVisible(WDVisibility.VISIBLE);

root.addChild(la);

Pre-requisite.

1. Create a context attribute Va_View and set it datatype from java native type

com.sap.tc.webdynpro.progmodel.api.IWDView

2. In wdDoModify() set the context attribute with --> view passed as argument in the wdDoModify method.

Regards,

Tushar Sinha

Former Member
0 Kudos

Thanks Tushar.

Former Member
0 Kudos

Hi,

I am sorry. Would request you to use

la.setOnAction(wdThis.wdGet<Your Action Name>Action());

instead for setting action to the newly created link to action.

Regards,

Tushar Sinha

Former Member
0 Kudos

Hi

then I tried to post as you say

Tushar Sinha

IWDView view = wdContext.currentContextElement (). GetVista ();

IWDTransparentContainer root = (IWDTransparentContainer) view.getRootElement ();

IWDLinkToAction la = (IWDLinkToAction) view.createElement (IWDLinkToAction.class, "la_Test");

la.setOnAction (this.wdComponentAPI.getAction ("<MyAction> "));

la.setEnabled (true);

la.setText ( "Do Test Action");

la.setVisible (WDVisibility.VISIBLE);

root.addChild (la);

I deploy and gives me this error:

The initial exception that caused the request to fail, was:

java.lang.NullPointerException

at it.cvascuole.CVA_SCUOLE_DISEGNI_View.wdDoInit (CVA_SCUOLE_DISEGNI_View.java: 159)

at it.cvascuole.wdp.InternalCVA_SCUOLE_DISEGNI_View.wdDoInit (InternalCVA_SCUOLE_DISEGNI_View.java: 136)

at com.sap.tc.webdynpro.progmodel.generation.DelegatingView.doInit (DelegatingView.java: 61)

at com.sap.tc.webdynpro.progmodel.controller.Controller.initController (Controller.java: 215)

at com.sap.tc.webdynpro.progmodel.view.View.initController (View.java: 445)

... 32 more

the error is on

IWDTransparentContainer root = (IWDTransparentContainer) view.getRootElement ();

I created the node facie com.sap.tc.webdynpro.progmodel.api.IWDView

I also did as you say Dreams4Desires

IWDLinkToAction link = wdContext.nodeClassi (). CreateClassiElement (). GetVarLinkToAction ();

link.setContextMenuId ("LinkToAction");

link.setOnAction (IWDAction);

link.setVisible (WDVisibility.VISIBLE);

/ / Keep setting the desired properties for relsult.

/ / Put the LinkToAction.Text

link.setText (SomeText ");

the error is link.setContextMenuId ("LinkToAction"), says he does not know LinkToAction

and I also tried so link.setContextMenuId ("linkToAction"); same error

I do not know how to solve

can you help me?

Thanks

Banana

Former Member
0 Kudos

Hi Friend,

It seems like the IWD view that you need to pick up from the wdDoModify() is not stored in the context attribute of IWDView type. Can you please check that because it is working in mine. I tried it.

Regards,

Tushar Sinha

Former Member
0 Kudos

In the layout I did a Child Insert -> TransparentContainer and id = idAnno

and wdDoInit have this source:

IWDView view = wdContext.currentContextElement ().getVista ();

IWDTransparentContainer root = (IWDTransparentContainer) view.getElement ("idAnno");

IWDLinkToAction la = (IWDLinkToAction) view.createElement (IWDLinkToAction.class, "la_Test");

la.setOnAction (this.wdComponentAPI.getAction (<MyAction> "));

la.setEnabled (true);

la.setText ( "Do Test Action");

la.setVisible (WDVisibility.VISIBLE);

root.addChild (la);

right way?

gives the same error.

something wrong?

but it is right to put idAnno in IWDTransparentContainer root = (IWDTransparentContainer) view.getElement ("idAnno");?

thanks

Banana

Former Member
0 Kudos

in wdDoModifyView i put something?

Former Member
0 Kudos

Yes,

You need to first get the root element as what i have already suggested you using

IWDTransparentContainer root = (IWDTransparentContainer) view.getRootElement ();

It is different from the transparent container that you have inserted.

You see in the layout, the root transparent container cannot be deleted. Whatever you have inserted is within the root element.

So, follow this and add child to this root element only.

In wdDoMofify() make sure you just have this code:

if(firstTime){

wdcontext.currentContextElement().setVa_View(view);

}

This 'view' is a prameter passed in this wdDoModify() method. Try this.

Regards,

Tushar Sinha

Former Member
0 Kudos

Hi Friend,

On more suggession. In case you want to add the Link to URL to your newly added transparent container.

1. Get the view and then the root element (transparent container)

IWDView view = wdContext.currentContextElement().getVa_View();

IWDTransparentContainer root1 = (IWDTransparentContainer)view.getRootElement();

2. Get your transparent container and add to root element

IWDTransparentContainer root = (IWDTransparentContainer)view.getElement("idAnno");

root1.addChild(root,0);

3. Add the Link to URL in your transparent container

IWDLinkToAction la = (IWDLinkToAction) view.createElement(IWDLinkToAction.class, "la_Test");

la.setOnAction(wdThis.wdGetPrintFileAction());

la.setEnabled(true);

la.setText("Do Test Action");

la.setVisible(WDVisibility.VISIBLE);

root.addChild(la);

Hope your problem is resolved now.

Regards,

Tushar Sinha

Former Member
0 Kudos

Sorry but setVa_View what would it be?

Regardes

Banana

Former Member
0 Kudos

In your case the attribute name is Vista (where i refered the same attribute by name Va_View, type IWDView). In the wdDoModify() method in your view controller, if you can check is as below which has IWDView type parameter with name view. You actually need to set that to the context.

public static void wdDoModifyView(IPrivate<YourViewController> wdThis, IPrivate<YourViewController>.IContextNode wdContext, com.sap.tc.webdynpro.progmodel.api.IWDView view, boolean firstTime){

if(firstTime){

wdContext.currentContextElement ().setVista (view);

}

}

Regards,

Tushar Sinha

Former Member
0 Kudos

wdDoInit this source:

IWDView view = wdContext.currentContextElement().getVista();

IWDTransparentContainer root1 = (IWDTransparentContainer)view.getRootElement();

IWDTransparentContainer root = (IWDTransparentContainer)view.getElement("idAnno");

root1.addChild(root,0);

IWDLinkToAction la = (IWDLinkToAction) view.createElement(IWDLinkToAction.class, "la_Test");

la.setOnAction(wdThis.wdGetPrintFileAction());

la.setEnabled(true);

la.setText("Do Test Action");

la.setVisible(WDVisibility.VISIBLE);

root.addChild(la);

in wdDoModifyView:

if(firstTime){

wdContext.currentContextElement ().setVista (view);

}

Error in:

IWDTransparentContainer root1 = (IWDTransparentContainer)view.getRootElement();

java.lang.NullPointerException

at com.sap.XXX_View.wdDoInit(XXX_View.java:164)

at it.cvascuole.wdp.InternalXXX_View.wdDoInit(InternalXXX_View.java:136)

at com.sap.tc.webdynpro.progmodel.generation.DelegatingView.doInit(DelegatingView.java:61)

at com.sap.tc.webdynpro.progmodel.controller.Controller.initController(Controller.java:215)

at com.sap.tc.webdynpro.progmodel.view.View.initController(View.java:445)

... 32 more

I can not resolve ....

but somewhere there is an example already done?? perhaps a zip of the imported project

Help me!

Former Member
0 Kudos

Oh! got the problem. This is because you are trying to get the value from Vista context element even before the value is getting set. So null pointer is obvious.

wdDoInit() would always be called before the wdDoModify().

But why do you need to create element dynamically when the screen loads. You can better define that UI element in design time under layout and do all the binding manually there.

In case, you need to create element again after the screen has loaded once on some action, then you should use this dynamic creation, because by then the wdDoModify() method will be called at least once.

Regards,

Tushar Sinha

Former Member
0 Kudos

Hi,

Thats what i tried to say should never ever use the hook method wdModifyView and wddoInit to generate data for first time if it fails whole application fails and is not a best practice at all.

Regards

Jeetendra

Former Member
0 Kudos

Finally it works!

Here's the source:

in wdDoModifyView

if(firstTime){

wdContext.currentContextElement().setVista (view);

IWDTransparentContainer rootElement = (IWDTransparentContainer) view.getRootElement();

// Set the layout manager to MatrixLayout

rootElement.createLayout(IWDMatrixLayout.class);

// Get the metadata of the node

IWDLinkToAction la = (IWDLinkToAction) view.createElement(IWDLinkToAction.class, "la_Test");

la.setEnabled(true);

la.setText("Do Test Action");

la.setVisible(WDVisibility.VISIBLE);

rootElement.addChild(la);

}

Thanks for your help

Banana

Former Member
0 Kudos

This is bad advice. The view instance should not be stored in the controller context and not be accessed from any other method than wdDoModifyView() (or methods called from there).

Armin

Former Member
0 Kudos

And why do you implement this programmatically and not using in the View Designer?

Armin

Former Member
0 Kudos

Yes, probably you can set value true to a boolean flag onAction of a button or something and then check this boolean flag to be true to execute the dynamic creation of UI element.

Regards,

Tushar Sinha

Answers (0)