Thursday 31 August 2017

Oracle JDeveloper Parameters

AddVMOption -Xms2048M
AddVMOption -Xmx2048M
AddVMOption -XX:PermSize=768m
AddVMOption -XX:MaxPermSize=1024m
AddVMOption -DMainWindow.MemoryMonitorOn=true

This is another usual error encountered when deploying projects to embedded WebLogic Server in JDeveloper 11g. I have done my searching to google and lost myself on the many lengthy discussion. 
To make the life of others easy, here is the solution that I have got: 

Change the PermGen size for your internal WLS in 
\jdeveloper\system\system11.1.1.0.31.51.88\DefaultDomain\bin\setDomainEnv.cmd
Find the line with MEM_MAX_PERM_SIZE.
set MEM_MAX_PERM_SIZE=-XX:MaxPermSize=128m
Increase it to 256m or 512m. 


This post is based on JDev 11g R2 (but same applies for other JDev 11g versions).

Its fairly easy to enable JDeveloper 11g Heap Memory Monitor, add this property to jdev.conf file (located under JDEV_INSTALL/jdev/bin/ folder) and restart IDE:

AddVMOption -DMainWindow.MemoryMonitorOn=true


java parameters like
set JAVA_OPTS=%JAVA_OPTS% -Xms256m -Xmx512m -XX:+UseParallelGC
set JAVA_OPTS=%JAVA_OPTS% -XX:PermSize=256m -XX:MaxPermSize=512m

Project Properties

Here is another case which requires the change of project properties in JDeveloper: 
  • Scenario:
    • JDeveloper is used to deploy "server-setup-seed-deploy-test" target with "Run Ant Target" and it threw "java.lang.OutOfMemoryError: PermGen space" exception.[2]
  • Solution:
    • In Jdev window, right click the project file >  Project Properties > Ant > Process > Java Options:
      • -Xms512m -Xmx1024m -XX:PermSize=512m -XX:MaxPermSize=1024m
    • Note that a new JVM is launched for the Ant process and it uses the above settings.
Files that control the amount of memory afforded to the JVM for JDeveloper upon startup, relative to the jdeveloper/ide/bin/ directory, include:
  • jdev.conf
  • ide.conf
Update these files as follows:
  1. Quit JDeveloper.
  2. Edit ide.conf.
  3. Append the following
    AddVMOption -Xms256M
    AddVMOption -Xmx1024M
    
  4. Edit jdev.conf.
  5. Find the AddVMOption for the "heap size."
  6. Change the values as follows:
    AddVMOption -Xmx1024M
    AddVMOption -XX:MaxPermSize=1024M
  7. Perm gen space error in jdev

    The Perm gen space often appears in jdeveloper when you re-run a UI application without stopping the server. This error can be avoided by adding the following to the project properties JAVA OPTIONS :- Project Properties -> Run/Debug/Profile -> Default -> Edit -> Java Options -> -Xms256m -Xmx1024m -XX:PermSize=96m -XX:MaxPermSize=512m -XX:CompileThreshold=8000

Tuesday 29 August 2017

Oracle ADF page background

<af:panelstretchlayout id="pt_psl1"
inlinestyle="padding:10px;background-image:url('/oracle/ui/pattern/dynamicShell/images/back.jpg');">
</af:panelstretchlayout>
=========================================================================
<af:panelstretchlayout id="pt_psl1"
inlinestyle="padding:10px;background-image:url('#{facesContext.externalContext.requestContextPath}/oracle/ui/pattern/dynamicShell/images/back.jpg');">
</af:panelstretchlayout>
==============================================================================
and I added the image images/JDev.jpg in hte public_html folder!

Create a skin file and add bellow class

.loadBg {
    background-image: url("../images/bgimg.jpg");
    background-repeat: no-repeat;
    background-position: center center;
    background-attachment: fixed;
    max-width: 100%;
    height: auto;
    display: block;
    background-color: #ee3a23;
}
==============================================================================
and add that class reference to your page

<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1" xmlns:af="http://xmlns.oracle.com/adf/faces/rich"
          xmlns:f="http://java.sun.com/jsf/core">
    <af:panelGroupLayout id="pgl13" layout="scroll" styleClass="loadBg">
        <ur conntent >
    </af:panelGroupLayout>
</jsp:root>

