Progress Message - oracle-adf

How to add a progress message like "Fetching Data" pragmatically. When the data is getting fetched , i need to display this message on the blank page.I am new to ADF , so pardon me if it is some thing very basic . I couldn't find it on net.

You can use javascript in your page or pagefragment. My example uses a page fragment, so the id of the popup must contain the region. If you have trouble locating the correct id you can look it up from any browser, by using View Source, and searching for the name you gave it (in this case splashPopup).
<af:resource type="javascript">
function enforcePreventUserInput(evt) {
var popup = AdfPage.PAGE.findComponentByAbsoluteId('pt1:r1:0:splashPopup');
if (popup != null) {
AdfPage.PAGE.addBusyStateListener(popup, handleBusyState);
evt.preventUserInput();
}
}
function handleBusyState(evt) {
var popup = AdfPage.PAGE.findComponentByAbsoluteId('pt1:r1:0:splashPopup');
if (popup != null) {
if (evt.isBusy()) {
popup.show();
}
else if (popup.isPopupVisible()) {
popup.hide();
AdfPage.PAGE.removeBusyStateListener(popup, handleBusyState);
}
}
}
</af:resource>
The popup inside the pageFragment. It displays a simple gif animation of a spinning circle. You can find numerous other animations if you need to on google.
<af:popup id="p1" contentDelivery="immediate">
<af:dialog id="d2" type="none" closeIconVisible="false" title="Loading">
<af:panelGroupLayout id="pgl5" layout="vertical" halign="center">
<af:image source="/images/loading.gif" shortDesc="Loading data..." id="i1"/>
</af:panelGroupLayout>
</af:dialog>
</af:popup>
Now, I think you will want to show the popup during a long running query or some other long running process, after pressing a button or an image link. For this you must define a clientListener on your component, which uses the javascript methods defined above.
<af:commandImageLink text="Test LongRunning Query" id="cil1" icon="/icons/excel.jpg"
action="#{myBean.doStuff}"
<af:clientListener method="enforcePreventUserInput" type="action">
</af:clientListener>
</af:commandImageLink>

If you have a long running method call then you can call that method on page load
<af:serverListener type="onloadEvent"
method="#{backingBeanScope.initBean.callMethod}"/>
<af:clientListener type="load" method="triggerOnLoad"/>
<af:resource type="javascript">
function triggerOnLoad(event)
{
AdfCustomEvent.queue(event.getSource(), "onloadEvent", {},false);
return true;
}
</af:resource>
and then use adf status indicator to show the status on the page.
<af:panelStretchLayout id="psl1" startWidth="33%" endWidth="33%"
topHeight="33%" bottomHeight="33%">
<f:facet name="bottom"/>
<f:facet name="center">
<af:statusIndicator id="si1"/>
</f:facet>
<f:facet name="start">
<af:panelGroupLayout id="pgl2"/>
</f:facet>
<f:facet name="end">
<af:panelGroupLayout id="pgl3"/>
</f:facet>
<f:facet name="top">
<af:panelGroupLayout id="pgl4"/>
</f:facet>
</af:panelStretchLayout>
Refer to this blog post fro more details
Show status indicator for long running method calls - ADF

Related

Button disable in Visual force page

