Thursday, November 15, 2012

Unable to reserve the .lok file for Integrated WebLogic Server (IntegratedWebLogicServer).

Oracle JDeveloper 11.1.2.1
Windows 7 Enterprise



When JDeveloper closes unexpected without shutting down IntegratedWebLogicServer, trying to start IntegratedWLS next time, gives "Unable to reserve the .lok file for Integrated WebLogic Server (IntegratedWebLogicServer)."

First Solution is to kill the process in Task Manager. Open Task Manager & check for java.exe process for higher memory consumption. End the process.

IF above does not help then go to C:\Users\RRA\AppData\Roaming\JDeveloper\system11.1.2.1.38.60.81\DefaultDomain . Delete the edit.lok file.




Saturday, October 20, 2012

How to make Default Command working in JSFF Page in AF:Region in JDeveloper 11g

Oracle JDeveloper 11.1.2.1
ADF Faces Rich Component


This post explain how can you set command button to default command in jsff page exposed in af:Region.

While you use jspx pages, af:form component has property DefaultCommand, when set to id of any af:commandButton, invokes the associated action on pressing Enter Key.

However, when you are using page fragment (jsff) page & exposed in region, using this property from parent page would not give right ID of command button bz of surrounding containers.

So, alternative is to use javascript in jsff page in one of the UI component, when the ENTER button is pressed inside this component, a button action is invoked programmatically.

