cancel
Showing results for 
Search instead for 
Did you mean: 

Enabling/ Disabling Button based on input property of the backend

Former Member
0 Kudos

Hi ,

I need to enable/ disable "New" button based on the property "CREATE_ENABLED" of the input which is model bound to my inport. The value of the property keeps changing dynamically so I need to read it in my view and set the button accordingly. Could you please suggests ways or API method which can be used to read the backend

property value at run time.

Thanks & Regards,

Ashish

Accepted Solutions (1)

Accepted Solutions (1)

sureshmandalapu6
Active Contributor
0 Kudos

Hi Ashish,

You need to bind the button Enable property to a context node either model attribute or value attribute.

if it is value attribute make its type as boolean and then according to the context value you can make the button enable or disable.

thanks

Suresh

Answers (3)

Answers (3)

Former Member
0 Kudos

Thanks to everyone who has contributed . The problem got solved. Below is the code snippet used to solve the problem.

boolean isCreateEnabled = true;
	  IWDNode calendarEntry = wdThis.wdGetCalendarController().wdGetContext().nodeCalendarEntry();
		if (calendarEntry.size() > 0 && calendarEntry!= null && calendarEntry.getElementAt(0)!= null){
			IBONodeElement iboNodeElement = ((IBONodeElement)calendarEntry.getElementAt(0).model());
			isCreateEnabled =  iboNodeElement.getBONode().isCreateAllowed();
			}
		createButton.setEnabled(isCreateEnabled);

where CalendarController is my component controller and calendarEntry node is one of the inports defined on it.

Thanks & Regards,

Ashish

Former Member
0 Kudos

Hi,

If you have taken data type of "CREATE_ENABLED" field as boolean in Webservice itself, then you can directly bind the 'Enabled' property of button to this model attribute. Button behaviour will change accordingly.

Regards

LN

Former Member
0 Kudos

Hi,

Create a calculated context attribute of type boolean.

In the getter check the value of "CREATE_ENABLED"

public boolean getButtonEnabledStatus()

{

return CREATE_ENABLED; // you have to make sure that the create enabled is acced properly

}

bind this context attribute to enabled property of the button.

Regards

Ayyapparaj

Former Member
0 Kudos

Hi,

Thanks for all the suggestions. I have taken a calculated attribute (createEnabled)

and have binded it to the button enabled property.

The doubt which I have is whether I am correctly referring to the backend property.

Following is the code snippet written in the getter method of the calculated attribute :

public boolean getCreateEnabled(IPrivateMainView.IContextElement element)
  {
    //@@begin getCreateEnabled
	  IWDNodeElement myElement = wdContext.nodeEntry().currentEntryElement();
	  IBONodeElement iboelement = (IBONodeElement)entryElement.model();
	  IBONode calendarEntryBONode = iboelement.getBONode();
	  if(!entryBONode.isCreateAllowed()){
		  return true;
	  }
    return false;
    //@@end
  }

In the backend, CREATE_ENABLED is one of the properties of the node element.

Former Member
0 Kudos

Hi,

If this attribute is part of the same node which you are refering in the code you can change the code from


public boolean getCreateEnabled(IPrivateMainView.IContextElement element)
  {
    //@@begin getCreateEnabled
	  IWDNodeElement myElement = wdContext.nodeEntry().currentEntryElement();
	  IBONodeElement iboelement = (IBONodeElement)entryElement.model();
	  IBONode calendarEntryBONode = iboelement.getBONode();
	  if(!entryBONode.isCreateAllowed()){
		  return true;
	  }
    return false;
    //@@end
  }

To


public boolean getCreateEnabled(IPrivateMainView.IContextElement element)
  {
    //@@begin getCreateEnabled
                  //Element will point to the current element
	  IBONodeElement iboelement = (IBONodeElement)element.model(); //Make sure this typecast work as I dont have the IDE right now with me.
	  IBONode calendarEntryBONode = iboelement.getBONode();
	  if(!entryBONode.isCreateAllowed()){
		  return true;
	  }
    return false;
    //@@end
  }


