3 Replies Latest reply: Nov 5, 2013 11:46 PM by LargeDachshund RSS

    Localizing the Timestamp as a default value

    LargeDachshund

      i'm trying to add a read-only field to a form that will have a timestamp based on the user's location, i.e. his browser location.  i've seen comments abound on timestamps in the database, but, in this situation, i'm not running a system process.

       

      i want to record the time when the user created the record.  is it true that adfFacesContext.getCurrentInstance() has a property that indicates the browser's local time.  can i somehow put it in the VO attribute's default value?

       

      can this be done programmatically?

       

          BindingContainer bindings = getBindings();

       

       

          OperationBinding operationBinding = bindings.getOperationBinding("Create");

       

       

          Object result = operationBinding.execute();

       

       

          if (!operationBinding.getErrors().isEmpty())

       

      If i intercept the process prior to operationBinding.execute, can i set the field after i get the local time and convert to timestamp?

       

      thanks,

        • 1. Re: Localizing the Timestamp as a default value
          Frank Nimphius-Oracle

          Hi,

           

          you can access the field after you executed the "Create" operation. Before it does not much sense as there would not be a new row created. You can then call

           

          DcIteratorBinding iter = (DcIteratorBinding) bindings.get("Name of Iterator");

          Row rw = iter.getCurrentRow();

          //set value

           

          rw.setAttribute("name of attribute", value);

           

          If this doesn't immediately show on the UI, issue a PPR (ADFFacesContext.getCurrentInstance().addPartialTarget(component) ) for the form layout or table

           

           

          For the client timezone, have a look at

           

          Configuring Apache Trinidad

           

          It discusses the time-zone option in trinidad-config.xml (used by ADF Faces). You can use this with org.apache.myfaces.trinidad.converter.DateTimeConverter to convert times from a String

           

          Frank

          • 2. Re: Localizing the Timestamp as a default value
            LargeDachshund

            Frank,

            thank you so much for your detailed response.  it's Halloween in the States, so i'll provide you a reply on how it goes with your solution over the weekend.

            • 3. Re: Localizing the Timestamp as a default value
              LargeDachshund

              hey Frank,

              i think your hunch was right.  PPR is in order because i wasnt able to get the fields to appear.  now, i've hunted around for a way of invoking the PPR.  on pfl1(panelFormLayout), i set the clientComponent attribute to true.  no joy.  this is what i got:

                public String createNewRow()

                {

                BindingContainer bindings;

                  OperationBinding operationBinding;

                  Object result;

                  DCIteratorBinding iter;

                  Row rw;

                 

                  bindings = getBindings();

               

               

                  operationBinding = bindings.getOperationBinding("Create");

               

               

                  //create the empty row

                  result = operationBinding.execute();

               

               

                  //access the empty row and set the Created field

                  iter = (DCIteratorBinding) bindings.get("JATableView1Iterator");

               

               

                  rw = iter.getCurrentRow();

               

               

                  //set value: this isnt even a timestamp.  once i can get the form fields to appear, i'll worry about the timestamp!

                  rw.setAttribute("Created", "11/9/2013");

                 

                  AdfFacesContext.getCurrentInstance().addPartialTarget(getUIComponent("pfl1"));

                 

                  if (!operationBinding.getErrors().isEmpty())

                  {

                    return null;

                  }

                  else

                  {

                    return null;

                  }

                }

               

                private UIComponent getUIComponent(String name)

                { 

                  FacesContext facesCtx = FacesContext.getCurrentInstance(); 

                  return facesCtx.getViewRoot().findComponent(name); 

                }