Disable the Back Button in browser

Reuirment-To Disable the Browser Back Button you need to use java script code in your jsp page.

For example, You have Page 1 and Page 2 .And you are navigation from page1 to page 2.now you click on browser bck button.
We need to disable this thing.We will be writing a javascript code into the page 1.We will use forward method.Let check what does it do-

forward()– method loads the next URL in the history list.This is the same as clicking the Forward button in the browser.JavaScript window history forward method provides the functionality to navigate the user to the next page visited by him. Actually history forward method works only if the user navigates to the previous page using back button of browser of history back method provided by JavaScript. This back history navigation enables the forward history navigation. JavaScript History object belongs to JavaScript window object that allows you to access the forward method using window.history.forward. You can also access the forward method directly as history.forward.

<script type ="text/javascript">
function stopGoingBack()
{
window.history.forward();
}
</script>
<html>
    <head>
    <title> Using the forward method of the History object</title>
    </head>
    <body>
    <form name=form1>
    Click on the button to go to the forward browser page.
    <input type="button" value="Go Forward" onload='stopGoingBack()'>
    </form>
    </body>
    </html>

Call this method on onload on the body of page.

Happy coding with techartifact with Vinay . 🙂

Generate id using dbsequence in Oracle ADF Without Losing it .

Requirements: Populate Primary key or ID using dbsequence in Oracle ADF only during database commit

Solution: In my previous post of generating the sequence generating sequence in ADF ,previous post ,But the problem is you will lose sequence at time of error or cancel time.

Following changes to achieve this requirement

1. Go the entity and put a default value as some -999 or -9999 (This cant be your dbsequence value, preferably negative values)

2. Generate EntityImpl.class file and add below lines of code to the file at the end.

Note: Here we are overriding doDML() method of EntityImpl.class so that it will the get the value from db sequence just before commit to database.

    public void doDML(int operation, TransactionEvent e) {
        this.setEmployeeId((Integer)(new SequenceImpl("Vinaytableid_seq",getDBTransaction()).getSequenceNumber()).intValue());
        super.doDML(operation, e);
    }

Note2: it is not a mandatory rule to modify doDML() method only, you can use prepareForDML() method as well if you like. As doDML() is the last method that gets fired before beforeCommit() method, I preferred it.

3. In UI page, users don’t want to see any negative values initially, to show it as blank, just put an ELExpression to hide it whenever the value is negative.i.e
#{bindings.ContractId.inputValue == -1 ? ” : bindings.EmployeeId.inputValue}

Happy coding with techartifact

Why we can’t override the static method? or Overriding Vs Hiding

Can I override a static method? – No you cant

Many people have heard that you can’t override a static method. This is true – you can’t. However it is possible to write code like this:

class test {
    public static void method() {
        System.out.println("in test");
    }
}

class example extends test{
    public static void method() {
        System.out.println("in example");
    }
}

This compiles and runs just fine. Isn’t it an example of a static method overriding another static method? The answer is no – it’s an example of a static method hiding another static method. If you try to override a static method, the compiler doesn’t actually stop you – it just doesn’t do what you think it does.

lets try it

Briefly, when you override a method, you still get the benefits of run-time polymorphism, and when you hide, you don’t. So what does that mean? Take a look at this code:

class test{
    public static void classMethod() {
        System.out.println("classMethod() in test");
    }

    public void instanceMethod() {
        System.out.println("instanceMethod() in test");
    }
}

class example extends test {
    public static void classMethod() {
        System.out.println("classMethod() in example");
    }

    public void instanceMethod() {
        System.out.println("instanceMethod() in example");
    }
}
 
class Test {
    public static void main(String[] args) {
        test f = new example();
        f.instanceMethod();
        f.classMethod();
    }
}



If you run this, the output is

instanceMethod() in example
classMethod() in test

Now we should understand what is overriding and hiding-

Overriding
An instance method overrides all accessible instance methods with the same signature in superclasses [JLS 8.4.8.1], enabling dynamic dispatch; in other words, the VM chooses which overriding to invoke based on an instance’s run-time type [JLS 15.12.4.4]. Overriding is fundamental to object-oriented programming and is the only form of name reuse that is not generally discouraged:

class Base {
    public void f() { }
}

class Derived extends Base {
    public void f() { } // overrrides Base.f()
}

Hiding
A field, static method, or member type hides all accessible fields, static methods, or member types, respectively, with the same name (or, for methods, signature) in supertypes. Hiding a member prevents it from being inherited.

class Base {
    public static void f() { }
}

class Derived extends Base {
    public static void f() { } // hides Base.f()
}

Instance methods and class methods have this important difference in behavior, we use different terms – “overriding” for instance methods and “hiding” for class methods – to distinguish between the two cases. And when we say you can’t override a static method, what that means is that even if you write code that looks like it’s overriding a static method (like the first test and example at the top of this page) – it won’t behave like an overridden method.