cancel
Showing results for 
Search instead for 
Did you mean: 

Disabling selective cells in a table column?

former_member187658
Participant
0 Kudos

Hi

Can anyone tell how to disable the selective cells in a table column?

I have a table in which data is coming from backend in 4 columns. And there is a 5th column which is editable, having input fields. Now based on the condition that current month should match with the one of the values in date column of the table, soem cells of the editable column need to be disabled.

I tried making a sub node in the data node and defiend an attribute in that of type boolean , and set that to the enabled property of the Input Field UIElement. And the code for this validation, i put in the wdModifyView method of the View.

The code sample i am writing below:

String year = (new SimpleDateFormat("yy").format(new Date()));

String month = (new SimpleDateFormat("MMM").format(new Date()));

String currentDate=month.toUpperCase()"-"year;

int size = wdContext.nodeContractVolumeResultViewNode().nodeOutput().nodeLi_Con_Nom().size();

String size1=""+size;

for(int i=0;i<size-1;i++)

{

if(wdContext.nodeContractVolumeResultViewNode().nodeOutput().nodeLi_Con_Nom().getLi_Con_NomElementAt(i).getMonths_Display()==currentDate)

{break;}

wdContext.nodeContractVolumeResultViewNode().nodeOutput().nodeLi_Con_Nom().nodeEnableNode().getEnableNodeElementAt(i).setEnableAttribute(false);

}

In the above code, nodeLi_Con_Nom is the model node which is a data node.

EnableNode in the Value node carrying EnableAttribute of type boolean which is set to the enabled property of the input field of the column table.

But when i run this code it throws an exception of

java.lang.IndexOutOfBoundsException: Index: 0, Size: 0

at java.util.ArrayList.RangeCheck(ArrayList.java:507)

at java.util.ArrayList.get(ArrayList.java:324)

at com.sap.tc.webdynpro.progmodel.context.Node$ElementList.getElement(Node.java:2087)

at com.sap.tc.webdynpro.progmodel.context.Node$MappedElementList.getElement(Node.java:2452)

at com.sap.tc.webdynpro.progmodel.context.Node.getElementAtInternal(Node.java:671)

at com.sap.tc.webdynpro.progmodel.context.Node.getElementAt(Node.java:678)

at com.sap.bp.ngl.contvol.wdp.IPrivateContractVolumeResultView$IEnableNodeNode.getEnableNodeElementAt(IPrivateContractVolumeResultView.java:840)

at com.sap.bp.ngl.contvol.ContractVolumeResultView.wdDoModifyView(ContractVolumeResultView.java:174)

Can anybody please help in this regard, as to how to go about it?

Thanks & regards,

Anupreet

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Anupreet,

Make sure you are setting the cardinality to 1..n. Then by default you will have an element created at index 0. And you can access it using the method node<node name>.get<node name>ElementAt(0);

As far as I see, I don't find anything wrong in your code. If you are still getting errors, paste all your code snippets that deals with the node.

Best Regards,

Nibu.

former_member187658
Participant
0 Kudos

Hi Nibu

I have set the cardinality to 1..n.

I am pasting the code snippet that deals with this node. It is the same as u had sent. Except that when I created the node element for Enalbenode instead of setting it as null, it again shows all the cells as disabled. And wheni set that as null, as you had mentioned, then the above stated error occurs.

here is the code, please look into it:

String year = (new SimpleDateFormat("yy").format(new Date()));

String month = (new SimpleDateFormat("MMM").format(new Date()));

String currentDate=month.toUpperCase()"-"year;

int size = wdContext.nodeContractVolumeResultViewNode().nodeOutput().nodeLi_Con_Nom().size();

String size1=""+size;

IPrivateContractVolumeResultView.ILi_Con_NomElement elmt = null;

IPrivateContractVolumeResultView.IEnableNodeElement elmt1 = wdContext.createEnableNodeElement();

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

{

elmt = wdContext.nodeLi_Con_Nom().getLi_Con_NomElementAt(i);

elmt1 = elmt.nodeEnableNode().getEnableNodeElementAt(0);

if(elmt.getMonths_Display()==currentDate)

{

elmt1.setEnableAttribute(true);

break;

}

elmt1.setEnableAttribute(false);

}

