on 09-07-2006 2:22 PM
Hi,
in my web dynpro application are lots of required fields.
How could I check if they were filled?
I hope there is a loop-solution, or someting else,
which guide me to every UI-Element to check.
Thanks Steve
Hello Steve
Try this :
Have a method say 'reportException' with input parameter of type 'String' where you report exception of null attributes.
Then, where-ever you want to do validate fields , there you run a loop of the size of node containing the attributes bound to the fields that require validation.
for(int i=0; i< nodeSize; i ++)
{
<get the element at i from the node, say nodeElement)>
if(null == nodeElement.attribute || nodeElement.attribute.length <= 0)
{
this.reportException(nodeElement.attibute);
}
Please note, in the reportException, use message manager's reportInvalidExceptionAttribute() in order to report all null fields at a time.
I hope this helps you.
Regards
Kapil
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Kapil,
How it works??? I didn't understand the logic getting context elements in the for loop.
Steve,
Try the following code.Here you don't need to write method for every field. You just need to call this method for all fields.
fieldName - is the Context Variable
fieldValue - is the Value
columnName - For which Column you want to show error msg. Ex: - "Name is required". Name - is Column Name
call this method like this.
wdThis.checkMandatory(contextElement.NAME,name,"Name");
// For all your entries, call this method.
public void checkMandatory( java.lang.String fieldName, java.lang.String fieldValue, java.lang.String columnName ){
//@@begin checkMandatory()
IWDMessageManager manager = wdComponentAPI.getMessageManager();
IWDAttributeInfo attributeInfo = null;
IWDNodeInfo iNodeInfo = wdContext.getNodeInfo();
if (fieldValue == null){
fieldValue = "";
}
if (fieldName == null){
fieldName = "";
}
if (contextElement != null){
if (iNodeInfo != null){
attributeInfo = iNodeInfo.getAttribute (fieldName);
}
if (fieldValue.length() == 0 && attributeInfo != null){
manager.reportContextAttributeMessage(
contextElement,
attributeInfo,
IMessageCompany.MISSING__INPUT,
new Object[] { columnName },
true);
}
}
//@@end
}
Note : In the Message Pool declare a Msg as 'is required.' Msg Type - Error.
Regards,
Sridhar
Message was edited by: Sridhar kanchanapalli
Please let me know if I have understood your question correctly.
a) All that you want to check is whether the user has filled the input field ? Only if the user has not filled the input field , throw an error. Is that right ?
If that is true, wouldn't the <b>state</b> of input field help ? Set the state to required.
Regards,
Subramanian V.
Hi,
You have to use portal Eventing
Receiver side : wdPortalEventing.fire()
Sender Side: wdPortalEventing.subscribe()
You have to set the action for button. Write the code in that action. This is the sample code.
public void onActionShow(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent
wdEvent )
{
//@@begin onActionShow(ServerEvent)
String name = wdContext.currentContextElement().getName();
WDPortalEventing.fire("urn:com.sap.tc.webdynpro.example.portaleventing",
"Show",
name);
//@@end
}
public void wdDoInit()
{
//@@begin wdDoInit()
WDPortalEventing.subscribe("urn:com.sap.tc.webdynpro.example.portaleventing",
"Show",
wdThis.wdGetReactPortalEventingAction() );
//@@end
}
public void
onActionReactPortalEventing(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent
wdEvent, java.lang.String dataObject )
{
//@@begin onActionReactPortalEventing(ServerEvent)
wdContext.currentContextElement().setName(dataObject);
//@@end
}
Regards,
Saraswathi.
Hi Steve,
How do you mark your fields as mandatory?
Do you set "state" attribute of InputField to "required"? Then you could run through all view elements in wdDoModifiyView the first time, and for each InputField encountered check the "state" property. If "state" is required, add the bindingOfValue to some list. Store that list in your context.
Now if you want to check required fields in an action handler you loop through the list, for each element find the matching context attribute and check its value.
You can then use MessageManager to point out missing items on the screen.
This is the most generic solution I can think about.
Might be best to think about a(n already existing?) model that supports these checks, though. Bind your UI elements via context binding, context mapping, model binding to your model and let the model do the work.
Keeping model and UI in sync in terms of user feedback (marking required fields with "*", pointing out missing items on the screen) still will be a challenge.
Regards
Markus
Steve,
Look at <a href="http://help.sap.com/saphelp_erp2005vp/helpdata/en/df/5893426f257073e10000000a155106/content.htm">Non-Validating and Validating Actions</a> and <a href="http://help.sap.com/saphelp_erp2005vp/helpdata/en/0d/5375848e41aa4c86219c80acd054df/content.htm">Validation Example</a>
Bala
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Bala,
thanks for your ideas, but I'm not searching for that.
There must be a comfortable solution for implementing such an use case, otherwise you cannot implement flexible applications with web dynpro.
For me its not plausible to name all contextelemets within a method, to get the required option.
In hope for a good solution
Steve
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.