Tuesday, October 28, 2014

Best technique to bind the UI Components to the managed bean in JSF/ADF

Problem

Runtime exceptions saying can't serialize rich ui component class.

Why is it occurring?

Binding a JSF UI Component to a managed bean which is in a scope greater than requestScope or backingBeanScope. We should not do that because the UI components are not serializable and the application might not work properly in the clustered environment. We should bind the JSF components to the managed beans which are either in requestScope or backingBeanScope.

What is so special about requestScope and backingBeanScope?

For backingBeanScope or requestScope bean the class references need not be serialized. So inorder to avoid any serialization errors it is recommended to keep the UI component references in a backing bean scoped or request scope bean so as to avoid any serialization done on these class references.

But requestScope or backingBeanScope is not sufficient for my scenario, what to do?

  1. Configure the manged bean (MB1) to the taskflow in the backingBeanScope
  2. Configure another managed bean (MB2) in the required scope, pageFlowScope or viewScope
  3. Refer the UI Components of MB1 in MB2.
Example

BackingBean.java  (BackingBean scope/ Request scope)

import oracle.adf.view.rich.component.rich.layout.RichInputText;
public RichInputText getRichInputText(){
 // implement the getter method as needed
}

// Access these getters on your pageFlowScope Bean
PageFlowScopeBean.java implements Serialization (PageFlowScope)

import javax.faces.context.FacesContext;
public void uiCompRefFromBackingBean(){
    // get the backingbean instance   
    FacesContext facesContext = FacesContext.getCurrentInstance();
    BackingBean backingBean = (BackingBean)facesContext.getExternalContext().getRequestMap().get("BackingBean");
   
    // get the component instance
    RichInputText tree = backingBean.getRichInputText();
 }




Thursday, October 16, 2014

How to provide security to the imported taskflows in adf?

 Open the Jazn-data.xml and click the checkbox "Show task flows imported from ADF libraries".

In which case, we see all the imported taskflows in the resources section.
 


Sunday, October 5, 2014

Showing the error messages for both system validation and custom validaton at a time in Oracle ADF

Sometimes we have the requirement to show the custom error messages coupled with the framework related error messages simultaneously on the screen.

Using the FacesMessage will show the error message for just one component and if we don't put the immediate="true" for the button, then just the system validations/framework validations are shown on the screen. But we want to display both the system messages and custom error messages by setting the immediate="true" for the button.

The following code snippet will solve the problem

Command Button Code
 
    <af:commandButton text="Submit" id="cb1" immediate="true"
                      actionListener="#{pageFlowScope.ErrorBean.onClickSubmit}">
      <af:clientAttribute name="superImmediate" value="#{true}"/>
      <af:clientListener method="catchActionEvent" type="action"/>
      <af:serverListener type="customButtonAction"
                         method="#{pageFlowScope.ErrorBean.customButtonActionListener}"/>
    </af:commandButton>

Javascript code to be embedded in the Jsff

<af:resource type="javascript">  
   AdfActionEvent.prototype.isValidationNeeded = function () {
       return !this.getSource().getProperty("superImmediate");
   }

   // Action event will cause server-side validation at the 
   // Apply Request Values phase (for immediate button). 
   // So we'll get validation error even if the client-side validation is suppressed 
   // We need to catch the original Action event, cancel it and replace with our 
   // custom event customButtonAction. 
   function catchActionEvent(evt) {
       AdfCustomEvent.queue(evt.getSource(), 'customButtonAction', null, true);
       evt.cancel();
   }
</af:resource>

Backing bean Code

public void onClickSubmit(ActionEvent actionEvent) {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error while Saving","Error while saving");
    facesContext.addMessage(null,msg);
}

public void customButtonActionListener(ClientEvent clientEvent) { 
      UIXCommand cb = (UIXCommand) clientEvent.getComponent(); 
      cb.broadcast(new ActionEvent(cb)); 
  } 

Friday, October 3, 2014

Jdeveloper integrated weblogic server Unrecognized option: -jrockit issue

When you try and run your web application and the embedded WebLogic tries to start you might run into an error like:

Unrecognized option: -jrockit
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit. 

This is most likely due to the fact that JDeveloper is trying to use the wrong JVM to run your WebLogic.

Solution

Edit the file: /users/vinay/.jdeveloper/system11.1.1.7.40.64.93/DefaultDomain/bin/setDomainEnv.sh

Add the following lines

JAVA_VENDOR="Sun"
export JAVA_VENDOR 

By doing this you'll instruct WebLogic to start with a regular JVM and not the JRockit variant which isn't on your mac.

More details here

Wednesday, October 1, 2014

Programmatically populate the af:selectOneChoice component in Oracle ADF?

Step1

Create a Java List of SelectItems and create getter setter for that as below

    List<SelectItem> customList;

    public void setCustomList(List<SelectItem> customList) {
        this.customList = customList;
    }

    public List<SelectItem> getCustomList() {
        return customList;
    }
 

Step2

 

Modify the getter method with the logic to return the list of items

 

    public List<SelectItem> getCustomList() {
        if (customList == null) {
            customList = new ArrayList<SelectItem>();
            customList.add(new SelectItem("Value 1","Label 1"));
            customList.add(new SelectItem("Value 2","Label 2"));
            customList.add(new SelectItem("Value 3","Label 3"));
            customList.add(new SelectItem("Value 3","Label 4"));
            customList.add(new SelectItem("Value 5","Label 5"));
        }
        return customList;
    }
 

Step3 

 

Configure the jsff/jspx as below to refer the select items from the bean getter method created above


 <af:selectOneChoice label="Custom List" id="soc1">
     <f:selectItems value="#{CustomerBean.customList}" id="si1"/>
</af:selectOneChoice>