On Standard Object (account) i have a button called SAD. The button is added over there by Visual force page.
Now my question is on Account page, for particular field Picklist value (Eg.. Company type=''Z001') how to disable the SAD button visibility to the all users?
Seems like you are using apex:detail tag in order to show the record detail on visualforce page.
To hide any button you can make use of the below code snippet along with conditions when to hide or when not to.
<apex:page standardController="Account" >
<apex:detail />
<apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" />
<script>
$(document).ready(function() {
if({!Account.Company_Type__c == 'Z001'}){
$('[name="REPLACE_BUTTON_NAME_HERE"]').hide();
}
});
</script>
</apex:page>
get your button name by inspecting the button on visualforce page and replace same in the code in place of REPLACE_BUTTON_NAME_HERE
Why not do it with a LWC instead?
You can use the #wire decorator with the getRecord method of the uiRecordApi to grab data from the object based on the id of the current record.
JS file would look something like this:
#wire(getRecord, { recordId: '$recordId', fields:['Company_Type__c'] })
Account;
visible = false;
if (Account.Company_Type__c == 'Z001'){
visible = true;
}
handleClick(){
// use #wire to access Controller class you used for your vf page.
}
You'd place the button in the LWC template. Just use the tag.
HTML File would look something like this:
<template>
<template if:true={visible}>
<lightning-button
variant="normal"
label="SAD"
title="SAD Button"
onclick={handleClick}>
</lightning-button>
</template>
</template>
i found out the solution for this code by adding property in Controller and getting it from controller to VF page.
Here is the code.
Code in Extn class
Public Account AccName{get;set;}
Public Account Acnt{get;set;}
Public user userid;
public boolean stagesDisabled {
get {
userid =[SELECT Id, Country FROM User where Id =:UserInfo.getUserId()];
Acnt = [Select id, Company_Type__c from account where id =: Acc.id];
return( Acnt.Company_Type__c =='Z008' && userid.Country =='XYZ' );
}
}
Code in VF page
<apex:commandButton action="{!SAD}" value="New Sales Area Data" disabled="{!stagesDisabled}" />

VisualForce prevent double clicking on a button

I have done a lot of research on this, and can not figure out the best way to solve this. I am trying to prevent a user from clicking multiple times on a custom button in a VF page. When that is done, they invoke the method related to the button multiple times. I saw quite a few posts with different solutions, but most of them are on posts from 5-10 years ago.
<script src="//ajax.googleapis.com/ajax/libs/jquery/latest/jquery.js"></script>
<script>
function buttonsEnabled(enabled) {
// retrieve all of the buttons or links on the page
// with the css class of btn
var $buttons = jQuery('.btn');
if (enabled === false) {
// add the btnDisabled class to give it the look of being disabled
// add the disabled attribute to actually disable interactability
$buttons.toggleClass('btnDisabled', true).attr('disabled', 'disabled');
} else {
// remove the css class and the disabled attribute
$buttons.toggleClass('btnDisabled', false).attr('disabled', null);
}
}
function doSomeWork() {
// first, call the action function to post the form
doSomeWorkActionFunction();
// second, disable the buttons
buttonsEnabled(false);
// third, return false to prevent the click from
// posting the form a second time
return false;
}
</script>
<apex:form>
<apex:actionFunction name="doSomeWorkActionFunction"
action="{!yourControllerMethod}"
oncomplete="buttonsEnabled(true);"
rerender="whateverYouNeedToRerender"></apex:actionFunction>
<apex:commandLink action="{!yourControllerMethod}"
value="Your Text Here"
id="theCommandLink"
onclick="return doSomeWork();" />
</apex:form>

ADF selectOnechoice how to display label in items

I am working on ADF. I need to display help text on mouse hover for each value of drop down. I struggled al lot but dint find any thing to do in model layer. Finally I endded up playing with string EL expression.
<af:table value="#{bindings.LetterUIConfig1.collectionModel}" rendered="false"
width="98%" styleClass="AFStretchWidth" var="row"
rows="#{bindings.LetterUIConfig1.rangeSize}"
emptyText="#{bindings.LetterUIConfig1.viewable ? 'No data to display.' : 'Access Denied.'}"
fetchSize="#{bindings.LetterUIConfig1.rangeSize}"
rowBandingInterval="0" id="t1" columnStretching="column:c1"
inlineStyle="border-style:hidden;" horizontalGridVisible="false"
verticalGridVisible="false">
<af:column sortProperty="#{bindings.LetterUIConfig1.hints.Name.name}"
sortable="false" id="c1" noWrap="false" headerText="">
<af:panelFormLayout id="pfl1" labelWidth="40%" fieldWidth="60%"
maxColumns="1" labelAlignment="start">
<af:panelLabelAndMessage label="#{row.Name}" id="plam1"
styleClass="alignLeft"
labelStyle="text-align: left;">
<af:panelGroupLayout id="pgl1">
<af:selectOneChoice value="#{row.bindings.Name.inputValue}"
label="#{row.bindings.Name.label}"
required="#{bindings.LetterUIConfig1.hints.Name.mandatory}"
shortDesc="#{bindings.LetterUIConfig1.hints.Name.tooltip}"
id="soc1">
<af:forEach items="#{bindings.LetterAttributeLOV.rangeSet}" var="list">
<af:selectItem id="si1" value="#{list.AttVal}"/>
</af:forEach>
</af:selectOneChoice>
<af:selectBooleanCheckbox value="#{row.bindings.Name.inputValue}"
rendered="#{row.Type eq 'SBC'}"
label="#{row.bindings.Name.label}"
shortDesc="#{bindings.LetterUIConfig1.hints.Name.tooltip}"
id="sbc1"/>
<af:selectManyCheckbox label="#{row.Name}" id="smc1"
rendered="#{row.Type eq 'SMC'}">
<f:selectItems value="#{row.bindings.Name.items}" id="si2"/>
</af:selectManyCheckbox>
</af:panelGroupLayout>
</af:panelLabelAndMessage>
</af:panelFormLayout>
<af:spacer id="s1" height="10"/>
</af:column>
My problem is select item is not displaying substring it is displaying only value. I did use valuePassThrough but no luck.
Try a define method for initialize to itemList;
public List getSelectItemList(){
ArrayList list = new ArrayList();
Iterator<Object> iterator = resolveExpression("#{bind here your LOV}");
while (iterator.hasNext()) {
Object obj= iterator.next();
list.add(new SelectItem(enterObjValue, enterObjValueLabel));
}
return list;
}
public Object resolveExpression(String expression) {
FacesContext fc = getFacesContext();
ELContext elCtx = fc.getELContext();
return fc.getApplication().getExpressionFactory().createValueExpression(elCtx, expression, Object.class).getValue(elCtx);
}
and bind this list to Select one choice component.
<af:selectOneChoice value="#{row.bindings.Name.inputValue}"
label="#{row.bindings.Name.label}"
required="#{bindings.LetterUIConfig1.hints.Name.mandatory}"
shortDesc="#{bindings.LetterUIConfig1.hints.Name.tooltip}"
id="soc1">
<f:selectItems value="#{yourBean.selectItemList}"
id="sadsadsa"/>
</af:selectOneChoice>

Populating a listview contents with an array

I have created a function that would be able to place the array contents into a listview, Here is my progress so far.
<div id="MainPage" data-role="page" >
<div data-role="content">
RENAME
</div>
</div>
<div id="ViewPage" data-role="page" >
<div data-role="content">
<ul id="viewlist" data-role="listview" data-filter="true" data-filter-placeholder="Sample Contents" data-inset="true">
<!-- array contents goes here -->
</ul>
</div>
</div>
<script>
var sampleContent = new Array( );
displayArray( )
{
for(var scan=0; scan<sampleContent.length; detect++)
{
$('#viewlist').append('<li>' + sampleContent[scan] + '</li>');
}
}
</script>
My code works during the first press of the button but when i pressed it the second time, the list view becomes messed up.
Any help or advice will be glady accepted thanks in advance.
edited, i have figured out how to do it but I am having problems during the second press of the button.
First of i don't want to be rude but i think you should start first to read some basics about android.
Like:
Android Activities , life cycle of activities
Layout in Android (how to add button on an activity then respond to a click etc) , different existing Layout in android and android widget (like the listView for example)
of course there are a lot more to read but it s a good way to start.
However i will provide you codes that will do what you are asking for and i will try to explain as much as i can
First of all you need to create the other activity and inside the layout of that activity insert a listview
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/listView"
android:layout_gravity="center_horizontal" />
</LinearLayout>
then the java code of the other activity will look like this
public class MainActivity2 extends Activity {
//create the array adapter that will input your array and convert it into a list of view
ArrayAdapter<String> arrayAdapter;
String[] list;
ListView listView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
listView = (ListView)findViewById(R.id.listView);
// get the array from ressource and insert them on an array
list = getResources().getStringArray(R.array.listArray);
// then create the arrayadpater with input your array of string if you dont get //anything here just read android documentation about arrayAdapter
arrayAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,list );
//then set the adapter to your listView
listView.setAdapter(arrayAdapter);
}
}
res xml file
<resources>
<string-array name="listArray">
<item>Apple</item>
<item>Banana</item>
<item>Cherry</item>
<item>Cranberry</item>
<item>Grape</item>
<item>Grape</item>
</string-array>
</resources
>
Hope it will help
Just add .listview('refresh') after you have added all items.
$('#viewlist').listview('refresh');
If you want to empty the list each time and refill it, call .empty() before the for loop:
$('#viewlist').empty();
To use better jquery mobile coding, structure your code like this:
Take the onclick out of the anchor tag and add an id:
<a id="viewPageBtn" href="#ViewPage" data-role="button" >RENAME</a>
In your script tag, handle pagecreate on the main page, and within it handle the click event of the anchor:
$(document).on("pagecreate", "#MainPage", function(){
var sampleContent = ["item 1", "item 2", "item 3"];
$("#viewPageBtn").on("click", function(){
$('#viewlist').empty();
for(var scan=0; scan < sampleContent.length; scan++)
{
$('#viewlist').append('<li>' + sampleContent[scan] + '</li>').listview('refresh');
}
$('#viewlist').listview('refresh');
});
});

