WebDynpro (both Java and ABAP edition) provides great options for formatting majority of data types. However, certain applications have own types (or if you like domains in RDBMS world) and demand even more – phone numbers, SSN, credit card numbers etc. WebDynpro does not support these capabilities out of the box, but you may roll your own solution using calculated attributes.
We have Phone Number data type from backend. Originally it is a field of type long. But we want to display it in user-friendly manner, something like (123)456-7890 for value 1234567890.
You have already an attribute in context node, say Phone (phone number with extension code) of type long.
- Create calculated attribute
PhoneFormatted of type string:
- create sub-node with cardinality 1..1 and selection 1..1 as direct child of aforementioned node;
create string attribute PhoneFormatted here of type string;
- select calculated in properties and WD generates getter / setter methods for attributes in controller.
- Add the following block to the custom coding area of controller:
private MessageFormat fmtPhone = new MessageFormat
final private static Pattern PHONE = Pattern.compile
- Complete code for calculated attribute getter:
- Declared getter method for attribute PhoneFormatted of node <SubNodeName>
- @param element the element requested for the value
- @return the calculated value for attribute PhoneFormatted
public java.lang.String get
//@@begin javadoc:setPhoneFormatted(IPrivateRTFViewerCV.IContextElement, java.lang.String)
- Declared setter method for attribute PhoneFormatted of node <SubNodeName>
- @param element the element to change the value
- @param value the new value for attribute PhoneFormatted
public void set