cancel
Showing results for 
Search instead for 
Did you mean: 

on Button click change the button display text from LOCK to UNLOCK

Former Member
0 Kudos

Hi Freinds,

I am rendering a TreeByNestingTableColumn with two columns like: Name , Status as below shown. In The status column I inserted a Table Cell editor Button type and the button element property text mapped to the context attribute called statusButton and set the button name in the code to display as LOCK. When the tree renders all the vales are displaying in status column as LOCK. Now whrn the user click on LOCK i should fire the event and change the button text from LOCK to UNLOCK. The same way when they click on UNLOCK and i have change to LOCK. please help how to do this.



   Name                          Status
|> Employee1------------------LOCK (when i click on lock  button here, his and under neath of him button status should                  
        |>Employee2-----------LOCK    change from LOCK status to UNLOCK)                                                      
               |>Employee3----LOCK

Thanks in advance.

Thanks

Srini

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Use a ToggleButton as cell editor an bind the "checked" property to a boolean attribute "locked" under the data source node. Add a calculated attribute "buttonText" under the data source node and implement the get-method like


String get<DataSourceNode>ButtonText(... element)
{
  return element.getLocked() ? "UNLOCK" : "LOCK";
}

Assign an empty action to the "onToggle" event of the ToggleButton.

Former Member
0 Kudos

Hi Armin,

Thanks for replying for my question.

***Use a ToggleButton as cell editor an bind the "checked" property to a boolean attribute "locked" under the data source node.

Yes I did exactly how you explained.

        • Add a calculated attribute "buttonText" under the data source node.

I created a attribute as "buttonText" under the node. 

      • Iimplement the get-method like:


I created a method and implemented as below, 
public java.lang.String changeButtonText( com.sap.xss.hr.ecm.selection.wdp.IPrivateVEcmSelectionView.ITestElement buttonElement )
  {
    //@@begin changeButtonText()
    
    return buttonElement.getLocked() ? "Un Lock" : "LOCK";
    //@@end
  }

Calling this method under Toggle Button action cause i wnat to happen this when user click on the toggle button.


  public void onActionTestToggle(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent, com.sap.xss.hr.ecm.selection.wdp.IPrivateVEcmSelectionView.ITestElement element11 )
  {
    //@@begin onActionTestToggle(ServerEvent)
    
    wdThis.changeButtonText(element11);
    
    //@@end
  }


Still i cannot seee the desired output. When i click on the Button , the Button text is not changing from LOCK to UNLOCK.

I appreiciate your time and please advice where i am doing wrong. Thank you.

Srini

Former Member
0 Kudos

Did you bind the ToggleButton's "text" property to the "buttonText" attribute? You should not create a changeButtonText() method, but define the context attribute as calculated=true, read-only=true, which will create a get-method. Ther you should write the code and you should not call anything from the action handler method.

Armin

Former Member
0 Kudos

Armin,

Yes I removed the method and created the calicualted value as you suggested and I able to get the out put what i have asked.

My complete scenario is some thing like this, i able to complete upto certain level but not able to make it work for complete scenario, I appreicate your comments or advice for getting me the below output

I have a TreeByNestingTableColum UI rendering with three columns as NAME(node |>), STATUS(Toggle Button) and PLANNING (Text view) (developed based on sample tutorial Integration of a Tree Structure in a Web Dynpro Table.pdf)

I am trying to get this output:

From the sap backed i am getting flag value, based on that i have to render Tree UI columns NAME, STATUS(Toggle Button) and PLANNING (Text view). if the flag is null i have to show as LOCK and In Planning else Unlock and Submitted (please see the below picture for clear idea)*


if (statusflag = ""){

i have to show values in two columns like Lock ...Planning
} else 

{

show values in two columns like Un Un Lock ...Submitted
  
}

One more thing is , If i lock a record at secound node level , then all the records should locked underneath of that node (it could be 2 nodes or 10 nodes) and then the status column values should change from lock to Unlock and Planning column values should change from In Planning to Submitted. where as when i Click on Unlock , only that perticular record (not node level) should changed from unlocked to Lock and planning is from Submitted to In Planning.

This is the functionality actually I am looking for.

Here the tree sample:


Name                        Status              Planning
|>M1                         Lock                 In Planning
   |>M2                      Lock                 In Planning
     *M2a                    Lock                 In Planning
   |>M3                    Un Lock                Submittd

Thank you.

Srini

Former Member
0 Kudos

Say you have the following recursive context structure


Entries (node)
+ Children (recursive node -> Entries)
+ locked (boolean)
+ buttonText (string, calculated)
+ planningText (string, calculated)

To implement the actions,

- create an action "ChangeLockState" and assign it to the ToggleButton's "onToggle" event

- add an action parameter "treeNode" of type IEntriesElement

- create an event parameter mapping for the "onToggle" event: "nodeElement" -> "treeNode"

Action handler:


void onChangeLockStateAction(..., IEntriesElement treeNode)
{
 /* Note that the "locked" state of the tree node is already the new state */
 if ( treeNode.getLocked() )
 {
   /* lock complete subtree */
   lockSubTree(treeNode);
 }
 else
 {
   /* don't unlock subtree */
 }  
}