Thnaks
PraveenM90
=======================================================
inlineStyle='background-image:url("image.JPG");

<af:gridRow marginTop="5px" height="auto" id="gr1">
                            <af:gridCell marginStart="5px" width="90%" id="gc1"
                                         inlineStyle='background-image:url("image.JPG");width:200px'>
                                <af:outputText value="#{item.AssetId}" id="ot1"/>
                            </af:gridCell>
                            <af:gridCell marginStart="5px" width="50%" marginEnd="5px" id="gc2"
                                         inlineStyle='background-image:url("image.JPG");'>
                                <af:outputText value="#{item.AssetType}" id="ot2"/>
                            </af:gridCell>
                        </af:gridRow>
==========================================================================
<img src="<%=renderRequest.getContextPath()%>/images/loading.gif"

worked for me.
Image was inside the war in /images/loading.gif
==========================================================================
Hi,

I had the same problem. my fault was , that i didn't imported a taglib:
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
and then
<img src="<%=request.getContextPath()%>/img/image.jpg"/>
worked.

I hope this helps.
==========================================================================
Steps:
1.Add images folder to docroot (docroot\images).
2. Access the image in JSP using the following.
<img src="<%=request.getContextPath()%>/images/abc.png"/>

Done!. Good Luck!
==========================================================================

Oracle ADF JavaScript


<f:view>
    <af:document title="untitled1.jspx" id="d1">
       <af:clientListener method="GetClock" type="load"/>
       <f:facet name="metaContainer">
            <af:resource type="javascript" source="resources/js/timer.js"/> 
       </f:facet>
   <af:messages id="m1"/>
   <af:form id="f1">

JavaScript file: timer.js

function GetClock() {
    var today = new Date();
    tday = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
    tmonth = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
    smonth = new Array("JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC");
    var d = new Date();
    var nday = d.getDay(), nmonth = d.getMonth(), ndate = d.getDate(), nyear = d.getFullYear();
    var nhour = d.getHours(), nmin = d.getMinutes(), nsec = d.getSeconds(), ap;

    if (nhour == 0) {
        ap = " AM";
        nhour = 12;
    }
    else if (nhour < 12) {
        ap = " AM";
    }
    else if (nhour == 12) {
        ap = " PM";
    }
    else if (nhour > 12) {
        ap = " PM";
        nhour -= 12;
    }

    if (nmin <= 9)
        nmin = "0" + nmin;
    if (nsec <= 9)
        nsec = "0" + nsec;

    var dateandTimeStr = "" + tday[nday] + ", " + tmonth[nmonth] + " " + ndate + ", " + nyear + " " + nhour + ":" + nmin + ":" + nsec + ap + "";
    var dateandTimeStr1 = "" + (nmonth + 1) + "/" + ndate + "/" + nyear + " " + nhour + ":" + nmin + ap + "";

    document.getElementById('DateStr').innerHTML = "Hello " + dateandTimeStr;
    t = setTimeout('GetClock()', 500);
}

 <af:outputText id="DateStr" value="DateStr1" clientComponent="true"/>

Monday 28 August 2017

Oracle ADF PageFlowScope Variables

Oracle ADF - Storing temporary values in PageFlowScope created at Run time
Greetings,

Some time you need to store temporary values on the page like a global variable. Oracle ADF provides various bean scopes like pageflow scope, session scope etc etc we can definitely use them

But can you create pageflow scope at run-time? the answer is YES


Lets explore a simple example

Example:
When you press the button on the screen it will count and display how many times you have pressed the button and counter will be different for each browser window or tab


Technical detail:
·                     We have an input text component and its value using a page flow scope bean attribute called 'counter'
·                     We got a button on screen which is calling an action listener method doCounting()

How Example works:
·                     When we pressed the button on screen it creates a pageflow scope bean on runtime called 'myCounter' and increment this value on every button pressed.
·                     The value of myCounter then assigned to pageFlowscope attribute in a managed bean called 'counter' which is visible on screen as output text

Following is the code on button with other helping methods
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59

//Method on the button
 public void doCounting(ActionEvent actionEvent) {
    
     Number value = (Number)getPageFlowScopeValue("myCounter");
     if (value.intValue() >= 0) {
         setPageFlowScopeValue("myCounter", value.intValue() + 1);
     }
      
     setManagedBeanValue("pageFlowScope.pFlowBean.counter",
getPageFlowScopeValue("myCounter"));

 }
 //Method to set the value of page flow scope created on runtime
 public void setPageFlowScopeValue(String name, Number value) {
     ADFContext adfCtx = ADFContext.getCurrent();
     Map pageFlowScope = adfCtx.getPageFlowScope();
     pageFlowScope.put(name, value);
 }

//method to get the value of page flow scope created on runtime
 public Object getPageFlowScopeValue(String name) {
     ADFContext adfCtx = ADFContext.getCurrent();
     Map pageFlowScope = adfCtx.getPageFlowScope();
     Object val = pageFlowScope.get(name);
  
     if (val == null)
         return 0;
     else
         return val;
 }

//Methods used to get and set the values in a Managed bean
 public Object getManagedBeanValue(String beanName) {
     StringBuffer buff = new StringBuffer("#{");
     buff.append(beanName);
     buff.append("}");
     return resolveExpression(buff.toString());
 }

 public Object resolveExpression(String expression) {
     FacesContext facesContext = FacesContext.getCurrentInstance();
     Application app = facesContext.getApplication();
     ExpressionFactory elFactory = app.getExpressionFactory();
     ELContext elContext = facesContext.getELContext();
     ValueExpression valueExp =
elFactory.createValueExpression(elContext, expression, Object.class);
     return valueExp.getValue(elContext);
 }


 public void setManagedBeanValue(String beanName, Object newValue) {
     StringBuffer buff = new StringBuffer("#{");
     buff.append(beanName);
     buff.append("}");
     setExpressionValue(buff.toString(), newValue);
 }

 public static void setExpressionValue(String expression, Object newValue) {
     FacesContext facesContext = FacesContext.getCurrentInstance();
     Application app = facesContext.getApplication();
     ExpressionFactory elFactory = app.getExpressionFactory();
     ELContext elContext = facesContext.getELContext();
     ValueExpression valueExp =
elFactory.createValueExpression(elContext, expression, Object.class);
   
     Class bindClass = valueExp.getType(elContext);
     if (bindClass.isPrimitive() || bindClass.isInstance(newValue)) {
         valueExp.setValue(elContext, newValue);
     }
 }

Download the sample code

Note: There are many ways to do the same task one technique is demonstrated by Andrejus click here
===============================
hi i have httpsession how i can get current user from session ?
public void afterPhase(PhaseEvent phaseEvent) {
FacesContext fc = phaseEvent.getFacesContext();
HttpSession session = (HttpSession) fc.getExternalContext().getSession(true);
UserData u = (UserData)session.getAttribute("user");
boolean loginPage = fc.getViewRoot().getViewId().lastIndexOf("login") > -1 ? true :false;
if (!loginPage && u == null){
NavigationHandler nh = fc.getApplication().getNavigationHandler();
nh.handleNavigation(fc, null, "logout");
}
}
===========================

down vote
accept
Yes its possible
If the bean doesnot exits then put it in session first
FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put(key,object);
And to use the bean on xhtml page use
<h:outputText value="#{sessionScope.key}" />
=========================================




 Yes its possible

If the bean doesnot exits then put it in session first

FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put(key,object);
And to use the bean on xhtml page use

<h:outputText value="#{sessionScope.key}" /> 
====================================================

Is it possible to display the current date (today's) in JSF without using a backing bean?

I have the following code snippet , but it didn't work out.

<div class="leftSide">Today's date #{currentDate}</div>
or

<f:facet name="header">  
<h:outputText value="Today's date" />  
</f:facet>
<h:outputText value="#currentDate">
    <f:convertDateTime pattern="MM/dd/yyyy" type="date" />
==================================

You could register an instance of java.util.Date as a request scoped bean in faces-config.xml.

<managed-bean>
    <managed-bean-name>currentDate</managed-bean-name>
    <managed-bean-class>java.util.Date</managed-bean-class>
    <managed-bean-scope>request</managed-bean-scope>
</managed-bean>
This way it's available as #{currentDate} without the need for a custom backing bean class.

Update: the JSF utility library OmniFaces has such a bean already registered as #{now}. So if you happen to use OmniFaces already, you can just make use of it directly.

<h:outputText value="#{now}">
    <f:convertDateTime pattern="MM/dd/yyyy" type="date" />
</h:outputText>
===================================

</h:outputText>