Skip to Main Content

Java Development Tools

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Go External URL - best way

Stuart FlemingMar 9 2016 — edited Mar 10 2016

Jdeveloper 12.1.2

I have a requirement to go to an external webiste.  I have found a number of ways to do this, but wonder which is best, in regards to:

1.  Whether it is considered a legacy way of doing it (or the method will be discontinued).

2.  Whether it is the most robust and predictable.

I am wondering of the three choices (I was able to find) which is the best one to use


  1. Button "Destination" set to value in Java


Java   

          private String goURL = “www.google.com” :
              public String getGoURL() { 

                   return “www.google.com” ;  

            }



JSF Page                             

<af:button text="destination...."

id="b2"                                   

                              partialSubmit="true"                                      

                           immediate="true"                                        

                          destination="#{backingBeanScope.myBean.goURL}"

                         targetFrame="_blank"/>




  1. Java Invoking JavaScript


JAVA 

  public String goURL() {
      String   url = “www.google.com” ;
        ExtendedRenderKitService erks = (ExtendedRenderKitService) Service.getRenderKitService(FacesContext.getCurrentInstance(), ExtendedRenderKitService.class);      

StringBuilder script = new StringBuilder();     

  script.append("window.open('" + url + "');");     

   erks.addScript(FacesContext.getCurrentInstance(), script.toString() );
        return null;    }


JSF


<af:button text="Update Personal Information"

id="b3"

targetFrame="_blank"

partialSubmit="true"

immediate="true"                                       

action="#{backingBeanScope.myBean.goURL}"/>



  1. JAVA invoking externalContext


JAVA

    public String  openURL(){

  String goURL = “www.google.com” :

       

        try{

             ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();

             externalContext.redirect(goURL );

         } catch(Exception e){

             throw new FacesException("Redirection failed");

         }

        return null ;

    }


JSF

       <af:button text="openURL"

            id="b3"

            targetFrame="_blank"

            partialSubmit="true"

             immediate="true"

            action="#{backingBeanScope.myBean.openURL}"/>



Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 7 2016
Added on Mar 9 2016
4 comments
507 views