How to implement "Cancel" functionality in a VisualForce Page

I know that this is how to save a record
<apex:commandButton action="{!save}" value="Save"/>
I want a button to NOT save the current record (ie. Cancel) and navigate to the list of saved record (ie. list of objects for that object type).
Something like this...
<apex:commandButton action="{!cancel}" value="Cancel"/>
The list view for an object is your base URL / the 3 letter prefix for your object / o, for example:
https://na1.salesforce.com/a0C/o
So you could just create an action method that returns a Pagereference with the appropriate URL and set to redirect (pr.setRedirect(true)).
Alternatively, you could use your controller as an extension to a standard controller, and just call cancel on the standard controller:
// controller extension
public class TimeSheetExtension
{
ApexPages.standardController m_sc = null;
public TimeSheetExtension(ApexPages.standardController sc)
{
m_sc = sc;
}
public PageReference doCancel()
{
return m_sc.cancel();
}
}
// page
<apex:commandButton action="{!doCancel}" value="Cancel"/>
Note that this doesn't necessarily take you to the list view, it'll return you to the last page you were viewing before going to the VF page.
You should also add the immediate tag to your Cancel button, so that the form doesn't run any validation before performing the Cancel operation.
<apex:commandButton action="{!cancel}" immediate="true" value="Cancel"/>
See http://blogs.developerforce.com/developer-relations/2008/12/using-the-immediate-attribute-on-commandlinks-and-commandbuttons.html
While applying cancel operation visualforce you should stop the form validation.Use below any one methods to stop the form validation based on your requirements.
Method 1:
Using
html-5 in doctype in visualforce page
means you should use html-formnovalidate and immediate in cancel button. For example
<apex:commandButton action="{!cancel}" value="Cancel" immediate="true"
html-formnovalidate="formnovalidate" />
Method 2:
you should use immediate key word only need for stopping form validation. For Example
<apex:commandButton action="{!cancel}" value="Cancel" immediate="true"/>
One of the other answers suggested calling the standard controller's cancel action so I want to expand on that since it led me in the direction to solve my similar problem.
If you want to cancel an edit as an ajax request without refreshing the whole page, declare the action as void and don't return the page reference, but still call the 'cancel' action on the standard controll. Make sure the command button specifies the rerender attribute.
// controller extension
public class TimeSheetExtension
{
ApexPages.standardController m_sc = null;
public TimeSheetExtension(ApexPages.standardController sc)
{
m_sc = sc;
}
public void doCancel()
{
m_sc.cancel();
}
}
// page
<apex:commandButton action="{!doCancel}" value="Cancel" rerender="container_id"/>

Resources