Ever since the
extension was introduced by SAP, I started using it in most of the BSP applications. It gives elegant look and feel and also pages are not crowded with large number of lines of code. However, there is a drawback(I feel), the controls rendered are of the same length.
It would be nicer if the
controls are customizable with different lengths to give more beautiful look and feel.On the other hand, it’s counterpart
extension has the attribute through which the size of the control can be set on the page.
This weblogs shows, how to take advantage of the additional attributes available in
controls but not in
. In this example the input field control
is used for customization. Even other controls from
extension can be customized using the same procedure.
Step 1 : Creating custom BSP extension
Using transaction SE80 create custom BSP extension
Step 2: Creating custom element
Copy the standard PHTMLB control into the custom BSP extension
and activate it. In this example
is copied to the custom BSP extension.
Step 3: Finding element handler class
Find the element handler class for the custom control
in PHTMLB BSP extension.
Using Transaction SE80, Choose standard
tag from the PHTMLB BSP extension, righ click and choose display option from the context menu.
Go to the attributes tab to find out the element handler class for the standard
Step 4: Create custom element handler
Using Class builder transaction(SE24), copy the standard element handler
into custom element handler class
and save the class.
Add additional attributes to the class for
size, maxlength and invalidate
as shown below.
Step 5: Redefine method IF_BSP_ELEMENT~DO_AT_END
From the class builder, choose change button to redefine the method
Add the code as shown below.
Here, the instance of the standard
control is obtained and the additional attributes that are passed from the page are set to the correspoponding attributes( size, maxlength and invalidate )of the instance. The changed
instance is passed to the
instance’s bee attribute.
method if_bsp_element~do_at_end. rc = co_page_continue.* data inputfield type ref to cl_htmlb_inputfield. inputfield ?= cl_htmlb_inputfield=>factory( id = me->id value = me->value type = me->type size = me->size <—Custom New Attributes maxlength = me->maxlength <—Custom New Attributes invalid = me->invalid <—Custom New Attributes disabled = me->
disabled = me->disabled
onvaluehelp = me->onvaluehelp
showhelp = me->showhelp ).
data formlayout type ref to cl_phtmlb_formlayout.
formlayout ?= me->get_class_named_parent( ‘CL_PHTMLB_FORMLAYOUT’ ).
formlayout->add_item( id = me->id
pos = me->pos
label = me->label
label_binding = me->_label
required = me->required
bee = inputfield
visible = me->visible ).
Step 6: Assigining handler class to the custom control
Assign the custom element handler class to the custom
From transaction SE80, select the BSP extension ZCPHTMLB and choose the control
. From the context menu choose change option and select attribute tab. Assign the custom element handler class
as shown and activate the class.
Step 7: Additional attributes in custom control
Define the attributes size, invalidate and maxlength in custom control
, so that when set in the Pagelayout theese values are in turn passed to the element handler class. Activate the BSP extension with all the control elements.
Step 8: Test BSP application
It’s time to test the custom
control. Using SE80, create a BSP application ZSDNPHTMLB with a page main.htm.
First Tray element uses standard PHTMLB
control and the second tray uses the custom
which uses the attribute
to customize the length of the input field.