can you please help in this. NA d this code is being written in the wdModifyView method of the View. It is not being used anywhere else.

Thanks & regards,

Anupreet

Former Member
0 Kudos

Hi Anupreet,

I think you are getting all the cells disabled because of this line <b>if(elmt.getMonths_Display()==currentDate)</b>. Use equals() or equalsIgnoreCase() to compare strings.

And about getting the exception when not initializing the element manually, I think it might be because of an older WAS version (not very sure). Because I tried out the same code in my system and it works fine.

I couldn't find anything else wrong with your code.

Best Regards,

Nibu.

former_member187658
Participant
0 Kudos

Hi Nibu

thanks a lot. Finally i am anble to solve the problem. The problem was there as you had mentioned.

Thanks a lot.

Thanks & regards,

Anupreet

Former Member
0 Kudos

Hi Anupreet,

It would be very encouraging if you could award points & close the thread.

Best Regards,

Nibu.

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Anupreet,

Set the cardinality of your 'EnableNode' as 1..n and 'singleton' as false.

Then modify your code as follows :

Iprivate<your view>.ILi_Con_NomElement elmt = null;

Iprivate<your view>.IEnableNodeElement elmt1 = null;

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

{

elmt = wdContext.nodeLi_Con_Nom().getLi_Con_NomElementAt(i);

elmt1 = elmt.nodeEnableNode().getEnableNodeElementAt(0);

if(elmt.getMonths_Display()==currentDate)

{

elmt1.setEnableAttribute(true);

break;

}

elmt1.setEnableAttribute(false);

}

Hope this helps,

Best Regards,

Nibu.

former_member187658
Participant
0 Kudos

Hi Nibu

I tried the solution you gave but the following error is coming :

com.sap.tc.webdynpro.progmodel.context.ContextException: Node(ContractVolumeResultView.ContractVolumeResultViewNode.Output.Li_Con_Nom.0.EnableNode): must not bind an empty collection to a Node of cardinality 1..1 or 1..n

can you please help in this?

Thanks & regards,

Anupreet

Former Member
0 Kudos

hi

is your model node initialised ( has the bapi run)? if yes create the element for the node you created inside the model node meaning elmnt1 (i guess) by saying wdContext.create<name>element.

regards

vln

Message was edited by: Lakshminarayanan Vijayaraghavan

Former Member
0 Kudos

Hi Anupreet,

You are missing one step.

You are not creating the element in the subnode.

Try this

if(wdContext.nodeContractVolumeResultViewNode().nodeOutput().nodeLi_Con_Nom().nodeEnableNode().currentEnableNodeElement() == null)

wdContext.nodeContractVolumeResultViewNode().nodeOutput().nodeLi_Con_Nom().nodeEnableNode().addElement(wdContext.nodeContractVolumeResultViewNode().nodeOutput().nodeLi_Con_Nom().nodeEnableNode().createEnableNode());

wdContext.nodeContractVolumeResultViewNode().nodeOutput().nodeLi_Con_Nom().nodeEnableNode().getEnableNodeElementAt(i).setEnableAttribute(false);

Regards,

Shubham

Former Member
0 Kudos

Hi Anupreet,

I guess you are getting data correctly in your output node.

Now, you have created one mode node inside Li_Con_Nom node. But have you initialized this node?

If not then first create element of this node and assign this element to node inside that for loop. After initializing, you check for your condition and then do accordingly.

I guess its problem due to initialization only.

Regards,

Bhavik

former_member187658
Participant
0 Kudos

Hi Bhavik

Can you please elaborate?

thanks & regards,

Anupreet

Former Member
0 Kudos

Hi anupreet,

Set that node cardinality to "1..N" It will initialize your node.

Otherwise, write following code inside your for loop before if statement.

ele = wdcontext.create<node name>();

ele.set<attribute name>(true);

wdcontext.node<nodename>().bind(ele);

Regards,

Bhavik

Former Member
0 Kudos

Hi Anupreet,

You can do this through context programming.

1. Create a attribute "Enable" of type boolean

2. Bind the table column "Enable" attribute to this attrib

3. Change the value of the attrib dyncamically.

Regards, Anilkumar

former_member187658
Participant
0 Kudos

Hi

That is what i tried but it is not working.

Thanks & regards,

Anupreet