Jul 27, 2012

Use of Popup window behaviour in ADF

Popup component shows a smart look of application, makes a more interactive page.
So in ADF we can  use two ways to show popup.

1.) Using Show popup Behavior component :-

 Drag Show Popup Behavior component from component palette to button.





Specify the Show Popup Behavior porperty......

>Popup Id:-Id of popup component that you want to show.
>Trigger type:-

>Align:-



Now run your page......
  
 When you click Add button popup will open.
 

 
 2.)Using Code :-
 
 Add following method in managed bean.
 
import javax.faces.context.FacesContext;
import oracle.adf.view.rich.component.rich.RichPopup;
import org.apache.myfaces.trinidad.render.ExtendedRenderKitService;
import org.apache.myfaces.trinidad.util.Service;

    private void showPopup(RichPopup pop, boolean visible) {
        try {
          FacesContext context = FacesContext.getCurrentInstance();
          if (context != null && pop != null) {
            String popupId = pop.getClientId(context);
            if (popupId != null) {
              StringBuilder script = new StringBuilder();
              script.append("var popup = AdfPage.PAGE.findComponent('").append(popupId).append("'); ");
              if (visible) {
                script.append("if (!popup.isPopupVisible()) { ").append("popup.show();}");
              } else {
                script.append("if (popup.isPopupVisible()) { ").append("popup.hide();}");
              }
              ExtendedRenderKitService erks =
                Service.getService(context.getRenderKit(), ExtendedRenderKitService.class);
              erks.addScript(context, script.toString());
            }
          }
        } catch (Exception e) {
          throw new RuntimeException(e);
        }
      }  
 
 
Add Binding  to popup 
 
 
 
 Add Action Listner to button.
 



Now call showPopup method in ActionListner of button 
 
The ActionListner Code of button:-
 
  public void Add(ActionEvent actionEvent) {
        showPopup(addpopup, true);
    }
 
 or we can use below code for same with above showPopup method

public void Add(ActionEvent actionEvent) {
    RichPopup.PopupHints hints = new RichPopup.PopupHints();        this.getAddpopup().show(hints);
    }
 
Now Run your page
When you click Add button popup will open.
.

convert af:inputtext to Uppercase

We can convert content of input text to uppercase,lowercase and initcap by 2 method.......

1.) Using Property:-

 Go to contentStyle property of af:inputtext

    >For Uppercase:-
      Write text in ContentStyle Property   "text-transform:uppercase"

    

Source code of field(in xml):-

 <af:inputText  id="it7"

       value="#{bindings.FirstName1.inputValue}"

       contentStyle="text-transform:uppercase;"/>
 
       

             

 >For Lowercase:- 
  Write text in ContentStyle Property "text-transform:lowercase"


Source code of field(in xml):-
 
 <af:inputText  id="it7"

       value="#{bindings.FirstName1.inputValue}"

       contentStyle="text-transform:lowercase;"/>

  >For Initcap:-
       Write text in ContentStyle Property "text-transform:capitalize"

Source code of field(in xml):-
  
  <af:inputText  id="it7"

       value="#{bindings.FirstName1.inputValue}"
 
       contentStyle="text-transform:capitalize;"/>

Run the page

1.Upper Case:-
2.Lower Case:-
3.Initcap:-


2.)Using java script:- 

We can use af:resource JSP tag to define JavaScript .

af:resource  is JSP tag that defines a CSS or JavaScript resource to be included in the HTML head element of the page.

 Now drag af:resource from component palette to any part of page.


 <af:resource type="javascript"><f:verbatim>
          function isLetter(keyCode) { if (keyCode == "A" || keyCode == "B" || keyCode == "C" || keyCode == "D" ||
          keyCode == "E" || keyCode == "F" || keyCode == "G" || keyCode == "H" || keyCode == "I" || keyCode == "J" ||
          keyCode == "K" || keyCode == "L" || keyCode == "M" || keyCode == "N" || keyCode == "O" || keyCode == "P" ||
          keyCode == "Q" || keyCode == "R" || keyCode == "S" || keyCode == "T" || keyCode == "U" || keyCode == "V" ||
          keyCode == "W" || keyCode == "X" || keyCode == "Y" || keyCode == "Z") { return true; } return false; }


function convertCase(event) { var keyChar =
          AdfKeyStroke.getKeyStroke(event.getKeyCode()).toMarshalledString(); if (isLetter(keyChar)) { var field =
          event.getCurrentTarget(); var value = field.getSubmittedValue(); field.setValue(value.toUpperCase()); return
          true; } }
        </f:verbatim></af:resource>


Select javascript Type property of af:resource

Add af:clientListner component to field where we want to use this.
Set properties of af:clientListner ,give method name as convertCase and type as keyUp
Now run your page

Jul 25, 2012

How to use FacesMessage component in ADF

FacesMessage component is used to show confirmation, warning, information and error message .In this tutorial, you will see that how to use FacesMessage component to show any confirmation, information, warning or any error. Suppose you want to show a confirmation when you save your records, here we use FacesMessage.

Managed Bean Code to use FacesMessage(Information)

Add this following code in any method(or method action).