For Example, jsff page has one af:inputText & one af:commandButton to press:

 <af:panelFormLayout id="pfl1" labelWidth="250">  
   
  <af:resource type="javascript">   
     function onEnterKey(inputevent){   
       if(inputevent.getKeyCode() = AdfKeyStroke.ENTER_KEY {   
        var inputTextId = inputevent.getSource();  
   
         //If inputText & Button reside in same container   
         var reportbtn = inputTextId.findComponent('cb2');           
   
         AdfActionEvent.queue(reportbtn);  
   
         inputevent.cancel(); //stop sending event to server  
   
        }  
   
      }  
   
   </af:resource>  
   
   <af:inputText label="Enter Year" id="it1" maximumLength="4" showRequired="true"   
               requiredMessageDetail="Please Enter Year">   
  
        <af:clientListener method="onEnterKey" type="keyUp"/>   
   </af:inputText>  
   
   <af:panelGroupLayout id="pgl2" layout="horizontal" inlineStyle="width:326px;">   
       <af:commandButton text="Show Report" id="cb2" clientComponent="true"/>     
   </af:panelGroupLayout>  
   
 </af:panelFormLayout>  


Please note that af:clientListener tag for inputText & clientComponent=true property of commandButton should present to work with javascript.

Monday, October 15, 2012

Programmatically Showing Popup In JDeveloper 11g

Oracle JDeveloper 11.1.2.1
ADF Rich Components
ADF Business Components

To show af:popup programmatically in adf, you can add script in Managed Bean by ExtendedRenderKitService class.

 import javax.faces.context.FacesContext;  
 import org.apache.myfaces.trinidad.render.ExtendedRenderKitService;  
 import org.apache.myfaces.trinidad.util.Service;  
 public void showPopup (String popupId){  
        FacesContext context = FacesContext.getCurrentInstance();  
        ExtendedRenderKitService extendedRenderKitSrvc =  
        Service.getRenderKitService(context, ExtendedRenderKitService.class);  
        extendedRenderKitSrvc.addScript(context, "AdfPage.PAGE.findComponent('" + popupId + "').show();");  
     }  

Saturday, October 13, 2012

How To Logout From ADF Application Programmatically In JDeveloper 11g ?

Oracle JDeveloper 11.1.1.3
ADF Faces Rich Components
ADF Business Components

As you might know already, from logging out to ADF Application you can set 'Destination' property of af:goLink to your desired page.

 <af:goLink text="Logout" id="gl2"   
     destination="/adfAuthentication?logout=true&amp;end_url=/faces/login.jspx"  
     accessKey="L" shortDesc="Logs-out current user session."/>  

The Logout can also handled programmatically by server side code in managed-bean.
To do so, af:commandLink can be used something like below.

 <af:commandLink text="Logout" id="cl2"   
   action="#{dataentry_bean.onLogout}"  
   immediate="true"  
   shortDesc="Logs-out current user session."  
   accessKey="L"/>  
Setting Immediate=true is optional, and it is for bypassing any validation on page.


The managed bean code -

 import javax.faces.context.ExternalContext;  
 import javax.faces.context.FacesContext;  
 import javax.servlet.http.HttpServletRequest;  
 import javax.servlet.http.HttpSession;  
 import weblogic.servlet.security.ServletAuthentication;  
   
   public String onLogout(){  
     FacesContext fctx = FacesContext.getCurrentInstance();  
     ExternalContext ectx = fctx.getExternalContext();  
     String url = ectx.getRequestContextPath() + "/adfAuthentication?logout=true&end_url=/faces/login.jspx";  
       
     HttpSession session = (HttpSession)ectx.getSession(false);  
     session.invalidate();  
       
     HttpServletRequest request = (HttpServletRequest)ectx.getRequest();  
     ServletAuthentication.logout(request);  
     ServletAuthentication.invalidateAll(request);  
     ServletAuthentication.killCookie(request);  
       
     try{  
       ectx.redirect(url);  
     }  
     catch(Exception e){  
       e.printStackTrace();  
     }  
     fctx.responseComplete();  
       
     return null;  
   }  

Wednesday, July 11, 2012

No Cache For JSF/JSPX Page To Avoid Use OF Browser Back Button In JDeveloper 11g / Use OF No-Cache With JSF LifeCycle

Oracle JDeveloper 11.1.1.3
Internet Explorer-8
FireFox-13


In one of my ADF application, I wanted to discourage the use of browser back button. But users never mind to pinpoint the security gaps.
Not finding any proper solution for disabling back button, I decided to expire the cache of page which back button uses to show the saved page.Well, you can't trust on browser, so this technique is not guaranteed to fill gap in security.

The simplest approrach for JSPX page is to add a Scriptlet under <jsp:root> tag with header information.
In Structure window under <jsp:root> tag drag a jsp:scriptlet & write the header information for no-cache.
You can get <scriptlet> from Component Palette & switching to "JSP" selection.
Write header information under <jsp:scriptlet> tag.

















You can also write header info by switching jspx page code editor something like this -
 <?xml version='1.0' encoding='UTF-8'?>  
 <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"  
      xmlns:f="http://java.sun.com/jsf/core"  
      xmlns:h="http://java.sun.com/jsf/html"  
      xmlns:af="http://xmlns.oracle.com/adf/faces/rich">  
  <jsp:directive.page contentType="text/html;charset=UTF-8"/>  
  <jsp:scriptlet>  
   response.setHeader("Pragma", "no-cache");  
   response.setHeader("Cache-Control", "no-cache, no-store, max-age=0, must-revalidate");  
   response.setDateHeader("Expires", 0);   
   response.addHeader("Cache-Control","post-check=0, pre-check=0"); 
  </jsp:scriptlet>  


Using above method was giving "500 Internal Server Error".  I did not investigated the reason for error. May be this error is context based for my project source files.

The other way was to use same header information with simple JSF Page Lifecycle.
I created a java class & wired it with managed bean with request scope since I wanted no-cache for
every single request of page. Select <f:view> in Structure Panel from JSPX Page. Add Phase Listener method to fire in 'BeforePhase' for page lifecycle.

  

Write header information in beforePhase listener method.



Sunday, July 8, 2012

Some Useful All Time Handy Backing Bean Code In JDeveloper

Some handy codes for backing bean for my record. I am following biemond's blogs for this -
http://biemond.blogspot.com/2009/03/some-handy-code-for-backing-beans-adf.html
http://biemond.blogspot.com/2011/01/some-handy-code-for-your-managed-beans.html

Part 1 of 2009 starts here -

   1:  // print the roles of the current user  
   2:  for ( String role : ADFContext.getCurrent().getSecurityContext().getUserRoles() ) {  
   3:     System.out.println("role "+role);  
   4:  }  
   5:    
   6:    
   7:  // get the ADF security context and test if the user has the role users         
   8:  SecurityContext sec = ADFContext.getCurrent().getSecurityContext();  
   9:  if ( sec.isUserInRole("users") ) {  
  10:  }  
  11:  // is the user valid  
  12:  public boolean isAuthenticated() {  
  13:   return ADFContext.getCurrent().getSecurityContext().isAuthenticated();  
  14:  }  
  15:  // return the user  
  16:  public String getCurrentUser() {  
  17:   return ADFContext.getCurrent().getSecurityContext().getUserName();  
  18:  }  
  19:    
  20:    
  21:  // get the binding container  
  22:  BindingContainer bindings = BindingContext.getCurrent().getCurrentBindingsEntry();  
  23:    
  24:  // get an ADF attributevalue from AttributeBinding in ADF page definitions  
  25:  AttributeBinding attr = (AttributeBinding)bindings.getControlBinding("test");  
  26:  attr.setInputValue("test");  
  27:    
  28:  // get an Action or MethodAction by OperationBinding in PageDef 
  29:  OperationBinding method = bindings.getOperationBinding("methodAction");  
  30:  method.execute();  
  31:  List errors = method.getErrors();  
  32:  
  33:  method = bindings.getOperationBinding("methodAction");  
  34:  Map paramsMap = method.getParamsMap();  
  35:  paramsMap.put("param","value")  ;   //putting method param value & executing       
  36:  method.execute();  
  37:    
  38:    
  39:  // Get the data from an ADF tree binding for AF:Table or AF:Tree
  40:  DCBindingContainer dcBindings = (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();  
  41:    
  42:  FacesCtrlHierBinding treeData = (FacesCtrlHierBinding)dcBindings.getControlBinding("tree");  
  43:  Row[] rows = treeData.getAllRowsInRange();  
  44:    
  45:  // Get a attribute value of the current row of iterator  
  46:  DCIteratorBinding iterBind= (DCIteratorBinding)dcBindings.get("testIterator");  
  47:  String attribute = (String)iterBind.getCurrentRow().getAttribute("field1");  
  48:    
  49:  // Get the error  
  50:  String error = iterBind.getError().getMessage();  
  51:    
  52:    
  53:  // refresh the iterator  
  54:  dcBindings.refreshControl();  
  55:  iterBind.executeQuery();  
  56:  iterBind.refresh(DCIteratorBinding.RANGESIZE_UNLIMITED);  
  57:    
  58:  // Get all the rows of a iterator  
  59:  Row[] rows = iterBind.getAllRowsInRange();  
  60:  TestData dataRow = null;  
  61:  for (Row row : rows) {  
  62:    dataRow = (TestData)((DCDataRow)row).getDataProvider();  
  63:  }  
  64:    
  65:  // Get the current row of a iterator , a different way  
  66:  FacesContext ctx = FacesContext.getCurrentInstance();  
  67:  ExpressionFactory ef = ctx.getApplication().getExpressionFactory();  
  68:  ValueExpression ve = ef.createValueExpression(ctx.getELContext(), "#{bindings.testIter.currentRow.dataProvider}", TestHead.class);  
  69:  TestHead test = (TestHead)ve.getValue(ctx.getELContext());  
  70:    
  71:  // Get a session bean  
  72:  FacesContext ctx = FacesContext.getCurrentInstance();  
  73:  ExpressionFactory ef = ctx.getApplication().getExpressionFactory();  
  74:  ValueExpression ve = ef.createValueExpression(ctx.getELContext(), "#{testSessionBean}", TestSession.class);  
  75:  TestSession test = (TestSession)ve.getValue(ctx.getELContext());  
  76:    
  77:  // main jsf page   
  78:  DCBindingContainer dc = (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();   
  79:  // taskflow binding   
  80:  DCTaskFlowBinding tf = (DCTaskFlowBinding)dc.findExecutableBinding("dynamicRegion1");  
  81:  // pagedef of a page fragment   
  82:  JUFormBinding form = (JUFormBinding) tf.findExecutableBinding("regions_employee_regionPageDef");  
  83:  // handle to  binding container of the region.  
  84:  DCBindingContainer dcRegion   = form;  
  85:    
  86:    
  87:    
  88:  // return a methodexpression like a control flow case action or ADF pagedef action  
  89:  private MethodExpression getMethodExpression(String name) {  
  90:   Class [] argtypes = new Class[1];  
  91:   argtypes[0] = ActionEvent.class;  
  92:   FacesContext facesCtx = FacesContext.getCurrentInstance();  
  93:   Application app = facesCtx.getApplication();  
  94:   ExpressionFactory elFactory = app.getExpressionFactory();  
  95:   ELContext elContext = facesCtx.getELContext();  
  96:   return elFactory.createMethodExpression(elContext,name,null,argtypes);  
  97:  }  
  98:    
  99:  //  
 100:  RichCommandMenuItem menuPage1 = new RichCommandMenuItem();  
 101:  menuPage1.setId("page1");  
 102:  menuPage1.setText("Page 1");  
 103:  menuPage1.setActionExpression(getMethodExpression("page1"));  
 104:    
 105:  RichCommandButton button = new RichCommandButton();  
 106:  button.setValueExpression("disabled",getValueExpression("#{!bindings."+item+".enabled}"));  
 107:  button.setId(item);  
 108:  button.setText(item);  
 109:  MethodExpression me = getMethodExpression("#{bindings."+item+".execute}");  
 110:  button.addActionListener(new MethodExpressionActionListener(me));  
 111:  footer.getChildren().add(button);  
 112:    
 113:    
 114:  // get a value  
 115:  private ValueExpression getValueExpression(String name) {  
 116:   FacesContext facesCtx = FacesContext.getCurrentInstance();  
 117:   Application app = facesCtx.getApplication();  
 118:   ExpressionFactory elFactory = app.getExpressionFactory();  
 119:   ELContext elContext = facesCtx.getELContext();  
 120:   return  elFactory.createValueExpression(elContext, name, Object.class);  
 121:  }  
 122:  // an example how to use this  
 123:  RichInputText input = new RichInputText();  
 124:  input.setValueExpression("value",getValueExpression("#{bindings."+item+".inputValue}"));  
 125:  input.setValueExpression("label",getValueExpression("#{bindings."+item+".hints.label}"));  
 126:  input.setId(item);  
 127:  panelForm.getChildren().add(input);  
 128:    
 129:    
 130:    
 131:  // catch an exception and show it in the jsf page  
 132:  catch(Exception e) {  
 133:   FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, e.getMessage(), "");  
 134:   FacesContext.getCurrentInstance().addMessage(null, msg);  
 135:  }  
 136:    
 137:                      
 138:  FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_WARN, msgHead , msgDetail);  
 139:  facesContext.addMessage(uiComponent.getClientId(facesContext), msg);                                                                     
 140:    
 141:    
 142:  // reset all the child uicomponents  
 143:  private void resetValueInputItems(AdfFacesContext adfFacesContext,  
 144:                                   UIComponent component){  
 145:     List<UIComponent> items = component.getChildren();  
 146:     for ( UIComponent item : items ) {  
 147:          
 148:         resetValueInputItems(adfFacesContext,item);  
 149:          
 150:         if ( item instanceof RichInputText  ) {  
 151:             RichInputText input = (RichInputText)item;  
 152:             if ( !input.isDisabled() ) {  
 153:                 input.resetValue() ;  
 154:                 adfFacesContext.addPartialTarget(input);  
 155:             };  
 156:         } else if ( item instanceof RichInputDate ) {  
 157:             RichInputDate input = (RichInputDate)item;  
 158:             if ( !input.isDisabled() ) {  
 159:                 input.resetValue() ;  
 160:                 adfFacesContext.addPartialTarget(input);  
 161:             };  
 162:         }  
 163:     }  
 164:  }  
 165:      
 166:  // redirect to a other url  
 167:  ExternalContext ectx = FacesContext.getCurrentInstance().getExternalContext();  
 168:  HttpServletResponse response = (HttpServletResponse)ectx.getResponse();  
 169:  String url = ectx.getRequestContextPath()+"/adfAuthentication?logout=true&end_url=/faces/start.jspx";  
 170:    
 171:  try {  
 172:    response.sendRedirect(url);  
 173:  } catch (Exception ex) {  
 174:    ex.printStackTrace();  
 175:  }  
 176:    
 177:  // PPR refresh a jsf component  
 178:  AdfFacesContext.getCurrentInstance().addPartialTarget(UIComponent);  
 179:    
 180:    
 181:  // find a jsf component      
 182:  private UIComponent getUIComponent(String name) {  
 183:   FacesContext facesCtx = FacesContext.getCurrentInstance();  
 184:   return facesCtx.getViewRoot().findComponent(name) ;  
 185:  }  
 186:    
 187:    
 188:  // get the adf bc application module  
 189:  private OEServiceImpl getAm(){  
 190:     FacesContext fc = FacesContext.getCurrentInstance();  
 191:     Application app = fc.getApplication();  
 192:     ExpressionFactory elFactory = app.getExpressionFactory();  
 193:     ELContext elContext = fc.getELContext();  
 194:     ValueExpression valueExp =  
 195:     elFactory.createValueExpression(elContext, "#{data.OEServiceDataControl.dataProvider}",  
 196:                                         Object.class);  
 197:     return   (OEServiceImpl)valueExp.getValue(elContext);  
 198:  }  
 199:    
 200:    
 201:  // change the locale  
 202:  Locale newLocale = new Locale(this.language);  
 203:  FacesContext context = FacesContext.getCurrentInstance();  
 204:  context.getViewRoot().setLocale(newLocale);  
 205:    
 206:    
 207:  // get the stacktrace of a not handled exception  
 208:  private ControllerContext cc = ControllerContext.getInstance();  
 209:    
 210:  public String getStacktrace() {  
 211:     if ( cc.getCurrentViewPort().getExceptionData()!=null ) {  
 212:         StringWriter sw = new StringWriter();  
 213:         PrintWriter pw = new PrintWriter(sw);  
 214:         cc.getCurrentViewPort().getExceptionData().printStackTrace(pw);  
 215:         return sw.toString();             
 216:     }  
 217:     return null;  
 218:  }  
 219:    
 220:    
 221:  // get the selected rows from a table component  
 222:  RowKeySet selection = resultTable.getSelectedRowKeys();  
 223:  Object[] keys = selection.toArray();  
 224:  List<Long> receivers = new ArrayList<Long>(keys.length);  
 225:  for ( Object key : keys ) {  
 226:    User user = modelFriends.get((Integer)key);  
 227:  }  
 228:    
 229:  // get  selected Rows of a table 2  
 230:  for (Object facesRowKey : table.getSelectedRowKeys()) {  
 231:   table.setRowKey(facesRowKey);  
 232:   Object o = table.getRowData();  
 233:   JUCtrlHierNodeBinding rowData = (JUCtrlHierNodeBinding)o;  
 234:   Row row = rowData.getRow();  
 235:   Test testRow = (Test)((DCDataRow)row).getDataProvider() ;  
 236:  }  
 
The 2nd Part of 2011 follows from here - Starting with FacesContext class, with this class you can use to find a JSF Component, change the Locale, get the ELContext, Add a message to your view and get the ExternalContext.
   1:  // FacesContext 
   2:  FacesContext facesCtx = FacesContext.getCurrentInstance();  
   3:   
   4:  // find UIComponent
   5:  UIComponent input = facesCtx.getViewRoot().findComponent("f1"); 
   6:   
   7:  // change the locale  
   8:  facesCtx.getViewRoot().setLocale( Locale.ENGLISH);   
   9:   
  10:  // el expression
  11:  Application app = facesCtx.getApplication();  
  12:  ExpressionFactory elFactory = app.getExpressionFactory();  
  13:  ELContext elContext = facesCtx.getELContext();   
  14:  ValueExpression valueExp = elFactory.createValueExpression(elContext,"{xxxx}", Object.class); 
  15:  Object result = valueExp.getValue(elContext); 
  16:   
  17:  // add a message
  18:  FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_WARN,"header","detail");  
  19:  facesCtx.addMessage(input.getClientId(facesCtx), msg);  
  20:   
  21:  // ExternalContext
  22:  ExternalContext ectx = facesCtx.getExternalContext();


