Wednesday, November 30, 2011

My old article "Building JSF custom components"

"Creating an AJAX enabled JSF (1.1 and 1.2 version) components" is my old article, still in draft version.

Article was created on the groundwork of Dr. Winston Prakash's article „Creating AJAX enabled JSF component – part 1”.
When I red Dr. Winston Prakash's article „Creating AJAX enabled JSF component – part 1” I had been verry impressed. In mine opinion
it was the best manual reffered to creating JSF components I whenever saw. There was all I wanted.
Dr. Prakash's article introduced me in exciting world of creating JSF components:).
Some time ago however I was aware of my working knowledge must be put in a good order. Then I decide to create new, but based
on Dr. Prakash's article, manual. I hope, it will be usefull for all of You. As well I hope, an author of the article I based on, perceives my
initiative with kindness and interest.

To download PDF version, please visit:


http://www.scribd.com/doc/74302797/Building-JSF-Custom-Components

Friday, November 25, 2011

How to fix "schema has already been upgraded" issue

I had similar problem when applying last oracle SOA/BPM FP.
To patch db schema I used psa tool:

%ORACLE_HOME%\bin>psa -dbType Oracle -dbConnectString  //dbhost:1521/tst -dbaUserName sys -schemaUserName MY_SOAINFRA


Psa utility threw an error but after removed cause of this error, still I could not run upgrade procedure once again. The cause was next error:


[2011-11-24T17:23:37.467+01:00] [SOAINFRA] [ERROR] [] [upgrade.SOAINFRA] [tid: 10] [ecid: 0000JFRKfjmCKu85njt1iZ1EnvBW000000,0] SOAINFRA schema has already been upgraded.


It looked like schema version was altered despite the fact that the upgrade script was not executed properly.

To check actually version of my SOA schema I used following query:


SELECT version, status FROM schema_version_registry WHERE owner='MY_SOAINFRA';


In the fact, schema version was altered from version 11.1.1.5.0 to 11.1.1.5.1.

To reset this invalid version value i used following clause:


Update SCHEMA_VERSION_REGISTRY set version='11.1.1.5.0' where comp_id='SOAINFRA' and owner='MY_SOAINFRA'

Thursday, November 17, 2011

Oracle jdbc 4.0 driver and createArrayOf issue

Problem description:

Passing an Array object to database stored procedure you can acheive as shown in oracle jdbc 4.0 documentation, eg:

Array aArray = con.createArrayOf("VARCHAR", northEastRegionnewYork);


but ... this don't work with oracle database, as I noticed today. After some googling I found following information:

The SQL standard array type is anonymous, that is the type "array of foo" does not have a name. Only the element type is named. In Oracle SQL the array type is named. In fact anonymous array types are not supported. So, the JDBC 4.0 standard factory method takes the element type as its argument and creates an instance of an anomyous array type. The Oracle JDBC drivers define an Oracle proprietary method, createArray, which takes the name of an array type and returns an instance of that named array type. This is required by the way Oracle SQL is defined. At present the Oracle database cannot support the JDBC 4.0 standard createArrayOf method.

Hmm... how to code this? This is my solution:

Connection conn;
....
ArrayDescriptor arraydesc = ArrayDescriptor.createDescriptor("NUMARRAY", conn);
ARRAY ar = new ARRAY(arraydesc, conn, di);
....
statement.setArray(1, ar);
statement.setString(2, "ble");
statement.execute();
ar.free();
...

Sunday, November 13, 2011

How to: McDialog Jsf component in JSP and facelets view

McDialog is a part of the McFaces (WshFaces) Rich Comnponents Library (JSF 2.0 version). You can find a complete sample code in project webpage: http://wshfaces.sourceforge.net.

