Thursday, March 31, 2011

Stupid view criteria with an and criteria not working

Note to self :

When creating a bind variable enabled criteria follow the following steps so you have no hassles.

1) Create LOV with straight sql (no bind variables in sql) or you will get a bind variable not bound error.

2) Create criteria (DONT use a criteria in your mappings create multiple criteria). This avoids parameter not found in sql error.

3) Apply all criteria to attribute lov mapping (View Accessors, edit, blue button to move). Then map your bind variable to a value ie if you have a attribute called Code in the VO you can just write Code in the value section.

4) If you want you can set a hint on the bind variable to hide it in the LOV.

DONE!!!

Wednesday, March 30, 2011

Hunting the elusive panellabelandmessage padding

I have a panelformlayout and with panellabelandmessages and various other stuff in it.

My alignment of fields is screwed because my plam items are left padded by 9px. Why I dont know.

So I decided to pad all the other items by 9px to keep it all looking good. (the plam items seem like they are hard codex to 9px or something).

So I add a style class to the other items called leftPad but the style doesnt work. So I added a background color to my style to check if I got my items correct and like magic the padding and the color work. So I just changed the background back to the original color and everything works - like magic.

Styled item
<af:inputtext columns="#{bindings.Attr1.hints.displayWidth}"
   id="it25" label="#{bindings.Attr1.hints.label}"
   maximumlength="#{bindings.Attr1.hints.precision}" required="true"
   shortdesc="#{bindings.Attr1.hints.tooltip}" styleclass="leftPad"
   value="#{bindings.Attr1.inputValue}">
  <f:validator binding="#{bindings.Attr1.validator}">
</f:validator></af:inputtext>

Style Sheet
.leftPad .AFPanelFormLayoutContentCell {
  padding-left: 9px;
  background-color: #F5F5F9;
}

Tuesday, March 29, 2011

List of values as one item for form layout - And lov key and description lookup

This is a quick and dirty so take note of the downside:

0) Create LOV based on sql query and map lov in your vo.

1) Add transient attribute based on sql query to your vo. (tick mapped to column or sql or and selected in query tick boxes)

2) Enter alias and sql query (Expression) in (makes sure your where clause maps one column of the vo to a column in that table). Select t.desc from table t where t.code = CodeInVO

3) Add an addtional mapping in your LOV setting in your vo attribute and map it (green button to add and select the correct values in the drop down) to your newly created transient.

see below for the formatting of this LOV if you are using a panelFormLayout and you want it to be layed out as one entry in the panel form.

<af:panelLabelAndMessage id="plam11" label="#{bindings.Attrib1.hints.label}">
  <af:panelGroupLayout layout="horizontal" id="pgl7">
    <af:inputListOfValues id="attrib1Id"
      popupTitle="Search and Select: #{bindings.Attrib1.hints.label}"
      value="#{bindings.Attrib1.inputValue}"
      model="#{bindings.Attrib1.listOfValuesModel}"
      required="#{bindings.Attrib1.hints.mandatory}"
      columns="#{bindings.Attrib1.hints.displayWidth}"
      shortDesc="#{bindings.Attrib1.hints.tooltip}"
      autoSubmit="true">
      <f:validator binding="#{bindings.Attrib1.validator}"/>
      <af:convertNumber groupingUsed="false"
        pattern="#{bindings.Attrib1.format}"/>
    </af:inputListOfValues>
    <af:inputText value="#{bindings.Attrib1Name.inputValue}" id="ot9"
      columns="50" partialTriggers="attrib1Id" disabled="true"/>
  </af:panelGroupLayout>
</af:panelLabelAndMessage>




NOTE: if you have a required field mark the inputlistof values as required and simple and the panelLabelAndMessage as showRequired true.



1) Click this button to map to sql
2) This is the alias field that needs a unique value mentioned above.
3) The sql statement you wish to use is inserted here.
4) This is the mapping of the expression you wish to use (field in the mapped vo).

Friday, March 11, 2011

Dynamic datasource selection/ swapping ADF

Just did this for a quick poc so pleased adapt this code as is is not production suitable.

1) Create a factory

package za.poc;
import oracle.jbo.server.DatabaseTransactionFactory;

public class CustomDatabaseTransactionFactory extends
 DatabaseTransactionFactory {
    public CustomDatabaseTransactionFactory() {
        super();
    }
    
    public oracle.jbo.server.DBTransactionImpl2 create() {
      return new CustomTransaction();
    }
}


2) Create new Transaction class
package za.poc;

import oracle.adf.share.ADFContext;
import oracle.jbo.server.DBTransactionImpl2;

public class CustomTransaction extends DBTransactionImpl2 {
  public CustomTransaction() {
    super();
  }

  public void connectToDataSource(java.util.Hashtable p1, java.lang.String p2, java.lang.String p3,
    java.lang.String p4, boolean p5) {
    String userName = (String)ADFContext.getCurrent()
      .getSessionScope().get("USER_NAME");
      if (userName != null) {
          if ("test".equalsIgnoreCase(userName) ) {
            p2 = "jdbc/testDS";
          }
      }
       super.connectToDataSource(p1, p2, p3, p4, p5);
  }
}

3) Override AM TransactionFactory property to your newly created class.

4) set the session value on login.
session.setAttribute("USER_NAME", "test");

See this blog post for an alternative (probably better)
http://jobinesh.blogspot.com/2011/04/modifying-application-modules-jdbc.html

Tuesday, March 8, 2011

Converting forms logic

ORA-00936-Missing-Expression
Make sure you havent done a search and replace through your code of IS NULL and replaced your sql code with ==.

I am really going to have to write a generator for this stuff.