cancel
Showing results for 
Search instead for 
Did you mean: 

Ajax/Javascript in Web dynpro ABAP

Former Member
0 Kudos

Hi,

I need your help in figuring out what artefacts of web dynpro ABAP could help me resolve a problem.

In a Web dynpro abap application, we have a button that redirects a user to an external site. Some of our users can go to this site from their computer and some others can't because they are not allowed. I would like to be able to show the button only to the users that have the right to execute this navigation.

In order to do that, I need to embed some script in my web dynpro application that will test if the URL of this application sends back an HTTP/200.

With the latest versions of Web Dynpro ABAP, is it possible to embed javascript of ajax? How can it be done?

If not, what could I use to base the visibility of my button on a validation that has to run on the users's browser?

Thank you very much for your help!

Renaud

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi,

Thank you for your answer. This looks very good. Although, it only allows to test if the web dynpro abap server can reach the external server and does not allow to test if the users' computer can reach this server. We know our web dynpro abap server will anwer to the post but the end user (who could not have access to the internet) won't.

I am pretty sure the only solution is to be able to write some script running in the client browser. Any other ideas?

Regards,

Renaud

Former Member
0 Kudos

another option might be that you can have your java script uploaded to mime repository. In any action handler code the following.

data: lo_mr      type ref to if_mr_api,
        l_html type xstring,
        l_mime_type type string.
  lo_mr = cl_mime_repository_api=>get_api( ).
 
 "you have to replace this with your mime location
lo_mr->get( exporting i_url = '/sap/bc/webdynpro/sap/zzs_localcomponent/script.htm'
              importing e_content = l_html
                        e_mime_type = l_mime_type ).
 
  cl_wd_runtime_services=>attach_file_to_response(
        exporting
          i_filename      = 'conn_script.htm'
          i_content       = l_html
          i_mime_type     = l_mime_type
          i_in_new_window = abap_false
          i_inplace       = abap_true ).

see this thread for possible idea to gather.

[|]

alespad
Contributor
0 Kudos

Another way it could be done creating a custom ztransaction (abap report) performing a PING to the ip server , reading log txt, saving if the user is authorized or not , and redirecting to the Abap Web Dynpro.

Then On wddoinit select zztable for authorization.

But i don't know if this solution will work for you (ping specific port 80? or other requirements)

DATA: workdir TYPE string,
      path_log TYPE string,
      parameter TYPE string.

TYPES: BEGIN OF tylog,
     line(1000),
  END OF tylog.
DATA: t_log TYPE TABLE OF tylog,
      v_log LIKE LINE OF t_log.

  DATA:  appl_name TYPE string,
            abs_url TYPE string.
START-OF-SELECTION.

  CALL METHOD cl_gui_frontend_services=>get_sapgui_workdir
    CHANGING
      sapworkdir = workdir.


  CONCATENATE '/C ping google.it >' workdir 
  INTO parameter SEPARATED BY space. "example google
  CONCATENATE parameter '\pinglog.txt' INTO parameter.

  CALL METHOD cl_gui_frontend_services=>execute
     EXPORTING
*    document               =
       application            = 'CMD'
       parameter              = parameter
       synchronous            = 'X'.

  CONCATENATE workdir  '\pinglog.txt' INTO path_log.

  CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
      filename                      = path_log
      filetype                      = 'ASC'
    TABLES
      data_tab                      = t_log.


  LOOP AT t_log INTO v_log WHERE LINE CS 'Lost = 0'. 
    EXIT.
  ENDLOOP.
if sy-subrc = 0. "ping ok
 zzping-uname = sy-uname.
   zzping-authorized = 'X'.
else. 
  zzping-uname = sy-uname.
  zzping-authorized = ' '.
  endif.
   INSERT ZZPING.

**construct web dynpro url and call browser
  cl_wd_utilities=>construct_wd_url( EXPORTING application_name = appl_name 
                                                             IMPORTING out_absolute_url = abs_url ).

CALL FUNCTION 'CALL_BROWSER'
  EXPORTING
    URL                          = abs_url.

Edited by: alessandro spadoni on Mar 24, 2011 10:09 PM

Edited by: alessandro spadoni on Mar 24, 2011 10:31 PM

Former Member
0 Kudos

Hi,

Thanks for your answer although it does not help me as I cannot know from the userID if the button has to be visibled or not. As an example, the same user from different computers could see or not see the button based on network security. I really need to run a script on their machine to check if I can get an HTTP/200 when trying to call he URL.

Anyone knows how to embed some locally running script in a webdynpro abap?

Regards,

Renau

alespad
Contributor
0 Kudos

You can try to execute an HTTP Request in WDDOINIT using ABAP CLASS if_http_client

Small example


  DATA: http_dest TYPE rfcdest VALUE 'HTTPDEST'.
DATA: ld_client TYPE REF TO if_http_client.
  DATA: ld_request TYPE REF TO if_http_request,
        rc TYPE sy-subrc,
        http_rc TYPE sy-subrc,
        xml_xstring TYPE xstring.

  TYPES: BEGIN OF ty_form_field,
         name TYPE string,
         value TYPE string,
  END OF ty_form_field.

  DATA ls_form_field TYPE ty_form_field.

**by Destination or specifing an URL
cl_http_client=>create_by_destination( EXPORTING
  destination = http_dest IMPORTING client = ld_client ).


  ld_request = ld_client->request.

  CALL METHOD ld_client->request->set_method(
    if_http_request=>co_request_method_post ).  "POST or GET

  CLEAR: ls_form_field.
  ls_form_field-name = 'parametername'.
  ls_form_field-value = parameter_value.

  CALL METHOD ld_request->set_form_field
    EXPORTING
      name  = ls_form_field-name
      value = ls_form_field-value.

 *send and receive
  CALL METHOD ld_client->send
    EXCEPTIONS
      http_communication_failure = 1
      http_invalid_state         = 2
      http_processing_failed     = 3
      http_invalid_timeout       = 4
      OTHERS                     = 5.
  IF sy-subrc <> 0.
    RAISE connection_error.
  ENDIF.


  CALL METHOD ld_client->receive
    EXCEPTIONS
      http_communication_failure = 1
      http_invalid_state         = 2
      http_processing_failed     = 3
      OTHERS                     = 4.

* are there any errors?
  rc = sy-subrc.

  IF rc <> 0.
ld_client->close( ).
else.
ld_client->response->get_status( IMPORTING code = http_rc ).

if http_rc = 200.  "HTTP OK

  CLEAR: xml_xstring.
  xml_xstring = ld_client->response->get_data( ). "XML?JSON?HTML?

* VERY IMPORTANT: close your connection
  ld_client->close( ).
endif.

endif.

depending on HTTP RESPONSE you could disable the button

Edited by: alessandro spadoni on Mar 24, 2011 5:53 PM

Edited by: alessandro spadoni on Mar 24, 2011 5:55 PM

Former Member
0 Kudos

Hi There,

I think Based on Login user id you can hide that button.

Create one attribute of the wdui_visibility or wdy_boolean, and bind to visible property of that button.

in WDDOINIT method set this attribute based on login user.

Hope it helps

Cheers,

Kris.