The ExternalContext class, with this you can retrieve all the java init & context (web.xml) parameters, the Request & Session parameters and your web application url.
   1:  // ExternalContext
   2:  ExternalContext ectx = facesCtx.getExternalContext();   
   3:   
   4:  // all the java init parameters
   5:  Map<String, Object> initParamsVar = ectx.getInitParameterMap();  
   6:     
   7:  Map<String, String> requestParamsVar = ectx.getRequestParameterMap();
   8:  Map<String, Object> sessionParamsVar = ectx.getSessionMap();
   9:   
  10:  // web application context root
  11:  String contextPath = ectx.getRequestContextPat();


AdfFacesContext class, you can use this class for Partial Page Rendering ( PPR), get the PageFlowScope and ViewScope variables
   1:  // AdfFacesContext
   2:  AdfFacesContext adfFacesCtx = AdfFacesContext.getCurrentInstance();
   3:   
   4:  // PPR
   5:  adfFacesCtx.addPartialTarget(input);  
   6:   
   7:  // get the PageFlowScope Params
   8:  Map<String, Object> scopePageFlowScopeVar= adfFacesCtx.getPageFlowScope(); 
   9:   
  10:  // get the viewScope Params
  11:  Map<String, Object> scopeViewScopeVar= adfFacesCtx.getViewScope();