Dialog with "static content":

            <mc:dialog id="dlg1" autoOpen="false" closeOnEscape="false" closeText="Zamknij" disabled="false" draggable="true"
                       height="300" hideEffect="none" includeCssTemplate="false" maxHeight="450" maxWidth="550" minHeight="250" minWidth="450"
                       modal="true" buttons="Yes; No; Cancel" resizable="true" title="This is McDialog demo" width="500"
                       dialogShowListener="#{dialogView.dialogShow}"
                       dialogCloseListener="#{dialogView.dialogClose}">
                <div>
                    <p>You can modify look and feel of this dialog by modyfying dialog CSS. Cause MCDialog uses JQuery.dialog pugin as a javascript frontend, you can use JQuery tools to design CSS template for your application.</p>
                    <p>dialogShowListener is called before dialog activation - please look at method mc.hqproducts.components.samples.Dialog.dialogShow to see how it works.</p>
                    <p>dialogCloseListener is called after one of buttons is clicked - please look at method mc.hqproducts.components.samples.Dialog.dialogClose to see it in action. Return value is an integer value. Last button click returns 1, next from right 2 and so on.</p>
                </div>
            </mc:dialog>




Dialog with content loaded via AJAX request:

             <mc:dialog id="dlg2" autoOpen="false" closeOnEscape="false" closeText="Zamknij" disabled="false" draggable="true"
                       height="300" hideEffect="none" includeCssTemplate="false" maxHeight="450" maxWidth="550" minHeight="250" minWidth="450"
                       modal="true" buttons="Yes; No; Cancel" resizable="true" title="This is McDialog demo" width="500" ajaxContentDelivery="true"
                       dialogShowListener="#{dialogView.dialogShow}"
                       dialogCloseListener="#{dialogView.dialogClose}"
                       >
                 <h:panelGroup id="pg2" layout="block">
                    <p>This is an exaple of Dialog with dynamically loaded content</p>
                 </h:panelGroup>
            </mc:dialog>

Thursday, November 10, 2011

How to: pass parameters to backing bean in JSF application

There is few methods to solve this task:

1. f:param - pass parameter value via f:param tag and get it back via request parameter in backing bean.

...
<h:commandbutton action="#{viewScope.documentView.handleSign}" binding="#{viewScope.documentView.pod}" partialsubmit="true" text="Sign">
   <f:param name="path" value="c:\\oracle\\middleware\\aaa">
</f:param></h:commandbutton>
...


@ManagedBean(name="documentView")
@ViewScoped
public class DocumentView{
    //...
    public String handleSign() {
        String path =     FacesContext.getExternalContext().getRequestParameterMap(.get("path");


    }
    //...
}


2. f:setPropertyActionListener - pass parameter to PropertyActionListener defined in your bean

...
<h:commandbutton actionlistener="#{viewScope.documentView.handleSign}" binding="#{viewScope.documentView.pod}" partialsubmit="true" text="Sign">
   <f:setPropertyActionListener target="#{
viewScope.documentView.podActionValue}" value="Podpisz" />
</f:param></h:commandbutton>
...


@ManagedBean(name="documentView")
@ViewScoped
public class DocumentView{
    //...

    String podActionValue;
    public void
setPodActionValue(String value) {
        String podActionvalue = value;
    }
    //...
}


3. f:atribute - Pass parameter value via f:atribute tag and get it back via action listener in backing bean.

 ...
<h:commandbutton actionlistener="#{viewScope.documentView.handleSign}" binding="#{viewScope.documentView.pod}" partialsubmit="true" text="Sign">
  
<f:param name="path" value="c:\\oracle\\middleware\\aaa">
</f:param></h:commandbutton>
...


@ManagedBean(name="documentView")
@ViewScoped
public class DocumentView{
    //...
    public void
handleSign(ActionEvent event) {
        String path = (String)event.getComponent().getAttributes().get("path");
    }
    //...
}


4. ADF way
   af:clientAttribute - You can use af:clientAttribute similar to f:attribute

   af:clientListener/serverListener - When we need add some client side processing in javascript we can pass parameter value from af:clientAttribute via af:clientListener to javascript, and next to af:serverListener tag. You can get values back in listener in backing bean. 

 ...