String msg ="Record Saved Successfully!";
FacesMessage message = new FacesMessage(msg); message.setSeverity(FacesMessage.SEVERITY_INFO);
FacesContext fc = FacesContext.getCurrentInstance();
fc.addMessage(null, message);



 To use for Error and Warning just change

 FacesMessage.SEVERITY_INFO or SEVERITY_ERROR or SEVERITY_WARN.

It will look like this
You can change your Message accordingly.


Auto Suggest Behavior


The af:autoSuggestBehavior produces a dropdown list of suggested items as the user types into the input component. This functionality is implemented as a behavior which means it is a sub-element that needs to be inserted into a top-level component tag. 

To use the auto-suggest functionality in a declarative way you need to define a model-driven list of values on your model project, which will be the base for the suggestedItems list. Select the FirstName attribute from the Employees VO and create a List of Values.











Create List of Values
 














Create List of Values
On the UI Hints Tab,select the Default Display to be Input Text with List of Values.


Drag the FirstName attribute is displayed as an inputListOfValues











Now drag and drop the autoSuggestBehavior from your component palette inside of List.



 Then Add   SuggestedItems Property Auto Suggest Behavior.








Add EL in  SuggestedItems.......
 

















 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Now run your page and now you will get auto suggest items as you type.
Here are two different types of lists:

                                                              ADF LOV Input

                                                                ADF LOV Choice List

Jul 21, 2012

Adf Security

ADF Security can be implemented for:

1)Declarative security support for ADF resources, such as the bounded task flow.
With Oracle ADF Security, you can control whether or not the user can enter a task flow. Thus, a single security policy for a task flow can control access to multiple web pages.

2)Simplified permission assignment using application roles that allow for the inheritance of permissions
While Java EE security roles that are used by Java EE security constraints are flat, JAAS permissions are granted to application roles, which can be nested and may be mapped to enterprise roles that the Oracle WebLogic Server domain defines.

3)Utility methods for use in EL expressions to access ADF resources in the security context
You can use the Oracle ADF Security EL expression utility methods to determine whether the user is allowed to perform a known operation. For example, you can determine whether the user is allowed to view a particular task flow.



Steps :
1.Enable Oracle ADF Security for the application:
(a)From the Application menu, choose Secure > Configure ADF Security.






(b)In the ADF Security page, leave the default ADF Authentication and Authorization option selected. Click Next.





(c)In the Authentication Type page> select the authentication type that you want your application to use when the user submits their login information. Click Next.
Select Form-based Authentication, you can also select Generate Default Pages to allow the wizard to generate a default login and error page.

 

(d)In the Automatic Policy Grants page, leave the default No Automatic Grants option selected. Click Next .




(e)In the Authenticated Welcome page, select Redirect Upon Successful Authentication to direct the user to a specific web page after they log in. Click Next. Then Finish.




2)Creating Application Roles
You create application roles to represent the policy requirements of the application and to define groups of users with the same view permission rights.
(a)Choose Secure > Application Roles from the Application menu in the JDeveloper




(b)Select Add New Role in the Application Roles tab. Provide the name for Role(eg: Admin)
When you add an application role to the policy store, JDeveloper updates the jazn-data.xml file located in the src/META-INF folder relative to the application workspace.




(c)Add users to the newly created Roles




Create the User and select the check box. Click OK.




3)Grant public access to ADF security-aware resources

In the Resource Grants overview editor, click one of the following Resource Type :
  • Task Flows when you want to make a bounded task flow public. The application displays the web pages under the permission you define for the task flow itself. Thus, all constituent web pages of the bounded task flow will become public.
  • Web Pages when you want to make individual web pages public. Typically, these pages are defined by an unbounded task flow and are top-level pages in the application, such as a home page.




Add required Application role or User to the TF or web page.





Use EL to specify viewable components on the Page. For Eg:
For login/logout Link:
Text: #{securityContext.authenticated ? "Logout" : "Login"}
Destination: #{securityContext.authenticated ? "/adfAuthentication?logout=true&end_url=/faces/IndexPage.jspx" : "/adfAuthentication?success_url=/faces/IndexPage.jspx"}

 


Use EL to configure rendered property of Button/Link for particular Role. For Eg:

#{securityContext.UserInRole['Admin']}
OR
#{securityContext.UserInRoles['Admin','Staff']}


4)Security can be bestowed upon Entity object attributes too.




Once security is enabled, you need to associate roles to it, or no one will be able to edit this attribute.




When 'Edit Authorization' is clicked jazn-data.xml is opened where you can configure the roles for the attributes to be modifiable.




Method/Expression Description
#{securityContext.taskflowViewable['SomeTaskFlow']}
Returns true if the user has access to the specific SomeTaskFlow task flow.


#{securityContext.regionViewable['SomePageDef']}


Returns true if the user has access to the specific SomePageDef page definition file associated with a page.


#{securityContext.userName}


Returns the authenticated user's username.


#{securityContext.authenticated}


Returns true if the user has been authenticated.


#{securityContext.userInAllRoles['roleList']}


Returns true if user has roles in the comma seperated rolesList assigned.


 
On the starting Page of your Application , to enable view for all users(anonymous), configure the role as 'Anonymous User' for the landing page as follows: