To achieve this:
- reinitialize the view with a custom writer object
- process the view
- retrieve the output from the writer object
Let's suppose we have a view, block.htm. that we want to render to a string, encode as html,
and include the result in another view main.htm.
Views:
-- block.htm
<%@page language="abap"%>
<strong>The name is <%= name %></strong>
-- main.htm
<%@page language="abap"%>
<html>
<body><%= blockader %></body>
</html>
Our controller code would look like this:
method DO_REQUEST.
DATA: view TYPE REF TO if_bsp_page,
main_view TYPE REF TO if_bsp_page,
writer type ref to cl_bsp_writer,
prev_writer type ref to if_bsp_writer,
render_block type ref to cl_bsp_page_base,
block_content type string,
elem type ref to if_bsp_element.
* Create the view and initialize the attributes.
view = create_view( view_name = 'block.htm' ).
view->set_attribute( name = 'name' value = 'Rose' ).
* Render the view and retrieve the resulting html from the writer object
create object writer
EXPORTING
previous_writer = prev_writer.
render_block ?= view.
render_block->do_reinit( current_element = elem
current_writer = writer ).
render_block->do_request( ).
block_content = writer->get_content( ).
* block_content holds the rendered view as a string.
* do whatever processing you need
block_content = cl_bsp_utility=>encode_string( encoding = if_bsp_writer=>co_html
in = block_content ).
main_view = create_view( view_name = 'main.htm' ).
* you can pass the rendered view as an attribute to include it in another view
main_view->set_attribute( name = 'blockvar' value = block_content ).
call_view( main_view ).
endmethod.
answered
13 Dec '11, 11:20
nuno ♦♦
162●2●2●9
accept rate:
0%