ADFContext class, with this you can get all the memory scopes variables even the application scope variables, ELContext and the SecurityContext.
   1:  // ADFContext
   2:  ADFContext adfCtx =  ADFContext.getCurrent(); 
   3:   
   4:  // Get the scope variables
   5:  Map<String, Object> applicationVar2   = adfCtx.getApplicationScope();
   6:  Map<String, Object> pageParamsVar2    = adfCtx.getPageFlowScope();  
   7:  Map<String, String> requestParamsVar2 = adfCtx.getRequestScope();
   8:  Map<String, Object> sessionParamsVar2 = adfCtx.getSessionScope(); 
   9:   
  10:  // el expression
  11:  ELContext elContext2 = adfCtx.getELContext();
  12:  ExpressionFactory elFactory2 = adfCtx.getExpressionFactory();
  13:  ValueExpression valueExp2 = elFactory2.createValueExpression(elContext2,"#{xxxx}", Object.class);
  14:  Object result2 = valueExp2.getValue(elContext2); 
  15:   
  16:  // Security
  17:  SecurityContext secCntx = adfCtx.getSecurityContext();


SecurityContext class, retrieve the current user and its roles.
   1:  // Security
   2:  SecurityContext secCntx = adfCtx.getSecurityContext();
   3:  String user             = secCntx.getUserName();  
   4:  String[] roles          = secCntx.getUserRoles();  