Regards

Ayyapparaj

Former Member
0 Kudos

Hi,

The above mentioned code throws an exception as element is an IContext element and not a model node element.

Thanks & Regards,

Ashish

Former Member
0 Kudos

Hi,

Create this calculated attribute under node "Entry".

Regards

Ayyapparaj

Former Member
0 Kudos

Hi ,

Thanks for your suggestion . I don't get the exception now.

I am writing the following piece of code for enabling /disabling the button

public boolean getCalendarEntryCalButtonEnabled(IPrivateMainView.ICalendarEntryElement element)
  {
    //@@begin getCalendarEntryCalButtonEnabled
	  if (element == null){
		  return true;
	  }
	  IBONodeElement iboElement = (IBONodeElement)element.model();
	  IBONode iboNode = iboElement.getBONode();
	  Boolean val = (Boolean) iboNode.getDescriptor().getPropertyValue("CREATE_ENABLED");
	  wdContext.wdGetAPI().getController().getComponent().getMessageManager().reportSuccess(val.toString());
	  return val;
	  
   // return false;
    //@@end
  }

I have bound the button enabled property to this calculated attribute. The issue is that i am getting false

even though the value of the property at the backend is true.

Am I using the correct API methods for the property check.

The property is defined at the BO node level and the name of the property is "CREATE_ENABLED" in the backend.

Former Member
0 Kudos

Hi,

Following two lines should do

IBONodeElement iboElement = (IBONodeElement)element.model();

return iboElement.getBONode().isCreateAllowed();

public boolean getCalendarEntryCalButtonEnabled(IPrivateMainView.ICalendarEntryElement element)

{

//@@begin getCalendarEntryCalButtonEnabled

IBONodeElement iboElement = (IBONodeElement)element.model();

return iboElement.getBONode().isCreateAllowed();

// return false;

//@@end

}

Regards

Ayyapparaj

Former Member
0 Kudos

Hi,

First of all I cannot declare my calculated attribute inside Calendar Entry node because it's a model bound node.

So I have declared it at context level and checking if the value of the property by the following

public boolean getCreateEnabled(IPrivateMainView.IContextElement element)
  {
    //@@begin getCreateEnabled
	  IWDNodeElement myElement = wdContext.nodeEntry().currentEntryElement();
	  IBONodeElement iboelement = (IBONodeElement)entryElement.model();
	  IBONode calendarEntryBONode = iboelement.getBONode();
	  if(!entryBONode.isCreateAllowed()){
		  return true;
	  }
    return false;
    //@@end
  }

Now the issue is that can we get a BO node if there's no BO node element because I need to check the

property when there's no lead selection.

Former Member
0 Kudos

Hi,

From the model you can get the BONode even when their are no elements

model.getBONode(IESRName arg1, IKEyList keys);

Regards

Ayyapparaj

Former Member
0 Kudos

Hi Ashish,

You Can Achieve the Functionality by using Enable property of the button.

For the Button Properties you have the Property Enabled usually it will be True or False. Now Create your own Attribute of type Boolean.

Example :- Bkey type Boolean.

Now give the Bkey for enabled property of The Button.

and create an Event for the button. Now in Implemenation of the Event Created write a sample Code like:

Event Created : onActionButton

according to your Condition Modify this.

public void onActionButton(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
  {
    //@@begin onActionButton(ServerEvent)
    String con = wdContext.currentContextElement.getyourElement(); /* get your attribute
    if( con == "true"  )                      /* give your Condition
     {
       wdContext.currentContextElement.setBkey(true);
     }
     elseif( con == "false"  )              /* give your Condition
     {
       wdContext.currentContextElement.setBkey(false);
     }
    //@@end
  }

I Hope This Information Might be Helpful for You.

Reagards,

Sharma.