Tuesday, October 29, 2013

Pass additional values to Listener using SetPropertyListener

Scenario: User enters bonus amount. If Salary+Bonus is greater than 1,50,000 show alert message.

Step1:Create VO with Salary and Bonus attributes. Create a table in JSPX page.

Step2: Set Bonus input text field properties.. add validate method to ValueChangeListener and set AutoSubmit to true.

Step3: Add setPropertyListener on Bonus inputtext field.
    From: Source value(Value to be saved in scope for later use) Ex: #{row.bindings.Salary.inputValue}
    To:  Variable Name(Scope and Variable to hold the source value) Ex; #{pageFlowScope.CurrRowSalaryVar}
    Type: Listener Type Ex: valueChange

Step4: Add code in bean.
    public void validateTotalSalary(ValueChangeEvent ve){
        BigDecimal bonus = (BigDecimal)ve.getNewValue();
        BigDecimal salary = (BigDecimal)AdfFacesContext.getCurrentInstance().getPageFlowScope().get("CurrRowSalaryVar");
        int ibonus = bonus.intValue();
        int isalary= salary.intValue();
        
        if(bonus!=null && salary!=null && (ibonus+isalary)>150000){
            FacesMessage msg = new FacesMessage("Total Salary exceeded 1,50,000.");
            msg.setSeverity(FacesMessage.SEVERITY_INFO);
            FacesContext fc = FacesContext.getCurrentInstance();
            fc.addMessage(null, msg);
        }
    }

Step5: Ouput


PPR on Table Row

Scenario: On Update in Bonus field of selected row, TotalSalary should get updated by Salary+Bonus amounts.

Step1: Create VO. Add TotalSalary as Transient attribute. Create table in JSP page.

Step2: Add ValueChangeListner on Bonus InputText box. Set AutoSubmit to true.

Step3:Create method in bean.
public void setTotalAmt(ValueChangeEvent ve){
        //BigDecimal bonus = (BigDecimal)ve.getNewValue();
        for (Object facesRowKey : t1.getSelectedRowKeys()) { 
            t1.setRowKey(facesRowKey); 
            Object o = t1.getRowData(); 
            JUCtrlHierNodeBinding rowData = (JUCtrlHierNodeBinding)o; 
            Row row = rowData.getRow(); 
            BigDecimal salary = (BigDecimal)row.getAttribute("Salary");
BigDecimal bonus = (BigDecimal)row.getAttribute("Bonus");
            row.setAttribute("TotalSalary", salary.add(bonus));
        }
}


Monday, October 28, 2013

ADF Security

1.Print the roles of the current user
for ( String role : ADFContext.getCurrent().getSecurityContext().getUserRoles() ) {
   System.out.println("role "+role);
}

2.Get the ADF security context and test if the user has the role users
SecurityContext sec = ADFContext.getCurrent().getSecurityContext();
if ( sec.isUserInRole("users") ) {
}

3.Is the user valid
public boolean isAuthenticated() {
 return ADFContext.getCurrent().getSecurityContext().isAuthenticated();}

4.Return the user
public String getCurrentUser() {
 return ADFContext.getCurrent().getSecurityContext().getUserName();
}

Source: http://blog.whitehorses.nl/2010/02/01/weblogic-web-application-container-security-part-2-adf-security/

Friday, October 25, 2013

Accessing URL Params

1. Using Groovy:
URL: http://highbrow:7101/TestUrl/Faces/TestPage.jspx?pupOrderNumber=27826728&pageMode=PUP

#{param.pupOrderNumber}  -- returns its value: 27826728
#{param.pageMode}  -- returns its value: PUP