BindingContext, BindingContainer and DCBindingContainer class. These classes are well known when you want to retrieve the ADF pagedef objects.
   1:  BindingContext bc           = BindingContext.getCurrent(); 
   2:  BindingContainer bcon       = bc.getCurrentBindingsEntry();
   3:   
   4:  List<AttributeBinding> attr = bcon.getAttributeBindings();
   5:  List<OperationBinding> oper = bcon.getOperationBindings();
   6:  List<ControlBinding>   ctrl = bcon.getControlBindings(); 
   7:   
   8:  DCBindingContainer    dcbcon = (DCBindingContainer) bc.getCurrentBindingsEntry();   
   9:   
  10:  List<AttributeBinding> attr2 = dcbcon.getAttributeBindings();
  11:  List<OperationBinding> oper2 = dcbcon.getOperationBindings();
  12:  List<ControlBinding>   ctrl2 = dcbcon.getControlBindings();
  13:  List                   iters = dcbcon.getIterBindingList();
  14:  List                   exec  = dcbcon.getExecutableBindings();


The last class is ControllerContext, which you can use to retrieve the exceptions
   1:  ControllerContext cc = ControllerContext.getInstance();  
   2:   
   3:  // get the exception
   4:  Exception exp = cc.getCurrentViewPort().getExceptionData();

Saturday, July 7, 2012

Use Of AF:Switcher with ViewScope Variable In JDeveloper 11g

JDeveloper 11.1.1.3
ADF Faces RC.

The af:switcher component is able to show facet component dynamically. It will render the facet matching "FacetName" property. Its a server side component with no client side representation. Refer here for more info http://jdevadf.oracle.com/adf-richclient-demo/docs/tagdoc/af_switcher.html .
The af:setPropertyListener is declartive operation component in ADF for assigning value when certain event fires. Refer more about propertyListener here http://jdevadf.oracle.com/adf-richclient-demo/docs/tagdoc/af_setPropertyListener.html .

  1. Open your adfc-config.xml file for unbounded task flow.
  2. Select view activity & in property inspector, under Page Parameters click + icon.
  3. Write in From Value=First & To Value=#{viewScope.paramVal}. When the view activity/jspx page will run framework will create a viewScope variable "paramVal" if not found & assign the "First" value to it. Your view activity would show warning message stating "Reference Not Found..." in design time. Just ignore it.



  4.    Drag the af:switcher component from component palette. Right click to select 'insert inside
         swithcer' & then "facet". Repeat twice for 2 facet named "First" & "Second" respectively. 
         Drag af:message component inside both facets.
  5.    You can set "DefaultFacet" property to any facet you want, in case, if "FacetName" is not
         defined or returns Null , DefaultFacet property will be used.
  6.    Select af:switcher in Structure window & write FacetName= #{viewScope.paramVal} .Now
         when first time the page will run, First facet would be selected.
  7.    Now, drag 2 command buttons. Under each button drag af:setPropertyListener.
  8.    In the first button's propertyListener write From=First, To= #{viewScope.paramVal}
         Type=action .
  9.    In the 2nd button's propertyListener write From=Second, To= #{viewScope.paramVal},
         Type=action .
10.    Just the optional thing to do is disabling your button after clicking it.Select first button & in
         disabled property write #{viewScope.paramVal == "First"} .
11.    Do same for second button & write #{viewScope.paramVal == "Second"} .




Run the page to test. 

The above functionality can also achieved by viewScope Managed Bean instead of viewScope variable.
Sample Workspace for viewScope variable - Download
Sample Workspace for viewScope bean - Download

Note the viewScope project has java class which is not using as managed bean. This class is 
wired in managed bean project workspace.

Thursday, June 28, 2012

Visual Design Editor Fails To Render Page In JDeveloper 11g

Oracle JDeveloper 11.1.1.3
ADF-BC, ADF RC


While doing some test work, suddenly an error dialog pops-up classnotfound in IDE.
Intially the error was claiming NoClassFound AdfcConfigNode in below screenshot.



And my page look like below -












& Fusion Application Template was missing in New Application dialog.



The first thing to check 'JSP Tag Libraries' in ViewController properties.
Make sure the 'Execute Tags in JSP Visual Editor' is checked for adf components, in 'JSP Tag Libraries'
section. This did not help in restoring the visual design, I deleted IntegratedWLS Installation folder.

Unfortunately, in my case it did not work.

After deleting the IntgratedWLS folder, the error dialog pops-up again like below -



















I started comparing the exact duplicate project in other Project Source.
I compared each tab in 'Technology Scope', that was ok.
Then I checked in 'Libraries & Classpath' section. 4 entries were referencing to
missing libraries-
  1. ADF Page Flow Runtime
  2. ADF Controller Schema
  3. ADF Faces Runtime 11
  4. ADF Controlller Runtime
Removing the entries & again adding from 'Add Library' button finally restored the page in design
visual editor.




-The other way is to check broken design time references in LOG Window.
From Tool > Preferences select "JSP and HTML Visual Editor".
Tick the checkbox "Show Design Time Messages In Log". Press OK to close Preferences Dialog.






Now, when accessing the particular page, Log Window shows, what causing the page to render improperly in design mode. Based on that, further action can be taken.

-Best way is to re-initialize Java Server Faces Servlet by registering below listener in web.xml file in ViewController Project. Issue is resolved instantly in majority cases.
 <listener>  
     <listener-class>com.sun.faces.config.ConfigureListener</listener-class>  
 </listener>  

Save web.xml after modification and shuttle the listener to Selected Listeners list in Project Properties like below. Press OK to close dialog & Save All. Re-open broken page or simply click on page. Editor should try to render the page in original format.

















-Also refer to ADF Code Corner Blog - https://blogs.oracle.com/jdevotnharvest/entry/when_jdeveloper_ide_doesn_t











Wednesday, June 27, 2012

Solving Cannot Load Driver Class: com.microsoft.sqlserver.jdbc.SQLServerDriver In JDeveloper 11g

As last post discussed about how to configure JDeveloper to connect MSSQL Server, it is not enough to run your jsf pages.
To run jsf pages, Integrated WebLogic Server needs to look your sqljdbc4.jar location.
Unless you specify the jar location, you would get "Cannot Load Driver Class: com.microsoft.sqlserver.jdbc.SQLServerDriver".

Platform - Windows 7 x86 Enterprise
JDeveloper - 11.1.1.3
Weblogic - 10.3.3.0
MSSQL Server 2008 Database

You can do in 3 ways either -
1. By defining Classpath in machine.
 a. In your machine set CLASSPATH variable to pointing the saved jar location.

systemvar






























 b. Click New button in System Variables area & follow screenshot.


classpath






























 c. Click OK to close the dialogs.
 d. Now, upon starting, integratedwls will able to look jar file.


2. By defining jar location in startWeblogic.cmd in IntegratedWLS.
 a.Navigate to C:\Users\ralam\AppData\Roaming\JDeveloper\system11.1.1.3.37.56.60\DefaultDomain\bin .

 b.Open startWebLogic.cmd file & look for "set SAVE_CLASSPATH"(without quotes) or "set
    CLASSPATH" (without quotes) entry.

 c.Put in any entry your jar file location & close to save the file, like this -

startweblogic

3. The last way is to save your jar file at this location in Integrated WLS installation folder -
    C:\Users\ralam\AppData\Roaming\JDeveloper\system11.1.1.3.37.56.60\DefaultDomain\lib\


Tuesday, June 26, 2012

Connecting MS SQL Server Database From Oracle JDeveloper 11g

This post addresses connectivity issue to Microsoft SQL Server Database 2008 from JDeveloper 11g.

Platform - Win 7 x86 Enterprise
MS SQL Server 2008 Database Engine
JDeveloper 11.1.1.3

Oracle JDeveloper 11g uses JDBC 4.0 to connect with RDBMS since JDK1.6 supports JDBC4.0 & JDeveloper uses JDK 1.6 to compile all its classes.
ojdbc6.jar classes to support basic functionality for the Thin and OCI drivers when using JDK 1.6 (JSE6) with Oracle database. Additional jar files are required when you use some features. See Oracle JDBC FAQ .

Well, that was of Oracle Database. MS SQL Server provides SQLJDBC4.jar class library, which provides support for JDBC 4.0. If you dont have this jar files, you won't be able to connect to MSSql server database. You can download from Microsoft.

1. Download sqljdbc4.jar from microsoft & save in filesystem.

2. Open JDeveloper & register the library file from Tool > Manage Libraries.

3. Click 'New' button by keep selecting 'User' Node.

4. In the 'Create Library' dialog click 'Add Entry' & locate your sqljdbc4.jar file & click 'Select' .

5. Optionally, you can check 'Deployed by default'.


managelibrary

6. Click OK.

7. Now, you are ready to establish connection to MSSQL Server.

8. Make sure your sqlserver engine is running & the account you are going to use for connect, is not
    locked.

9. From Database Navigator, create a new connection.

10.Next Screenshots are self explanatory except for 'Library' field where click 'Browse' & locate the jar file
     from 'Select Library' dialog.


selectLibrary

ConnectionDialog

































11. Click Test Connection to test the connection.

Saturday, June 23, 2012

Get Current Actual Value Of AF:SelectOneChoice In ValueChangeListener

Oracle JDeveloper 11.1.1.3
ADF Faces Rich Components

Sometime your program logic needs to get Actual value of selected item in af:selectOneChoice in java code.
And SelectChoice is attached by a VO for fetching all values.
Well, when you use some basic operations in ValueChangeListener method, you notice that its returning only the index of item or old actual value.

Refer some codes -
 String selectedItem = (String)selectListBinding.getAttributeValue() ;  //old actual value  

 valueChangeEvent.getNewValue() ; //will give new index no irrespective of valuePassThru = true/false  

 valueChangeEvent.getOldValue();  //will give old index no irrespective of valuePassThru = true/false  

 Row row = (Row)selectListBinding.getSelectedValue();  
 oracle.jbo.domain.Number no= (Number)row.getAttribute("Deptid");//Old actual value  

Here is successful approach for getting Actual Selected Current Value & not the old value.

Set Autosubmit=true for SelectChoice.Goto PageDef of your jsf page.
Right click on bindings node then insert inside bindings , Generic Binding &
Attribute Values.In the dialog, choose your parent ViewObject Iterator & then attribute
on which LOV was created.

Write this code in Listener Method -
 public void SelectionListener(ValueChangeEvent valueChangeEvent)  
 {  
   BindingContainer container = BindingContext.getCurrent().getCurrentBindingsEntry();  
   valueChangeEvent.getComponent().processUpdates(FacesContext.getCurrentInstance());  
   AttributeBinding attrIdBinding = (AttributeBinding)container.getControlBinding("Deptno");  
   //Deptno is ID of an Attribute Binding in pageDef 
  
   oracle.jbo.domain.Number Id = (Number)attrIdBinding.getInputValue();  
   System.out.println("Id- " + Id);  
 }  

Error Starting Integrated WebLogic Server By ALOCKOUT.DLL

Platform - Windows 7 x32 Enterprise
JDeveloper - 11.1.1.3
Weblogic Server - 10.3.3.0

One day I had hard time when deploying my application. During intial deployment, it was successful with some warning in log windows.These were showing first time to me. After 2-3 attempt to run the application
I got the severe error continuously. I removed the IntegratedWLS installation from local directory to cleanup the environment.

Now it get worst when tried to create fresh IntegratedWLS domain instance.
The weblogic create command denied to build new domain after setting the environment successfully.

