on 07-14-2008 12:12 PM
Hi
I want to validate my input fields which i m using in mu webdynpro java application
here i m using sample application to display flightlistdetails..
here context i m having like this
context(contextnode)
bapi_flighlist_input(node)
destinationfrom(childnode)
city(attribute)
destinationto(childnode)
city(attribute)
bapi_flightlist_output(node)
flightlist(childnode)
:
:
(some attributes)
here those city is input field
i m having button called submit
when i click on buttun, i should get flightlist details in a table
till here i got the output
but i wanna maintain city is madatory field
if i dont give any input...out put should not generate
for this i wrote the below code
i create a message at messagepool also
method:Checkmanditory
public void CheckMandatory( java.lang.String FieldName )
{
//@@begin CheckMandatory()
IWDMessageManager messageMgr = wdComponentAPI.getMessageManager();
Object attributeValue = wdContext.currentDestination_FromElement().getAttributeValue(FieldName);
IWDAttributeInfo attributeInfo = wdContext.getNodeInfo().getAttribute(FieldName);
messageMgr.reportSuccess(wdContext.getNodeInfo().getAttribute(FieldName).toString());
if (((String) attributeValue).length() == 0)
{
messageMgr.reportContextAttributeMessage(
wdContext.currentContextElement(),
attributeInfo,
IMessageFlightList_Comp.MISSING_INPUT,
new Object[] { "City" },
true);
}
//@@end
}
action button: submit
public void onActionsubmit(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
{
//@@begin onActionsubmit(ServerEvent)
this.CheckMandatory(IPrivateFlightList_View.IDestination_FromElement.CITY);
wdThis.wdGetFlightList_CompController().executeBapi_Flight_Getlist_Input();
//@@end
}
now after executnig n click on submit button, i m getting below error:
java.lang.NullPointerException
at com.sccl.FlightList_View.CheckMandatory(FlightList_View.java:149)
at com.sccl.FlightList_View.onActionsubmit(FlightList_View.java:169)
at com.sccl.wdp.InternalFlightList_View.wdInvokeEventHandler(InternalFlightList_View.java:205)
at com.sap.tc.webdynpro.progmodel.generation.DelegatingView.invokeEventHandler(DelegatingView.java:87)
at com.sap.tc.webdynpro.progmodel.controller.Action.fire(Action.java:67)
at com.sap.tc.webdynpro.clientserver.window.WindowPhaseModel.doHandleActionEvent(WindowPhaseModel.java:420)
at com.sap.tc.webdynpro.clientserver.window.WindowPhaseModel.processRequest(WindowPhaseModel.java:132)
at com.sap.tc.webdynpro.clientserver.window.WebDynproWindow.processRequest(WebDynproWindow.java:335)
.................................................
Hi,
check Input field mandatory:
1.Create an context attribute and it should be available on the current context.
2.Display name is dynamically created text message and fieldContextID is common for every message.
3.you can create the method in component/view controller as checkMandatory(with params what we declare below)
4.this method should where we need to check this method simple add like this.
In Onactoon()
{
checkMandatory(pleae eneter,context value attribute name);
wdComponentAPI.getMessageManager().raisePendingException();
}
public void checkMandatory( java.lang.String displayName,java.lang.String fieldContextID )
{
//@@begin checkMandatory()
IWDMessageManager messageMgr =wdThis.wdGetAPI().getComponent().getMessageManager();
String attributeValue = wdContext.currentContextElement().getAttributeAsText(fieldContextID);
IWDAttributeInfo attributeInfo =wdContext.getNodeInfo().getAttribute(fieldContextID);
if (attributeValue != null)
attributeValue = attributeValue.trim();
if (attributeValue.length() == 0 && attribute.charAt('@') < 0 ) {
messageMgr.reportContextAttributeMessage(wdContext.currentContextElement(),attributeInfo,
IMessage<compname>.EMPTY_INPUT,
new Object[] { displayName },
true);
}
5. Go to message editor and add the EMPTY_INPUT key and add your message add over there.
regards,
Pradeep
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi venkat ,
in the check mandatory u are passing the attribute which belong to node Destination.
this.CheckMandatory(IPrivateFlightList_View.IDestination_FromElement.CITY);
and while printing u are getting the attribute from the context ,
so better remove the line message manager from the code .
and
since the attribute is not intialised before the execution of the submit button ,u get the null pointer exception.
ie :
here the attributeValue is not intialiesd so the value would be null. and invoking a method with null object result in null pointer exception ...
if (((String) attributeValue).length() == 0)
{
messageMgr.reportContextAttributeMessage(
wdContext.currentContextElement(),
attributeInfo,
IMessageFlightList_Comp.MISSING_INPUT,
new Object[] { "City" },
true);
}
better do it in this way ,
in the doinit method , intialize the city attribute with "".
wdContext.nodeDestination.setCity("");
In the check mandatory method :
if (((String) attributeValue).length() == 0)
{
messageMgr.reportContextAttributeMessage(
wdContext.currentContextElement(),
attributeInfo,
IMessageFlightList_Comp.MISSING_INPUT,
new Object[] { "City" },
true);
}
thanks and regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hI....
now i m getting validated messages...
if it is error, its giving error message at the bottom of the page
i need some more modifiable output
when its throughed any error...its giving error message...till now ok
how to make input filed red color when its throughed error.
wehn i select error the inputfiled should give an description of that error....
its standard one...i knw it...but wer i m missing i dont knw
kindly put sme light on this
tqu
hi ,
use the context Attribute Exception method of message manager .
IWDMessageManager messageMgr = wdComponentAPI.getMessageManager();
String fieldLabel = wdContext.nodePatentDetails().getNodeInfo()
.getAttribute(fieldname).getSimpleType().getFieldLabel();
messageMgr.reportContextAttributeMessage(wdContext
.currentPatentDetailsElement(), titleAttributeInfo,
IMessageWDCOCreatePatent.TITLE,
new Object[] , true);
thanks and regards
Hi,
For this you have to link your input field with error message.
Create a message pool with message key and error message. after write code like this, here I am giving you the generic code, change as you want
//Report a message with reference to the context (links message to the offending field)
msgMgr.reportContextAttributeMessage(
nodeElement,
attrInfo,
IMessage{nc}.{MessageKey},
new Object[] {p1,u2026,pn},
boolean);
// Metadata of context attribute {ca}, containing the erroneous value
IWDAttributeInfo attrInfo =
wdContext.node{cn}.getNodeInfo().getAttribute({ca});
// Reference to element at lead selection, having {ca} as a child
I{cn} Element nodeElement = wdContext. node{cn}.current{cn}Element();
Checking the Exception Manager for stored messages and terminate user coding processing
wdComponentAPI.getMessageManager()
.raisePendingException();
here is the step by step procedure for doing the above one
http://help.sap.com/erp2005_ehp_03/helpdata/EN/36/d4528e6dbf084b9d79a50fb8d08e86/frameset.htm
regards,
Pradeep
Hi,
Problem will be one of these lines
IWDAttributeInfo attributeInfo = wdContext.getNodeInfo().getAttribute(FieldName);
messageMgr.reportSuccess(wdContext.getNodeInfo().getAttribute(FieldName).toString());
if (((String) attributeValue).length() == 0)
in if condition you can directly write if (attributeValue != null) and after trim() the value
and to check the size if (attributeValue.length == 0).
change this lines... you will get it..
*check the code which I posted previously.
regards,
Pradeep
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
It seems that there could be this line which is responsible for this error.
messageMgr.reportSuccess(wdContext.getNodeInfo().getAttribute(FieldName).toString());
I mean to say that "wdContext.getNodeInfo().getAttribute(FieldName)" is null. Dont have ant idea what you are trying to do with this line.
Please check this line. Hope it helps.
thanks & regards,
Manoj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
81 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.