2. Programmatically:
HttpServletRequest request =(HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
String ordNum = request.getParameter("pupOrderNumber");
String pMode= request.getParameter("pageMode");

or

FacesContext fctx = FacesContext.getCurrentInstance();
ExternalContext ectx = fctx.getExternalContext();

java.util.Map params = ectx.getRequestParameterMap();
String ordNum = (String)params.get("pupOrderNumber");
String pMode = (String)params.get("pageMode");

Tuesday, October 22, 2013

Accesing Login User Details

1- Using Groovy: We can set default expression in view object attribute as below

adf.context.securityContext.getUserPrincipal().getName()
or
adf.context.securityContext.getUserName()

2- Java Code: You can get User Name in Java code also using the following code.

     ADFContext adfCtx = ADFContext.getCurrent();
     SecurityContext secCntx = adfCtx.getSecurityContext();
     String user = secCntx.getUserPrincipal().getName();
     String _user = secCntx.getUserName();

3-Expression Language: You can bind ADF Faces componenets with the following EL to get logged User Name.

 #{securityContext.userName}

Source:http://mahmoudoracle.blogspot.in/2012/06/adf-get-current-logged-user-name.html#.UmTBMPlHK8w

Monday, October 14, 2013

Attributes of the PageDef.xml File Element

Element SyntaxAttributesAttribute Description
<accessorIterator>BeanClassIdentifies the Java type of beans in the associated iterator/collection.


CacheResultsIf true, manage the data collection between requests.


DataControlThe data control which interprets/returns the collection referred to by this iterator binding.


idUnique identifier. May be referenced by any ADF value binding.


MasterBindingReference to the methodIterator (or iterator) that binds the data collection that serves as the master to the accessor iterator's detail collection.


ObjectTypeThis is used for ADF BC only. A boolean value determines if the collection is an object type or not.


RangeSizeSpecifies the number of data objects in a range to fetch from the bound collection. The range defines a window you can use to access a subset of the data objects in the collection. By default, the range size is set to a range that fetches just ten data objects. Use RangeSize when you want to work with an entire set or when you want to limit the number of data objects to display in the page. Note that the values -1 and 0 have specific meaning: the value -1 returns all available objects from the collection, while the value 0 will return the same number of objects as the collection uses to retrieve from its data source.


RefreshDetermines when and whether the executable should be invoked. Set one of the following properties as required:
  • always - causes the executable to be invoked each time the binding container is prepared. This will occur when the page is displayed and when the user submits changes, or when the application posts back to the page.
  • deferred - refresh occurs when another binding requires/refers to this executable.Since refreshing an executable may be a performance concern, you can set the refresh to only occur if it's used in a binding that is being rendered.
  • ifNeeded - whenever the framework needs to refresh the executable because it has not been refreshed to this point. For example, when you have an accessor hierarchy such that a detail is listed first in the page definition, the master could be refreshed twice (once for the detail and again for the master's iterator). Using ifNeeded gives the mean to avoid duplicate refreshes. This is the default behavior for executables.
  • never - When the application itself will call refresh on the executable during one of the controller phases and does not want the framework to refresh it at all.
  • prepareModel - causes the executable to be invoked each time the page's binding container is prepared.
  • prepareModelIfNeeded - causes the executable to be invoked during the prepareModel phase if this executable has not been refreshed to this point. See also ifNeeded above.
  • renderModel - causes the executable to be invoked each time the page is rendered.
  • renderModelIfNeeded - causes the executable to be invoked during the page's renderModel phase on the condition that it is needed. See also ifNeeded above.


RefreshConditionAn EL expression that when resolved, determines when and whether the executable should be invoked. For example, ${!bindings.findAllServiceRequestIter.findMode} resolves the value of the findModel on the iterator in the ADF binding context AllServiceRequest. Hint: Use the Property Inspector to create expressions from the available objects of the binding context (bindings namespace) or binding context (data namespace), JSF managed beans, and JSP objects.
<invokeAction>BindsDetermines the action to invoke. This may be on any actionBinding. Additionally, in the case, of the EJB session facade data control, you may bind to the finder method exposed by the data control. Built-in actions supported by the EJB session facade data control include:
  • Execute executes the bound action defined by the data collection.
  • Find retreives a data object from a collection.
  • First navigates to the first data object in the data collection range.
  • Last navigates to the first data object in the data collection range.
  • Next navigates to the first data object in the data collection range. If the current range position is already on the last data object, then no action is performed.
  • Previous navigates to the first data object in the data collection range. If the current position is already on the first data object, then no action is performed.
  • setCurrentRowWithKey passes the row key as a String converted from the value specified by the input field. The row key is used to set the currency of the data object in the bound data collection. When passing the key, the URL for the form will not display the row key value. You may use this operation when the data collection defines a multipart attribute key.
  • setCurrentRowWithKeyValue is used as above, but when you want to use a primary key value instead of the stringified key.


idUnique identifier. May be referenced by any ADF action binding


Refreshsee Refresh above.


RefreshConditionsee RefreshCondition above.
<iterator> and <methodIterator>BeanClassIdentifies the Java type of beans in the associated iterator/collection


BindingClassThis is for backward compatibility to indicate which class implements the runtime for this binding definition. Ignored in JDeveloper 10.1.3.


Bindssee Binds above.


CacheResultssee CacheResults above


DataControlName of the DataControl usage in the bindingContext (.cpx) which this iterator is associated with.


DefClassUsed internally for testing.


idUnique identifier. May be referenced by any ADF value binding.


ObjectTypeNot used by EJB session facade data control (used by ADF Business Components only).


RangeSizesee RangeSize above


Refreshsee Refresh above


RefreshConditionsee RefreshCondition above
<page> and <variableIterator>idUnique identifier. In the case of , refers to nested page/region that is included in this page. In the case of the executable, the identifier may be referenced by any ADF value binding


pathUsed by executable only. Advanced, a fully qualified path that may reference another page's binding container.


Refreshsee Refresh above


RefreshConditionsee RefreshCondition above

Tip:
You can determine the order of executable invocation using the refreshAfter attribute. For example, say you have two invokeAction elements; one with an ID of myAction and another with an ID of anotherAction, and you want myAction to fire afteranotherAction. You would set the refreshAfter condition on myAction toanotherAction.

Execute some code when the page loads in adf

There are many ways to execute some code before loading the page in adf.

They are:
1. By using Method activity in the Task flow.
We can achieve this in 2 ways again.
a.  Add the code to be executed, to a method in ApplicationModuleImpl class and expose it to client interface. From Data Control panel drag and drop that method to the Task flow. In the task flow add the page (view activity) and navigation from the method activity to the view acitvity. In this approach, first the method will be invoked before rendering the page.

b. Add the code to be executed to the managed bean and add a method call activity to the Task flow. For that method call activity bind the method in the Managed bean. Now add the view activity(page) and add navigation from method call activity to the view activity. In this approach, first the method from the managed bean will be invoked before rendering the page.

2. Using invokeAction executables.
This approach is used when we dont want to use taskflow method call to execute this page load code.     If we dont have any task flows in our application and we are using only jsf pages, then this is the best approach. Add the code to the method in the ApplicationModuleImpl class and expose it to the client interface. Go to the pagedef file corresponding to the page and in the bindings section add the method from datacontrol. Now in the executables section add invokeAction executable. It will ask for some id and  in the binds field specify the method action added in the bindings. Select the executabel now and go to Property Inspector. In the Refresh property specify “renderModel”. Now it will be executed before the page loads.

3. Using Server and ClientListener code
In the jspx page give the code in the following manner.

 af:document id=”d1″
    af:serverListener type=”onloadEvent”
                       method=”#{managedbean name.method name}”
 
    af:clientListener method=”onLoadClient” type=”load”
 
    af:resource type=”javascript”
    function onLoadClient(event) {
      AdfCustomEvent.queue(event.getSource(),”onloadEvent”,{},false);
      return true;
    }
    af:resource

Source: http://adfnbpel.wordpress.com/2012/08/07/execute-some-code-when-the-page-loads-in-adf/

Page Definition Variables

We can use Page Definition variables to store temporary values, these values will be preserved between requests.

Details: http://andrejusb.blogspot.in/2011/10/page-definition-variables-to-store.html
Related Posts Plugin for WordPress, Blogger...