Additional Blogs by Members
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member
0 Kudos

Introduction


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.


Scenario


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.


Solution


You have already an attribute in context node, say Phone (phone number with extension code) of type long.

    1. Create calculated attribute
PhoneFormatted of type string:

    1. 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;

    1. select calculated in properties and WD generates getter / setter methods for attributes in controller.

    1. Add the following block to the custom coding area of controller:


//@@begin others
private MessageFormat fmtPhone = new MessageFormat
(
  "'('{0,number,000}')'{1,number,000}'-'{2,number,0000}"
);
final private static Pattern PHONE = Pattern.compile
(
  "^
((
d)
)(
d
)-(
d)$"
);
//@@end




    1. Complete code for calculated attribute getter:

//@@begin javadoc:getPhoneFormatted(IPrivateRTFViewerCV.IContextElement)
/**
  1. Declared getter method for attribute PhoneFormatted of node <SubNodeName>
  1. @param element the element requested for the value
  1. @return the calculated value for attribute PhoneFormatted
*/
//@@end
public java.lang.String get


//@@begin javadoc:setPhoneFormatted(IPrivateRTFViewerCV.IContextElement, java.lang.String)
/**
  1. Declared setter method for attribute PhoneFormatted of node <SubNodeName>
  1. @param element the element to change the value
  1. @param value the new value for attribute PhoneFormatted
*/
//@@end
public void set


2 Comments