void lockSubTree(IEntriesElement treeNode)
{
  for (int i = 0; i < treeNode.nodeChildren().size(); ++i)
  {
    IEntriesElement child = treeNode.nodeChildren().getChildElementAt(i);
    child.setLocked(true);
    lockSubTree(child);
  }
}

Armin

Former Member
0 Kudos

Hi Armin,

Thanks for the steps.

I am still missing some thing.

I have done the following things as you suggested:

- create an action "ChangeLockState" and assign it to the ToggleButton's "onToggle" event

- add an action parameter "treeNode" of type IEntriesElement

I am not sure this part, I think I am doing some thing wrong here, . I looked at SDN forums on what is this parameter mapping and found some information but still not able to make it work.

Please can you give me the steps to perform the parameter mapping?

-*****************create an event parameter mapping for the "onToggle" event: "nodeElement" -> "treeNode"

To do event perameter mapping , I followed your previously written thread, but still i am bit confused with this concept,

wdDoModifyView()

{

if (firstTime)

{

IWDButton button = (IWDButton) view.getElement("ToggleButton_lock");

button.mappingOfOnAction().addParameter("buttonText", button.getText());

}

}

in the above written addParameter method, i ahve passed one parameter as from the action event handler event parameter and the other one is the standard method of Button class i.e button.getText().

Now, when i deploy the code , i am getting a null pointer exception at this line my code: if(treeNode.getLocked())

here, locked is a boolean variable and setting the vlaues for it in getEcmStatusButtonText() , method but still getting a null pointer , not sure what is going wrong here.

Thank you.

Former Member
0 Kudos

wdDoModifyView()
{
  if (firstTime)
  {
    IWDToggleButton button = (IWDToggleButton) view.getElement("ToggleButton_lock");
    button.mappingOfOnToggle().addSourceMapping("nodeElement", "treeNode" /* or however the action parameter is named */);
  }
}

or better, do it using the IDE, if your version supports that.

Armin

Former Member
0 Kudos

Thank you for the reply.

I was using the button api earlier and I changed this to

IWDToggleButton button = (IWDToggleButton) view.getElement("ToggleButton_lock");

button.mappingOfOnToggle().addSourceMapping("nodeElement", "treeNode" )

///* the treeNode is the event parameter defined for the action onActionTestToggle

Still I am getting the error at bold underline text , the error is as below:

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

java.lang.NullPointerException

at ...................onActionTestToggle(VEcmSelectionView.java:433)

public void onActionTestToggle(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent, ........IEntriesElement treeNode )

{

//@@begin onActionTestToggle(ServerEvent)

if(treeNode.getLocked())

{

lockSubTree(treeNode);

}

else

{

}

//@@end

}

Please advice.

Thanks

Edited by: Srinibapati on Aug 31, 2009 6:11 PM

Edited by: Srinibapati on Aug 31, 2009 6:17 PM

Former Member
0 Kudos

Use the debugger and check the wdEvent parameter. What does it contain?

Armin

Former Member
0 Kudos

Hi,

I'm not sure if is the version or not, but you can try:


wdDoModifyView()
{
  if (firstTime)
  {
    IWDToggleButton button = (IWDToggleButton) view.getElement("ToggleButton_lock");
    button.mappingOfOnToggle().addSourceMapping("nodeElement", "EntriesElement");
  }
}

You should also set the new parameter name to "EntriesElement".

Hope it helps,

Regards,

Daniel

Former Member
0 Kudos

Why should renaming the action parameter help?

Armin

Former Member
0 Kudos

Hi,

void lockSubTree(IEntriesElement treeNode)
{
  for (int i = 0; i < treeNode.nodeChildren().size(); ++i)
  {
    IEntriesElement child = treeNode.nodeChildren().getChildElementAt(i);
    child.setLocked(true);
    lockSubTree(child);
  }
}

Not sure, but try by doing the post increment of i in for loop:

for (int i = 0; i < treeNode.nodeChildren().size(); i++)

Regards,

Charan

Former Member
0 Kudos

Please don't pollute this thread with such nonsense.

Armin

Former Member
0 Kudos

Hi Armin,

Yes, i am passing the wrong event parameter, Now i able to resolve that Null pointer excption after passing the correct action event parameter.

Now I am working on executing the RFC in the backed to update the data.

I am closin this thread and If i ahve any issues , i will create a new thread.

Thanks for all.

Srini.

Former Member
0 Kudos

Hi,

My try was not to pollute this thread and i was just tried to solve this issue.

As per the earlier posts of Srini he mentioned that he was passing the correct parameter.

There could be n no of reasons for null pointer error.

Some times we miss a very simple thing..in doing the coding...

So i though he might be trying to get the element which is not there in that position....So i hav posted that solution...

For your kind information....I NEVER TRIED TO POLLUTE ANY THREAD...I WILL JUST TRY TO HELP OTHERS TO RESOLVE THE ISSUE...

Regards,

Charan

Former Member
0 Kudos

Sorry.

Armin

Answers (0)