on 06-04-2007 7:09 PM
All,
I have a context node called DataSource and it has an field called First_Name..
Im checking whether its blank or not using below code..but getting an error
" com.sap.tc.webdynpro.progmodel.context.ContextException: NodeElement(ParentView.0): unknown attribute First_Name
Here is the code...
this.CheckMandatory(IPrivateParentView.IDataSourceElement.FIRST__NAME);
public void CheckMandatory( java.lang.String fieldName )
{
//@@begin CheckMandatory()
IWDMessageManager messageMgr =
wdComponentAPI.getMessageManager();
Object attributeValue =
wdContext.currentContextElement().getAttributeValue(fieldName);
IWDAttributeInfo attributeInfo =
wdContext.getNodeInfo().getAttribute(fieldName);
if (attributeValue instanceof String) {
if (((String) attributeValue).length() == 0) {
String fieldLabel =
wdContext.getNodeInfo().getAttribute(fieldName)
.getSimpleType().getFieldLabel();
messageMgr.reportContextAttributeMessage(
wdContext.currentContextElement(),
attributeInfo,
IMessageParent.MISSING_INPUT,
new Object[] { fieldLabel },
true);
}
}
//@@end
}
Can anyone tell me what im missing..
BM
Hi Bharati,
First_Name attribute is created under node DataSource, but while taking attributeInfo you are taking nodeInfo of root node not DataSource.
Replace this line with wdContext.getNodeInfo().getAttribute(fieldName);
wdContext.nodeDataSource().getNodeInfo().getAttribute(fieldName);
Hope It helps.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Now im getting below error:
" java.lang.IllegalArgumentException: No such attribute First_Name
Corrected code as follows:
public void CheckMandatory( java.lang.String fieldName )
{
//@@begin CheckMandatory()
IWDMessageManager messageMgr =
wdComponentAPI.getMessageManager();
Object attributeValue =
wdContext.currentDataSourceElement().getAttributeValue(fieldName);
IWDAttributeInfo attributeInfo =
wdContext.nodeDataSource().getNodeInfo().getAttribute(fieldName);
if (attributeValue instanceof String) {
if (((String) attributeValue).length() == 0) {
String fieldLabel = "Test" ;
messageMgr.reportContextAttributeMessage(
wdContext.currentContextElement(),
attributeInfo,
IMessageParent.MISSING_INPUT,
new Object[] { fieldLabel },
true);
}
}
//@@end
}
BM..
Since original issue is resolved, closing this thread & opening another thread for Integer issue..
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Can anyone tell me how to check whether Integer fields are populated or not?
BM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Bharathi,
I guess you attribute type is integer. If your attribute type is integer then directly check whether value is 0 or not.
If it is type of String then use following code:
try {
Integer.parseInt(<context atrribute value>);
return true;
} catch (NumberFormatException nfe){
return false;
}
Regards,
Bhavik
Bhavik,
Thanks for your reply..I want to check whether user entered any value or not..THe integer field always populated with 0.
I want to check whether its initial or not. If its 0 then i need to throw an error message.How can i do that?
In SAP the fields types are NUMC.So will it convert it as Integer ot String?
BM
Solved..
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
88 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.