Showing posts with label class. Show all posts
Showing posts with label class. Show all posts
Saturday, May 20, 2017
Local inner class in Java
Local inner class in Java
Local inner class is a class which is define local to the outer class. So it must be defined within the local scope of a class like method, constructor or initialization block . A class within a class in never treated as the local inner class. And most importantly scope of the inner class will be limited to where it is declared, outside of which it is not valid. As local inner class is the local scope to the outer class then we all know that within a local scope we cannot define any static member. So here also in the local inner class we cannot define any static member.
For the local inner class a .class file is generated in the following format :
< outer_class > $ < int_value > < inner class > .class
where as int_value depends on the number of times inner class with the same name is used.
Important points regarding Local inner class
1. We cannot define any static member in a local inner class as because of local scope.
2. But static final variable can be used because of its constant nature.
3. In the generated class file of local inner class the int value indicate that the local inner class has been used how many times in a single program with the same name.
4. We cannot use the local inner class with the same name in the same method, constructor or initialization block as like we cannot define local variable with the same name within the same block.
5. As we cannot define any static member so it cannot be the starting point of any java program.
6. We cannot create any object of local inner class outside the scope of that class.
Simple example to show the working of the local inner class :
For the local inner class a .class file is generated in the following format :
< outer_class > $ < int_value > < inner class > .class
where as int_value depends on the number of times inner class with the same name is used.
Important points regarding Local inner class
1. We cannot define any static member in a local inner class as because of local scope.
2. But static final variable can be used because of its constant nature.
3. In the generated class file of local inner class the int value indicate that the local inner class has been used how many times in a single program with the same name.
4. We cannot use the local inner class with the same name in the same method, constructor or initialization block as like we cannot define local variable with the same name within the same block.
5. As we cannot define any static member so it cannot be the starting point of any java program.
6. We cannot create any object of local inner class outside the scope of that class.
Simple example to show the working of the local inner class :
public class prog{
int x; // Outer class instance member
prog(){ //Outer class constructor
class B { // Local inner class
int x; // Local inner class instance member
B(){ // Local inner class constructor
System.out.println("Local inner class");
}
}
B b = new B(); // Local inner class object
class C{} // Local inner class
}
public static void main(String[] args) {
prog p = new prog();
}
}Available link for download
Wednesday, April 19, 2017
Making Related List without using Apex Class
Making Related List without using Apex Class
Hi All,
Here i want to give some sample code to show you how to make RelatedList on your VF page without using any Apex Code. There are two solutions for this problem.
1) Using <apex:relatedlist>
Suppose you have standard Case object and have one custom child object named "Child__c" to case. Then you can show your relatedlist on vf page using below code.
<apex:page standardController="Case">
<apex:relatedList list="Childs__r"/>
</apex:page>
The list will be displayed on your page but it always gives "Action" column also with "Edit | Del" links. If you want to get rid off that then you need to do a little jquery trick to remove that. See the below code.
<apex:page standardController="Case">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(#Childs a).attr(target,_blank);
});
</script>
<style>
.pbButton{
display:none;
}
.actionColumn{
display:none;
}
</style>
<Div id="Childs">
<apex:relatedList list="Childs__r"/>
</Div>
</apex:page>
The main issue i found using above approach of making list is that it depends on fields selected on page layout for that relatedlist. If you have added 2 fields on your layout, your vf will also show two fields. If you remove that related list from layout, then your vf will show only default fields ( name) only. So, in some sitations this solution is not perfect. For that reason, here is another solution.
3) Using relations objects iteration and Standard Tags.
Here is the other way to achieve your related list on vf page:
<apex:page standardController="Case">
<apex:sectionHeader title="http://www.aslambari.com" subtitle="Related List Example"/>
<apex:pageBlock>
<apex:pageBlockTable value="{!Case.Childs__r}" var="child">
<apex:column headervalue="Name"><apex:outputLink value="/{!child.id}">{!child.name}</apex:outputLink></apex:column>
<apex:column value="{!child.detail__c}"/>
<apex:column value="{!child.is_active__c}"/>
<apex:column value="{!child.createddate}"/>
<apex:column value="{!child.createdbyId}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>
http://labsprojects-developer-edition.ap1.force.com/apex/RelatedListSample?id=50090000000sW5q
The above way, you can customize your list as you want.
Hope It helps developers to find quick solution for related list.
Thanks
Aslam Bari
Available link for download
Subscribe to:
Posts (Atom)