on 01-28-2005 11:04 AM
Hello,
we want to achieve that our dynamic tree will
be built up in the state it was before we jumped onto another page. When navigating backwards, the tree
does not remember any more it treenodes properties.
Just the root is displayed, not any more the information which node was open and which not.
Also restoreViewState = "TRUE" did not help.
Any ideas ?
Thanks.
Have you tried the following.
When you create a <htmlb:tree> and use the restoreViewState, the application will generate hidden input fields for each of the tree nodes. It uses these input fields to persist the view state.
Now in your inputProcessing before you do the navigation, you could use a call to request->get_form_fields to get a listing of all these hidden input fields and their values.
DATA: fields TYPE tihttpnvp.
request->get_form_fields( CHANGING fields = fields ).
IF sy-subrc NE 0.
ENDIF.
You could persist these values yourself using a server cookie perhaps. Then on the Initialization of the original page when you navigate back, you check for this server cookie. If you find it, use the values from the hidden input fields to set the inital state of each tree node manually.
This should have the effect that you are looking for. Let me know if you need code samples for the server cookie or other parts of this solution.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Here is a complete (yet simplistic) example that proves that the serialization idea works.
Stateless Application
Page One called tree.htm
Page Attributes (Auto Flag is NOT set)
h1_isopen TYPE STRING
h2_isopen TYPE STRING
view_state TYPE SHSVALTAB
OnInitialization
* event handler for data retrieval
DATA: istream TYPE string,
xslt_err TYPE REF TO cx_xslt_exception.
**** Read Server cookie
CALL METHOD cl_bsp_server_side_cookie=>get_server_cookie
EXPORTING
name = 'view_state'
application_name = runtime->application_name
application_namespace = runtime->application_namespace
username = sy-uname
session_id = runtime->session_id
data_name = 'view_state'
CHANGING
data_value = istream.
**** deserialize the Class
IF istream IS NOT INITIAL.
TRY.
CALL TRANSFORMATION id
SOURCE XML istream
RESULT view_state = view_state.
CATCH cx_xslt_exception INTO xslt_err.
ENDTRY.
ENDIF.
CHECK view_state IS NOT INITIAL.
FIELD-SYMBOLS: <wa_state> LIKE LINE OF view_state.
LOOP AT view_state ASSIGNING <wa_state>.
IF <wa_state>-key CS 'Header1'.
IF <wa_state>-value = 'O'.
h1_isopen = 'TRUE'.
ENDIF.
ENDIF.
IF <wa_state>-key CS 'Header2'.
IF <wa_state>-value = 'O'.
h2_isopen = 'TRUE'.
ENDIF.
ENDIF.
ENDLOOP.
OnInputProcessing
* event handler for checking and processing user input and
* for defining navigation
DATA: fields TYPE tihttpnvp.
request->get_form_fields( CHANGING fields = fields ).
FIELD-SYMBOLS: <wa_field> LIKE LINE OF fields,
<wa_state> LIKE LINE OF view_state.
LOOP AT fields ASSIGNING <wa_field>.
IF <wa_field>-name CS 'test'. "My Tree ID
APPEND INITIAL LINE TO view_state ASSIGNING <wa_state>.
<wa_state>-key = <wa_field>-name.
<wa_state>-value = <wa_field>-value.
ENDIF.
ENDLOOP.
DATA: ostream TYPE string,
xslt_err TYPE REF TO cx_xslt_exception.
***** serialize model class
TRY.
CALL TRANSFORMATION id
SOURCE view_state = view_state
RESULT XML ostream.
****Write cookie it into the Server Cookie
cl_bsp_server_side_cookie=>set_server_cookie( name = 'view_state'
application_name = runtime->application_name
application_namespace = runtime->application_namespace
username = sy-uname
session_id = runtime->session_id
data_name = 'view_state'
data_value = ostream
expiry_time_rel = '1200' ).
CATCH cx_xslt_exception INTO xslt_err.
ENDTRY.
navigation->goto_page( 'Navigate.htm' ).
Layout of tree.htm
<%@page language="abap" %>
<%@extension name="htmlb" prefix="htmlb" %>
<htmlb:content design="design2003" >
<htmlb:page title=" " >
<htmlb:form>
<htmlb:tree id = "test"
restoreViewState = "TRUE" >
<htmlb:treeNode id = "Header1"
text = "Header1"
isOpen = "<%= h1_isopen %>" >
<htmlb:treeNode id = "Header2"
text = "Header2"
isOpen = "<%= h2_isopen %>" >
<htmlb:treeNode id = "Item1"
text = "Item1" />
<htmlb:treeNode id = "Item2"
text = "Item2" />
</htmlb:treeNode>
<htmlb:treeNode id = "Item3"
text = "Item3" />
<htmlb:button text = "test"
onClick = "TEST" />
</htmlb:treeNode>
</htmlb:tree>
</htmlb:form>
</htmlb:page>
</htmlb:content>
Second Page Navigate.htm (Just a dummy page to simulate Navigation)
OnInputProcessing
* event handler for checking and processing user input and
* for defining navigation
navigation->goto_page( 'tree.htm' ).
Layout for Navigate.htm
<%@page language="abap"%>
<%@extension name="htmlb" prefix="htmlb"%>
<htmlb:content design="design2003">
<htmlb:page title = " ">
<htmlb:form>
<htmlb:textView text = "Hello World!"
design = "EMPHASIZED" />
<htmlb:button text = "Press Me"
onClick = "myClickHandler" />
</htmlb:form>
</htmlb:page>
</htmlb:content>
restoreViewState = "TRUE" would work if you are in the same page and making server round trips. if you naviagate away from the page and coming back ot it, restoreViewState = "TRUE" wont help. As Thomas suggested, you should write the state of the tree to server side cookie and read it back to set it to last state of the tree.
Regards
Raja
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Check out this weblog to get you started:
/people/durairaj.athavanraja/blog/2004/11/21/bsphow-to-build-performance-efficient-dynamic-htmlbtree
You should also do a search in this forum for treeNode because this has been a topic covered quite a bit but I think the weblog will be enough help to get you to where you need.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
83 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.