<af:commandbutton actionlistener="#{viewScope.documentView.handleSign}" binding="#{viewScope.documentView.pod}" partialsubmit="true" text="Sign">

   <af:clientAttribute name="path" value="c:\\oracle\\middleware\\aaa"/>
  
<af:serverListener type="customEvent" method="{viewScope.documentView.handleSign}"/>
   </
af:serverListener>
   <af:clientListener method="signButton" type="click"/>
</af:commandbutton>


<af:resource type="javascript>
function podpiszButton(evt) {
                        var src = evt.getSource();
                        var path = evt.getSource().getProperty('path');
                        component = evt.getSource();
                        AdfCustomEvent.queue(component, "customEvent", {spath:path}, true);
                        evt.cancel();
                    }

</af:resource>
...


@ManagedBean(name="documentView")
@ViewScoped
public class DocumentView{
    //...
    public void
handleSign(ClientEvent event) {
        String path = (String)event.getParameters().get("spath");
    }
    //...
}



5. MethodExpression - the simplest way available in JSF 2.0 version


...
<h:commandButton action="#{viewScope.documentView.handleSign('aaa')}" />
...


@ManagedBean(name="documentView")
@ViewScoped
public class DocumentView{
    //...

    public void handleSign(String sign) {
        this.sign = sign;
    }
    //...
}

Monday, November 7, 2011

How to: storing configuration parameters in web.xml file

Sometimes we need store application wide settings of our web application in configuration files or database. Of course one can also hardcode these parameters, but it isn't best way if we need to construct flexible, easy to maintain software.
There exists also one more, elegant and easy way to store application wide parameters: storing params in web.xml file. As you must know the web.xml file provides configuration and deployment information for the Web components that comprise a Web application. The web.xml file resides in the WEB-INF directory under the context of the hierarchy of directories that exist for a Web application. For example, if the application is myApp.war, then the web.xml file is placed in the myApp.war/WEB-INF directory.

We can store our params as shown bellow:

<?xml version = '1.0' encoding = 'UTF-8'?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         version="2.5" xmlns="http://java.sun.com/xml/ns/javaee">
  <description>sample web.xml file for task flow</description>
  <display-name>MyApp.jws</display-name>
  <context-param>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>client</param-value>
  </context-param>


<context-param>
    <param-name>myParam1</param-name>
    <param-value>user@domain.com</param-value>
  </context-param>
<context-param>
    <param-name>myParam2</param-name>
    <param-value>xyz</param-value>
  </context-param>

...

<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>


...

</web-app>


When we need access stored params in web application code, it can be done very easy:

String ldapUser = getServletContext().getInitParameter("myParam1");
String ldapPassword = getServletContext().getInitParameter("myParam2");


In JSF backing bean it looks simillar, by example:

ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
String ldapUser = context.getInitParameter("myParam1");
String ldapPassword = context.getInitParameter("myParam2"); 


Friday, November 4, 2011

Annouce: McFaces alpha edition released

I'm happy to announce the *alpha* edittion of McFaces, a set of JSF rich components library.
More info about the library you can find on SourceForge.

How to fix: Weblogic ServletContext.getRealPath() returns null

Weblogic Server[WLS] returns null if your code is using Servlet.getRealPath(). You can suppose that it's another weblogic server bug but it's not.

The problem is the way in which you deploy the application. If the application was deployed in exploded mode, getRealPath returns occured, valid value. But, if you deploy it as an archive having extentions like war, ear etc.  you will see "null pointer" Exception. Fortunatelly there is simple way to avoid this exception. You can fix this problem in domain level, setting weblogic Admin Console option Domain | Web Application | Archived Real Path Enabled to true, as shown below:


You can also apply fix in application level by adding the following entry to weblogic.xml file:

<container-descriptor>
    <show-archived-real-path-enabled>true</show-archived-real-path-enabled>
</container-descriptor>

You can do this by JDeveloper IDE as shown below: