6 Replies Latest reply: May 15, 2013 5:52 PM by BAO.SZ RSS

    How to convert CreatewithParams button into a checkbox?

    BAO.SZ
      Hi,experts!
      In jdev 11.1.2.3,
      I have a maybe uncommon and simple requirement: how to convert a CreatewithParams button into a checkbox ?
      The use case for this requirements is this:

      A scenario:(Why the second NamedData variable doesnot work for CreateWithParams? --This use case maybe used many times for me.
      There is a m-m relation between VO1,and VO3 with VO2 as the cross-link table:
      --A 1-M link between VO1(id,amount),VO2(id,amount,fkid1,fkid3) where VO2.fkid1=VO1.id;
      --When create a new record for VO2, will select record from VO3(id,amount) and populate for VO2 with VO2.amount=VO3.amount, VO2.fkid3=VO3.id;
      --VO1 render as a formlayout, VO2 and VO3 as tables in the same page;
      --Drag and drop CreateWithParams button for VO2 into VO3's table, so that for each record of VO3,when the button is pressed, a new record for VO2 with default values from VO3 will be created.

      Now I have succeed in implementing above requirements, and want to go forward:
      Change the CreatewithParam button into a checkbox, so that:
      --when the checkbox is selected(true), a new record is created for VO2;
      --when the checkbox is unselected(false), the newly created and correspondent record in VO2 will be deleted.

      But, in jdev designer, cannot find way to convert a button into a checkbox?
      Anyone can help?

      Thanks!
      bao
        • 1. Re: How to convert CreatewithParams button into a checkbox?
          EonvanTonder
          A checkbox is not an action component so you would need to drag a checkbox onto your screen, set it's valueChangeListener to a backing bean method and in that method invoke the create method your button's actionListener is referring to. Here is a simple post on how to do this http://rohith-oracle.blogspot.com/search/label/How%20to%20post%20changes%20to%20a%20Database%20using%20ValueChangeListener. You will call Create/CreateWithParams i.s.o. commit though
          • 2. Re: How to convert CreatewithParams button into a checkbox?
            Timo Hahn
            Because you can't access the blog here is the text
            ADF - How to submit/post values changes to database immediately in ADF UI components
            
            When you want to persist changes to a database as soon as a user changes the value in any of the UI Components. you can use the below technique.
            
            1. Add a value change listener to your UI Component and also make Auto Submit to true.
            
            <af:selectOneChoice value="{row.bindings.reasonCode.inputValue}" 
                 label="#{row.bindings.reasonCode.label}" id="soc1" autoSubmit="true"
                 valueChangeListener="#{failures.reasoncodeChange}">
                             <f:selectItems value="#{row.bindings.reasonCode.items}" id="si1"/>
            </af:selectOneChoice>
            
            2.  In the Backing bean value change listener method
            valueChangeEvent.getComponent().processUpdates(FacesContext.getCurrentInstance());
            Calling the the above line will do all the model updates. refer the link
            
            public void reasoncodeChange(ValueChangeEvent valueChangeEvent) {
            valueChangeEvent.getComponent().processUpdates(FacesContext.getCurrentInstance());
            BindingContainer bindings = getBindings();
            OperationBinding operationBinding =bindings.getOperationBinding("Commit");
            operationBinding.execute();            
            }
            Timo (sorry you can't get to the other blogs)
            • 3. Re: How to convert CreatewithParams button into a checkbox?
              BAO.SZ
              Hi, experts,

              I write a method in a backing bean to be called by a valueChangeListener in one of VO3' column to invoke the createWithParas method createReceipt() for VO2 as flowing:
              =================
              public void addRecbyBill(ValueChangeEvent valueChangeEvent) {
              BindingContainer bindings = getBindings();
              AttributeBinding Sel= (AttributeBinding) bindings.get("Sel");

              if (Sel.getInputValue().equals(1)) {
              String receiptRel = createReceiptRel();
              Sel.setInputValue(0);
              } else {
              String receiptRel = delReceiptRel();
              Sel.setInputValue(1);
              }
              }
              ===================
              The goal for above is to create a new row for VO2 based on values of the selected row in VO3.

              The problem is:
              More than one row is created by this call. and the number of rows created is decided by the number of rows in VO3.

              Can someone give any advice on this issue?
              Thanks!

              Edited by: BAO.SZ on 2013-5-15 下午1:47
              • 4. Re: How to convert CreatewithParams button into a checkbox?
                Timo Hahn
                The code you have posted doesn't reveal why more the one row is created.
                Have you debugged the code to see if the method is called more than once?
                What does the createReceiptRel() method do?
                how is the checkBox setup? where is the selection stored?
                Why do you set the sel parameter back to 0 after calling the createReceiptRel() method?
                Would this not remove the checkmark the user just set in the UI?
                You know that you can get the value (state of the checkbox) by using valueChangeEvent.getNewValue();
                There is no need to use the attribute value.

                Timo
                • 5. Re: How to convert CreatewithParams button into a checkbox?
                  BAO.SZ
                  Hi, Timo

                  I have another try:
                  In VO2, add a attribute SelBill which is BigDecimal with default value of 0;
                  Here is the codes:

                  (for simplicity VO2 refer to TransBillReceiptRel, VO3 refer to TransAccountBill1VO1)
                  ================
                  <af:column sortProperty="#{bindings.TransAccountBill1VO1.hints.Status.name}"
                  sortable="true"
                  headerText="#{bindings.TransAccountBill1VO1.hints.Status.label}"
                  id="c45" width="85">
                  <af:inputText value="#{row.bindings.Status.inputValue}"
                  label="#{bindings.TransAccountBill1VO1.hints.Status.label}"
                  required="#{bindings.TransAccountBill1VO1.hints.Status.mandatory}"
                  columns="#{bindings.TransAccountBill1VO1.hints.Status.displayWidth}"
                  maximumLength="#{bindings.TransAccountBill1VO1.hints.Status.precision}"
                  shortDesc="#{bindings.TransAccountBill1VO1.hints.Status.tooltip}"
                  id="it59"
                  inlineStyle="background-color:rgb(202,255,253);">
                  <f:validator binding="#{row.bindings.Status.validator}"/>
                  <af:convertNumber groupingUsed="false"
                  pattern="#{bindings.TransAccountBill1VO1.hints.Status.format}"/>
                  </af:inputText>
                  </af:column>
                  <af:column sortProperty="#{bindings.TransAccountBill1VO1.hints.IsValid.name}"
                  sortable="true"
                  headerText="#{bindings.TransAccountBill1VO1.hints.IsValid.label}"
                  id="c46" width="31"
                  visible="false">
                  <af:inputText value="#{row.bindings.IsValid.inputValue}"
                  label="#{bindings.TransAccountBill1VO1.hints.IsValid.label}"
                  required="#{bindings.TransAccountBill1VO1.hints.IsValid.mandatory}"
                  columns="#{bindings.TransAccountBill1VO1.hints.IsValid.displayWidth}"
                  maximumLength="#{bindings.TransAccountBill1VO1.hints.IsValid.precision}"
                  shortDesc="#{bindings.TransAccountBill1VO1.hints.IsValid.tooltip}"
                  id="it63">
                  <f:validator binding="#{row.bindings.IsValid.validator}"/>
                  <af:convertNumber groupingUsed="false"
                  pattern="#{bindings.TransAccountBill1VO1.hints.IsValid.format}"/>
                  </af:inputText>
                  </af:column>
                  <af:column sortProperty="#{bindings.TransAccountBill1VO1.hints.Sel.name}"
                  sortable="true"
                  headerText="#{bindings.TransAccountBill1VO1.hints.Sel.label}"
                  id="c51" width="50"
                  visible="false">
                  <af:inputText value="#{row.bindings.Sel.inputValue}"
                  label="#{bindings.TransAccountBill1VO1.hints.Sel.label}"
                  required="#{bindings.TransAccountBill1VO1.hints.Sel.mandatory}"
                  shortDesc="#{bindings.TransAccountBill1VO1.hints.Sel.tooltip}"
                  id="it64">
                  <f:validator binding="#{row.bindings.Sel.validator}"/>
                  </af:inputText>
                  </af:column>
                  ==================

                  <af:column id="c52" width="49"
                  visible="true">
                  <af:selectBooleanCheckbox
                  id="SelBill"
                  autoSubmit="true"
                  attributeChangeListener="#{TransBillReceiptRel.ChkBill4Rec}"
                  value="#{bindings.SelBill.inputValue}"
                  valueChangeListener="#{TransBillReceiptRel.addRecbyBill}"/>
                  </af:column>
                  ==================

                  <af:column id="c38" width="44">
                  <af:commandButton text="SEL"
                  disabled="#{!bindings.CreateWithParams.enabled}"
                  id="SelRel"
                  action="#{TransBillReceiptRel.createReceiptRel}"
                  partialSubmit="true"/>
                  ==================

                  </af:column>
                  <af:column id="c53" width="55">
                  <af:commandButton
                  text="DEL"
                  disabled="#{!bindings.Delete2.enabled}"
                  id="DelRel"
                  partialSubmit="true"
                  action="#{TransBillReceiptRel.DelTranBillReceiptRel}"/>
                  </af:column>

                  ======================================
                  package backing;

                  import javax.faces.component.UIComponent;
                  import javax.faces.context.FacesContext;
                  import javax.faces.event.ValueChangeEvent;

                  import oracle.adf.model.BindingContext;

                  import oracle.adf.model.binding.DCBindingContainer;
                  import oracle.adf.model.binding.DCIteratorBinding;

                  import oracle.adf.view.rich.component.rich.data.RichTable;

                  import oracle.adf.view.rich.event.ColumnSelectionEvent;

                  import oracle.binding.BindingContainer;
                  import oracle.binding.OperationBinding;
                  import oracle.binding.AttributeBinding;

                  import org.apache.myfaces.trinidad.event.AttributeChangeEvent;

                  import project1.TransAccountBill1VORowImpl;
                  import project1.TransAccountBillImpl;
                  import project1.TransBillReceiptRelImpl;


                  public class TransBillReceiptRel {
                  private static Object createReceiptRel;
                  private RichTable cellColor;

                  public TransBillReceiptRel() {
                  }

                  public BindingContainer getBindings() {
                  return BindingContext.getCurrent().getCurrentBindingsEntry();
                  }

                  public String createReceiptRel() {
                  BindingContainer bindings = getBindings();
                  OperationBinding operationBinding = bindings.getOperationBinding("CreateWithParams");
                  Object result = operationBinding.execute();
                  if (!operationBinding.getErrors().isEmpty()) {
                  return null;
                  }
                  return null;

                  }

                  public void addRecbyBill(ValueChangeEvent valueChangeEvent) {
                  BindingContainer bindings = getBindings();
                  AttributeBinding ChkBill= (AttributeBinding) bindings.get("ChkBill");
                  AttributeBinding Sel= (AttributeBinding) bindings.get("SelBill");

                  if (Sel.getInputValue().equals(1)) {
                  //String receiptRel = createReceiptRel();
                  String receiptRel = DelTranBillReceiptRel();
                  Sel.setInputValue(-1);
                  } else {
                  //String receiptRel = DelTranBillReceiptRel();
                  String receiptRel = createReceiptRel();
                  Sel.setInputValue(1);
                  }
                  }


                  public String DelTranBillReceiptRel() {

                  BindingContainer bindings = getBindings();
                  OperationBinding operationBinding = bindings.getOperationBinding("Delete2");
                  Object result = operationBinding.execute();

                  if (!operationBinding.getErrors().isEmpty()) {
                  return null;
                  }
                  return null;

                  }



                  public void ChkBill4Rec(AttributeChangeEvent attributeChangeEvent) {
                  // Add event code here...
                  // select bill record for receipts. 130516
                  BindingContainer bindings = getBindings();
                  AttributeBinding ChkBill= (AttributeBinding) bindings.get("ChkBill");
                  AttributeBinding Sel= (AttributeBinding) bindings.get("Sel");

                  if (Sel.getInputValue().equals(1)) {
                  String receiptRel = createReceiptRel();
                  Sel.setInputValue(0);
                  } else {
                  String receiptRel = createReceiptRel();
                  Sel.setInputValue(1);
                  }
                  }
                  }
                  ============================

                  The result is:
                  The Sel button can work ok: add one row for each hit;
                  (http://223.4.132.24:8180/BlobUtilServlet?tableName=FILE_TABLE&columnName=BODY&stuffID=020010110000001292&strNO=1&type=downfile&fileName=Receipt01.jpg&directOpen=true)

                  But one click of SelBill checkbox will create 10 same rows (VO3 has 10 rows).
                  (http://223.4.132.24:8180/BlobUtilServlet?tableName=FILE_TABLE&columnName=BODY&stuffID=020010110000001292&strNO=2&type=downfile&fileName=Receipt02.jpg&directOpen=true)

                  Can you see the process?
                  Thanks

                  Edited by: BAO.SZ on 2013-5-15 下午3:49
                  • 6. Re: How to convert CreatewithParams button into a checkbox?
                    BAO.SZ
                    The code you have posted doesn't reveal why more the one row is created.
                    Have you debugged the code to see if the method is called more than once?
                    ---have not. and i not familar how to.

                    What does the createReceiptRel() method do?
                    --method for createWithParas for VO2.

                    how is the checkBox setup? where is the selection stored?
                    --a triansient attribute from VO2.

                    Why do you set the sel parameter back to 0 after calling the createReceiptRel() method?
                    Would this not remove the checkmark the user just set in the UI?
                    --no.

                    You know that you can get the value (state of the checkbox) by using valueChangeEvent.getNewValue();
                    There is no need to use the attribute value.
                    --so i can try

                    Thanks