cancel
Showing results for 
Search instead for 
Did you mean: 

setReadOnly(boolean)

Former Member
0 Kudos

I've got some elements in my view layout that have their readOnly property linked to a context element.

Now, in the wdDoModifyView method, I want to set some elements readOnly property to true.

((IWDAbstractInputField) uiEl).setReadOnly(true)

However, this gives problems for those elements whose readOnly property is linked with a context element.

java.lang.NullPointerException
at com.sap.tc.webdynpro.clientserver.data.DataContainer.removePendingUserInput(DataContainer.java:1231)
at com.sap.tc.webdynpro.clientserver.data.DataContainer.setBoolean(DataContainer.java:891)
at com.sap.tc.webdynpro.clientserver.uielib.standard.impl.AbstractInputField.setReadOnly(AbstractInputField.java:724)
at com.carrefour.be.evere.msstime.uiinput.UIInputInterface.disableUIElement(UIInputInterface.java:146)
at com.carrefour.be.evere.msstime.uiinput.UIInputInterface.disableUIElement(UIInputInterface.java:139)
at com.carrefour.be.evere.msstime.uiinput.UIInputInterface.disableUIElement(UIInputInterface.java:130)

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Why do you do this inside wdDoModifyView() at all? Just set the value of the context attribute to which the "readOnly" property is bound in the event handler.

Armin

Former Member
0 Kudos

Armin,

because it has to be a generic method, that can be used by different DCs. Depending on an application parameter, this method will or will not be called in wdDoModifyView.

Former Member
0 Kudos

That's no reason to do it inside this method which should only be used to change the view structure.

Armin

Former Member
0 Kudos

Should it be called in wdDoInit() then?

Former Member
0 Kudos

Not necessarily in wdDoInit(), but maybe in some event handler or inbound plug? Difficult to say without knowing the scenario.

Armin

Former Member
0 Kudos

Ok, but that still leaves the initial question open.

Former Member
0 Kudos

The answer is: Set the value of the context attribute inside the correct method which is not wdDoModifyView().

Armin

Former Member
0 Kudos

Have you seen the code I posted? I want to loop over all view elements, without even wondering whether their properties are linked to context attributes.

Former Member
0 Kudos

Ok, I think I understand what you are trying to do.

The error is caused by an attempt to store a boolean value in a non-existing context attribute. This may happen for example, if the attribute is part of a non-singleton node without parent element.

I'm not sure if this is a bug in your release but in any case a better exception than a NPE should be thrown.

Armin

Former Member
0 Kudos

> I'm not sure if this is a bug in your release but in

> any case a better exception than a NPE should be

> thrown.

>

How would you solve the problem?

Former Member
0 Kudos

These views, that are switched to read-only by the generic code, belong to certain Web Dynpro components.

Wouldn't it be possible to define the needed context bindings in these views and just offer a method on their component interface to set the read-only state? Then you would not have to traverse views generically, you would just have to call one method.

Or are these views from completely "foreign" Web Dynpro components?

Armin

Answers (3)

Answers (3)

Former Member
0 Kudos

Lakshmi,

public void disableUIElement(com.sap.tc.webdynpro.progmodel.api.IWDUIElement uiEl ) {

//@@begin disableUIElement()
if (uiEl instanceof IWDUIElementContainer) {

    IWDUIElement[] elements = ((IWDUIElementContainer) uiEl).getChildren();
    List l = Arrays.asList(elements);
    Iterator i = l.iterator();
    while (i.hasNext()) {
        disableUIElement((IWDUIElement) i.next());
    }
}
else if (uiEl instanceof IWDTable) {

    IWDTableColumn[] cols = ((IWDTable) uiEl).getColumns();
    List l = Arrays.asList(cols);
    Iterator i = l.iterator();
    while (i.hasNext()) {
        IWDTableColumn tc = (IWDTableColumn) i.next();
        disableUIElement((IWDUIElement) tc.getTableCellEditor());
    }
}
else if (uiEl instanceof IWDAbstractDropDown) {

    ((IWDAbstractDropDown) uiEl).setEnabled(false);
}
else if (uiEl instanceof IWDAbstractInputField) {

    ((IWDAbstractInputField) uiEl).setReadOnly(true);
}
else if (uiEl instanceof IWDAbstractButton) {

    ((IWDAbstractButton) uiEl).setEnabled(false);
}
//@@end
}

public static void wdDoModifyView(...)  {
    wdThis.wdGetUIInputInterface().disableUIElement((IWDUIElement view.getRootElement());
}

Former Member
0 Kudos

hi,

Check the id of the inputField which you are passing while creating the instance of IWDAbstractInputField. Else use the following:

IWDAbstractInputField inp = (IWDAbstractInputField) viewObj.getElement("InputField");

inp.setReadOnly(true);

thanks & regards,

Manoj

Former Member
0 Kudos

Manoj, same error.

Former Member
0 Kudos

Hi

Can u send me complete code..

Try using IWDInputFiled inplace of IWDAbstractInputFiled

Regards

LakshmiNarayana