I got this error -
wlst > Failed to get environment, getEnv command (set) did not print environment as key=value lines.
wlst > Output=CreateFileandSetSecurity failed with FALSE (Expected on FAT Partitions) GLE: 3
wlst > CreateFileandSetSecurity failed with TRUE (not expected) GLE: 3

--
--
wlst > Error:  ADRS_DOMAIN_PASSWORD environment variable not set.

The Log Window warning some days back was -

CreateFileandSetSecurity failed with FALSE (Expected on FAT Partitions) GLE: 3
 
CreateFileandSetSecurity failed with TRUE (not expected) GLE: 3

The problem was Microsoft Windows Distribution Kit file, ALOCKOUT.DLL .
Basically, Alockout.dll tracks every exe file for sending bad passwords to Active Directory in domain
controller.

Removing the file & de-registring the entries from Regedit solved the problem.
Please refer how to remove Alockout.dll completely from your machine.

Fixing IE 8 Crashes For JInitiator 1.3.1.21 In Win7.

The IE 8 was crashing when launching oracle applications forms . The solution is to replace jvm.dll in JInitiator 1.3.1.21 directory with that present in Sun's JRE 1.6.

1. First download the correct version of JInitiator while launching to forms which in my case 1.3.1.21.
2. Install JRE 1.6 in your machine.
3. Rename the jvm.dll to jvm.dll.orgi in 'C:\Program Files\Oracle\JInitiator
    1.3.1.21\bin\hotspot'.
4. Move the jvm.dll from 'C:\Program Files\Java\jre6\bin\client' to 'C:\Program Files\Oracle\JInitiator
    1.3.1.21\bin\hotspot'.

OR

You can also download jvm.dll for oracle forms/report compatible with its JInitiator to IE8 from here & replace the same in JInitiator directory.

IE 8.0
Make sure the following settings are corrected in IE8.0-
Tools > Internet Options > Advanced > Uncheck "Enable third-party browser extensions"




Start Production Weblogic Server Automatically When Server Machine Starts.

In this post I am going to explain, how you can configure Production Weblogic Server Machine to start weblogic services, automatically when Administrator logs-in. The same you can achieve when only machine
starts, but you would not able to see command window when you get logged-in.

Weblogic Production Server - 10.3.3.0 (11g)
Server Machine OS - Windows Server 2008 SP1 64 Bit , Intel Xeon Processors (2)

1.  Logged into your server machine.

2.  Check the location of startWebLogic.cmd command script at 'C:\Oracle\Middleware3
     \user_projects\domains\sbgom\bin\' according to your filesystem.

3.  Anywhere in your filesystem create a .bat file & name as 'weblogicAutoStart'. Explicitly check the
     .bat extension by looking properties of file.

4.  In the batch file write start /min %SystemRoot%\system32\cmd.exe /k"C:\Oracle\Middleware3
     \user_projects\domains\sbgom\bin\startWebLogic.cmd" & Save.

5.  Note the /min parameter is only to start command window in minimized mode. You can remove if dont
     want.

6.  Now you can invoke this bat file when Admin logs-in by Windows Task Scheduler.

7.  Open the Task Scheduler from Administrative Tools in Control Panel.

8.  In the Task Scheduler right click to Create Task. In the Wizard dialog, in Name field of General Tab give
     an appropriate task name like 'WebLogicAutoStart'.

9.  In the Trigger Tab click New button. Select At Logon from dropdown & choose Specific User or 
     Group radio button.

10.In the Actions Tab, click New button & select Start A Program from dropdown in Edit Action dialog.

11.Click Browse button to locate your bat file & Press OK & OK. Its done.



How to reload whole jsf/jspx page from bean in JDeveloper 11g ?

Oracle JDeveloper 11.1.1.3
ADF Faces Rich Components


Sometimes requirement is to refresh whole jspx page from root . By simple java bean code this can achieve.
 public String refreshPage_action() {  
    FacesContext fctx = FacesContext.getCurrentInstance();  
    String pageToRefresh = fctx.getViewRoot().getViewId();   //getting View Id of current page  
    ViewHandler viewHandler = fctx.getApplication().getViewHandler();      
    UIViewRoot viewRoot = viewHandler.createView(fctx, pageToRefresh);   //ViewRoot for current page  
    viewRoot.setViewId(pageToRefresh);  
    fctx.setViewRoot(viewRoot);     //set the viewroot in facesContext to reload  
    return null;  
 }   

How to remove installed extensions in JDeveloper 11g ?

Windows 7 Enterprise
Oracle JDeveloper 11.1.1.3

From Help > Check For Updates menu, you can install new extensions either from 'Search Update Centers' or 'Install From Local File'.

When you want to remove those extensions from IDE manually, you can goto filesystem & should remove
the related .jar files. This would completely remove the extension.

The location in my machine is - C:\Oracle\Middleware11g\jdeveloper\jdev\extensions.

Alternatively, the extension can be disabled or enabled from JDeveloper.
From Tools > Preferences > Extensions the list of installed extensions can be found.
Deselect desired extension to stop loading in IDE.

In future, if same extension want to use again, this can be enabled from here.