Monday, September 5, 2011

Implementing Login form in ADF

If we need to provide our own JSF login page then we can use following JSF code and corresponding managed bean code :

JSF Code:


<af:panelFormLayout id="pfl1">
                    <af:message for="loginname" partialTriggers="cb1" />
                    <af:inputText label="Login Name" id="loginname" />
                    <af:inputText label="Password" id="password" />
</af:panelFormLayout>

<af:panelGroupLayout id="pgl2">
                    <af:commandButton text="Submit" id="cb1" actionListener="#{MyApp_ManagedBean.Login}"/>
                    <af:commandImageLink text="SignUp" id="cil1"/>
</af:panelGroupLayout>



Managed Bean Code:


  public void Login(ActionEvent actionEvent) {
    FacesContext fctx=FacesContext.getCurrentInstance();
    HttpServletRequest request = (HttpServletRequest)fctx.getExternalContext().getRequest();
    HttpServletResponse response = (HttpServletResponse)fctx.getExternalContext().getResponse();
    UIViewRoot viewRoot=fctx.getViewRoot();
    RichInputText userName = (RichInputText)viewRoot.findComponent("pt1:loginname"); 
    //pt1 indicated the page template naming container.
    String userNameStr = (String)userName.getValue();
    RichInputText password = (RichInputText)viewRoot.findComponent("pt1:password");
    String passwordStr = (String)password.getValue();
    try
    {
      int authSuccess=ServletAuthentication.login(userNameStr,passwordStr,request,response);  
      if(authSuccess==ServletAuthentication.AUTHENTICATED)
      {
        try{
          ExternalContext ectx=fctx.getExternalContext();
         //Using Controller Context  is recommended to implement redirect logic instead of directly calling  //External Context redirect method and passingredirect URL in it "faces/RedirectPage".
          ControllerContext controllerCtx = null;
          controllerCtx = ControllerContext.getInstance();
          String activityURL = controllerCtx.getGlobalViewActivityURL("WelcomePage");
          ectx.redirect(activityURL);


        }catch(IOException ioex){ioex.printStackTrace();}
      }
    }
    catch(LoginException loginex)
    {
      String message="Authentication Failed. Please try again";
      fctx.addMessage("pt1:loginname", new FacesMessage(FacesMessage.SEVERITY_ERROR,message,null));
    }
  }
}


Recommended Reading: Oracle Fusion Developer Guide Building Rich Internet Applications with Oracle ADF Business Components and Oracle ADF Faces

Tuesday, August 23, 2011

Display SWF file in Webcenter Space

There may be a requirement to display SWF inside Oracle Webcenter Space. The SWF file can be added to space as content presenter in following way.

All we need to do is to embed our SWF file inside HTML file. Following is the code that can be used:

<html>
<body>
<object width="500" height="500">
    <param name="movie" value="http://localhost:16200/cs/groups/public/documents/document/newswf.swf">
    <embed src="http://localhost:16200/cs/groups/public/documents/document/newswf.swf" width="400" height="400">
    </embed>
</object>
</body>
</html>

The SWF file in above code is coming from UCM. Once done, the HTML file can be easily added to Webcenter Space as content presenter. The same concept can also be used for some video files.

Sunday, August 21, 2011

Store TaskFlow Input Param in Memory Scope or Managed Bean?

If we need to specify some input parameters for our Bounded task flow then, we can specify value (Note: the value field in Input parameter definition indicates the location where the input parameter will be stored. It does not indicate the value of  the parameter we are defining.) either using managed bean or in memory scope. The recommended way is to use managed bean or a simple pojo class configured as manged bean in a memory scope. The reason of using managed bean is that we can use comments in our class file to indicate the purpose for other developers and also make it clear what exactly the input parameters are and where they are stored as they can now be access using managed bean.

Disable text filed in InputDate Component @ADF

If you need to disable the input text filed for adf:inputDate component then we can do that using any of the java scripts below.

1) This script will disable the key events on the text filed. Thus the user will not be able to edit the selected date using Keyboard.

<af:resource>
function disableEntry(evt){
evt.cancel();
}
</af:resource>

<af:inputDate label="Label 1" id="id1" readOnly="false"
contentStyle="background-color:lightgray;">
<af:clientListener method="disableEntry" type="keyDown"/>
</af:inputDate>


2) This script will completely disable the text filed. The only problem with this script is that, if we have many input date components on a page, then we will need to apply this for all component by their IDs.

<af:document id="d1">
<f:facet name="metaContainer">
<f:verbatim>
<script type="text/javascript">
function disable(evt) {
document.getElementById('id1::content').disabled=true;
}

</script>
</f:verbatim>
</f:facet>
<af:clientListener method="disable()" type="load"/>
.....
<af:inputDate label="Date Picker" value="#{pageFlowScope.genPDF.dateEcheance}" binding="#{pageFlowScope.genPDF.id1}" id="id1"/>




Display UCM content in WebCenter based on Locale


Multilingual Page Name in WebCenter


Monday, July 4, 2011

Bounded Task Flow as ADF Library @ADF

To know how to deploy BTF as ADF library, please refer to this tutorial.

I created two different project, one producer that was deployed as ADF library and one consumer for deployed task flow, with all the default settings. Everything was smooth until running the consumer. While running i got following error:


oracle.jbo.JboException: JBO-34010: The "view/DataBindings.cpx" descriptor appears in the application classpath more than once:
 jar:file://.../JDeveloper/system11.1.1.4.37.59.23/DefaultDomain/servers/DefaultServer/tmp/_WL_user/ApplicationPack_V2.0/63ryyw/war/WEB-INF/lib/BTFADFLibrary.jar!/view/DataBindings.cpx


 file://.../JDeveloper/system11.1.1.4.37.59.23/o.j2ee/drs/ApplicationPack/ApplicationPackWebApp.war/WEB-INF/classes/view/DataBindings.cpx

The reason was same name of the packages in both the projects.  The Databinding.cpx file was under view package in both project.  Tried to change the package name from project properties -> project source path  -> Default Package option but still received the same error. I recreated the producer project with new package names and the error was resolved. Other way will be to use refactoring.