Thursday 30 August 2007

JSF Basics Access the HTTP Session from a backing bean

Here is something I always seem to forget and never realy got to use :-)
Code to gain access to the HTTP session from a inside backing bean :

FacesContext fc = FacesContext.getCurrentInstance();
HttpServletRequest request = (HttpServletRequest)fc.getExternalContext().getRequest();
HttpSession session = request.getSession();

Tuesday 21 August 2007

ABAP: How to get the Screen Table row that the cursor is in

Getting the row that the user cursor is in accomplished by using the GET CURSOR LINE statement. As always, we need to declare a global field named something like cur_tbl_line to hold the current table line. Then during PAI processing we need to issue statements like the following : (tc_mydata is the name of the screen table control and XXX is the screen number)

MODULE user_command_XXX INPUT.

* set up the current line variable
  GET CURSOR LINE cur_tbl_line.
  cur_tbl_line = tc_mydata-top_line + cur_tbl_line - 1.

* do the classic stuff
  ok_code = ok_code_XXX.
  CLEAR ok_code_XXX.

  ...
ENDMODULE.

Using this approach, you can get the selected line of the tbl_mydata table by writing code like this

FORM sync_mydata_with_selection
     CHANGING
        f_none_selected TYPE c.

  FIELD-SYMBOLS
    <fs> LIKE LINE OF tbl_mydata.

  CLEAR f_none_selected.

* give precedence to the table control selection
  READ TABLE tbl_mydata
  WITH KEY sel = 'X'
  ASSIGNING  <fs>.

  IF sy-subrc <> 0.
*   No selection was made so get the current row using the
*   cursor
    IF cur_tbl_line > 0.
      READ TABLE tbl_packages INDEX cur_tbl_line
        ASSIGNING .
    ELSE.
      f_none_selected = 'X'.     
    ENDIF.
  ENDIF.
ENDFORM.

After this is executed, the header line of tbl_mydata contains the selected row and if your user has not selected anything then f_none_selected will have a value of 'X'.

Friday 3 August 2007

ABAP: Gettting the selected column

Every TABLEVIEW control defined in an ABAP program contains a cols field that contains information about selected columns. Whether or not column selection is allowed is set by the tableview object's properties in the screen painter. (see also the relevant image for the posting How to setup a Screen containing a Table a few days back.

One common use for column selection is sorting, so an example sorting function that sorts a global table named tbl_my_data based on the selected column might look like this :

FORM sort_table USING  sort_mode LIKE sy-ucomm.
  FIELD-SYMBOLS
     TYPE cxtab_column.

* find out if a column is selected.
  READ TABLE tc_mytab-cols
    WITH KEY selected = 'X'
    ASSIGNING <selected_col>.

  IF sy-subrc <> 0.
    MESSAGE s888(sabapdocu) WITH 'No column is selected'.
    EXIT.
  ENDIF.

* sort according to the selected column
  CASE sort_mode.
    WHEN 'SORT_ASC'.
      CASE <selected_col>-index.
        WHEN 1.
          SORT tbl_mydata ASCENDING BY field1.
        WHEN 2.
          SORT tbl_mydata ASCENDING BY field2.
        WHEN OTHERS.
          MESSAGE s888(sabapdocu) WITH 'Not yet implemented'.
      ENDCASE.
    WHEN 'SORT_DSC'.
      CASE <selected_col>-index.
        WHEN 1.
          SORT tbl_mydata DESCENDING BY field1.
        WHEN 2.
          SORT tbl_mydata DESCENDING BY field2.
        WHEN OTHERS.
          MESSAGE s888(sabapdocu) WITH 'Not yet implemented'.
      ENDCASE.
  ENDCASE.
ENDFORM.                    " sort_table

Thursday 2 August 2007

SuSE Linux: Speeding up boot time by getting rid of zmd

Here is a cool post I found at linuxQuestions.org.. If you feel that your openSUSE 10.x Linux box is taking too much time to boot, then it might be a good idea to remove ZMD altogether.

The actual details can be found here