cancel
Showing results for 
Search instead for 
Did you mean: 

getting the text of a Label from an inputField

Former Member
0 Kudos

Hello everyone,

In my application, I have an inputField and a Label.

The labelFor property of the Label directs to the inputField.

How can I get the text of the label from the inputField ?

Any suggestions ?

Thanks.

Ruthie.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Ruthie,

What do you mean by "get the text of the label from the inputField ".

You can write the following code in wdDoModifyView method

IWDLabel lbl=(IWDLabel)view.getElement("");

lbl.getLabelFor();

Regards, Anilkumar

Answers (5)

Answers (5)

Former Member
0 Kudos

Thanks Nibu.

It didn't work.

I guess its not possible.

Let me give you some points.

Former Member
0 Kudos

Please tell exactly what you tried and what did not work.

If the DDIC type has a label text, you can access this as described. If you set the label text in the Label element and want to access it from a controller method, then use data binding, i.e. bind the Label.text property to a context attribute and set it via the attribute value. In the controller method, you can read the attribute value.

Armin

Former Member
0 Kudos

Hi Armin,

If I use data binding it is going to work.

But I thought that I can make use of the property

"labelFor" which appears in the layout for each label

so I can get the text from the inputField which appears

in the "labelFor".I just don't get the meaning of the

"labelFor" property.

Thanks.

Ruthie.

Former Member
0 Kudos

The "labelFor" property connects the Label with the labelled element and is usually assigned in the NWDS view designer. The effect of setting this property is more "visible"/hearable in accessibility mode. Another effect is, if you click on the Label, the labelled element gets the focus.

In most cases, there is no need to access this property at runtime. If you need to access the property value from event handlers, use data binding.

Armin

Former Member
0 Kudos

Hi Ruthie,

Try this code:

IWDAttributeInfo info= wdContext.getNodeInfo().getAttribute(IPrivate<View>.IContextElement.<attrib_name>);

wdComponentAPI.getMessageManager().reportSuccess("Field Label::"+info.getSimpleType().getFieldLabel());

Hope this helps,

Best Regards,

Nibu.

Message was edited by: Nibu Wilson

Former Member
0 Kudos

Hi Anilkumar,rahul,Valery.

I didn't explain it clear enough.

In my application I use the method reportContextAttributeMessage as follows:

private void checkMandatory(String fieldName, String fieldText){

IWDMessageManager messageMgr = wdControllerAPI.getComponent().getMessageManager();

IWDAttributeInfo attributeInfo = wdContext.getNodeInfo().getAttribute(fieldName);

String value = wdContext.currentContextElement().getAttributeAsText(fieldName);

if (value.length()==0){

messageMgr.reportContextAttributeMessage(wdContext.currentContextElement(),

attributeInfo, IMessageOpenUserApp.MISSING_INPUT,

new Object[] { fieldText },

true);

}

}

So,this method executes validity check to an input field

("fieldName").

In the layout I have an inputField and a Label.

The property labelFor of the Label is set to the inputField.

The parameter "fieldText" should be the text of the label.

Is there a way - that when knowing only the context attribute of the inputField - I can get the text of the Label ? what is the meaning of the labelFor property ?

Thanks.

Ruthie.

Former Member
0 Kudos

Ruthie,

You must bind an IWDInputField to some context attribute. Then corresponding label (connected via labelFor property) will use metadata of attribute (unless you eclipse this value by setting label text explicitly for IWDLabel). Namely, it will show "Field Label" property of corresponding attribute's simple type.

So you have to create a simple type in local dictionary and assign "Field Label" to necessary value.

For model nodes (like Adaptive RFC) data dictionary with corresponding types and their metadata are retrieved from backend (R/3), so you get label texts automatically in this case.

P.S. Just in case I understand you wrong: if you have to display same text for InputFiled and Label, then just bind InputField.value and Label.text to same context attribute.

Valery Silaev

EPAM Systems

http://www.NetWeaverTeam.com

Former Member
0 Kudos

Hi Ruthie,

go to Local dictionary create a simple type. inside the simple type go to 'representation' tab, then set the 'field label' to any value you want. Now create an attribute of this simple type and bind that to an inPut fields value property. then if you set the labelfor property of a label to this input field, the label will display the' field label' of simple type .

regards,

rahul.