Access Java class in my JSP/JSF page and conditionally open a new browser

When the user clicks on a button in my JSP page, I'd like to launch a new browser and display certain things in that browser window while leaving the original browser window open.
My thought was to invoke a javascript method in 'onLoad' which would determine if the new window needs to be launched.
This is kinda what my page looks like:
<jsp:root version="1.2" ................>
    <jsp:directive.page import="java.util.*, com.test.Configuration" contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"/>
    <f:view>
     <ui:body binding="#{Page1.body1}" id="body1" onLoad="launchWindow();">     
     </ui:body>
   </f:view>
   <script type="text/javascript">
        function launchWindow(){
         if (Configuration.openWindow()) {
          window.open("hello.jsp", "newWindow", 'toolbar,width=400,height=400');            
    </script>     
</jsp:root>My problem is that the call to "Configuration.openWindow()" does not resolve correctly. If I remove that call and simply make a call to "window.open()" all works. But once I put the condition in, nothing happens. I do not see an exception in my browser window but a new browser window does not open.
Is my syntax correct. Can I make a call to the static method 'openWindow()' in my class 'Configuration.java'.
thanks,
tsc

I have made some changes so that I do not directly access the 'Configuration' class in my javascript.
I have a hidden field on my form and when the user clicks the button, in my back bean, I set a value for the hidden field. In the javascript function 'launchWindow()' I check if a value has been set for the hidden field and if yes, I open a new window.
<ui:body binding="#{Page1.body1}" id="body1" onLoad="launchWindow(document.forms[0]);">
<h:inputText id="hiddenField" value="#{formBean.hiddenValue}" />
<script type="text/javascript">
        function launchWindow(form){
            alert("in lw");
            var test = form["form1:hiddenField"].value;
            alert("got test");
            if (test !=  "")
                window.open("hello.jsp", "newWindow", 'toolbar,width=400,height=400');            
            alert ("done test");
</script>When my page is first loaded, the launchWindow() is called and all the alerts popup as expected.
When I click on the button (the back bean sets the value on the hidden field), my page is reloaded but this time its blank.
Any ideas as to why this maybe the case?
thanks,
tsc

Similar Messages

  • Conditionally opening a new browser window from a JSP page

    When the user clicks on a button in my JSP page, I'd like to launch a new browser and display certain things in that browser window while leaving the original browser window open. The new browser should only be displayed if certain conditions are met.
    My thought was to invoke a javascript method in 'onLoad' which would determine if the new window needs to be launched.
    This is kinda what my page looks like:
    <jsp:root version="1.2" ................>
        <jsp:directive.page import="java.util.*, com.test.Configuration" contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"/>
        <f:view>
         <ui:body binding="#{Page1.body1}" id="body1" onLoad="launchWindow();">     
         </ui:body>
       </f:view>
       <script type="text/javascript">
            function launchWindow(){
             if (Configuration.openWindow()) {
              window.open("hello.jsp", "newWindow", 'toolbar,width=400,height=400');            
        </script>     
    </jsp:root>
    My problem is that the call to "Configuration.openWindow()" does not resolve correctly. If I remove that call and simply make a call to "window.open()" all works. But once I put the condition in, nothing happens. I do not see an exception in my browser window but a new browser window does not open.
    Is my syntax correct. Can I make a call to the static method 'openWindow()' in my class 'Configuration.java'.
    I posted this same query on the JSF forum but received now replies. My question is more suited to the JSP forum and hence I'm posting this question here.
    thanks,
    tsc

    I have made some changes so that I do not directly access the 'Configuration' class in my javascript.
    I have a hidden field on my form and when the user clicks the button, in my back bean, I set a value for the hidden field. In the javascript function 'launchWindow()' I check if a value has been set for the hidden field and if yes, I open a new window.
    <ui:body binding="#{Page1.body1}" id="body1" onLoad="launchWindow(document.forms[0]);">
    <h:inputText id="hiddenField" value="#{formBean.hiddenValue}" />
    <script type="text/javascript">
            function launchWindow(form){
                alert("in lw");
                var test = form["form1:hiddenField"].value;
                alert("got test");
                if (test !=  "")
                    window.open("hello.jsp", "newWindow", 'toolbar,width=400,height=400');            
                alert ("done test");
    </script>When my page is first loaded, the launchWindow() is called and all the alerts popup as expected.
    When I click on the button (the back bean sets the value on the hidden field), my page is reloaded but this time its blank.
    Any ideas as to why this maybe the case?
    thanks,
    tsc

  • Is it possible to use two diff forms in same jsp/jsf page?

    Hi all,
    My requirement is to submit the form based on selection of radio button.
    since half part needs to be jsp based which is not using any tags etc.
    But i am trying to use some jsf based component which requires to be inside <f:view><h:form> of
    <%@ taglib prefix="f" uri="http://java.sun.com/jsf/core" %>
    <%@ taglib prefix="h" uri="http://java.sun.com/jsf/html" %>
    i.e. some <c:comboBox>
    </h:form> </f:view>
    Now earlier i was submitting the form as
    <form action="/techstacks-v2_1/reportAction.do" method="post" name=doSearch id='doSearch'>
    But now i found, in order to use combo box component which is entirely jsf based i need to use <f:view><h:form> which is kind of taking over the previous form submission mechiansm.
    I am trying to keep them separate as two differnt forms.
    one entirely jsp based and other as jsf based.
    Now my question is can i use such way of doing so or is there any better way of implementing so.
    My friend suggested that i can pass the value of jsf based form in hidden form to a input box of form to be submitted finally instead of submitteing two diff forms.
    but in that case also i ahev to use two forms in a single jsp/jsf page.
    suggest me something which can really work out.
    thanks
    vijendra

    You can use as many forms as you want as long as you don't nest forms. The HTML spec probibits that.

  • Unable to import a java class in a jsp file

    Hi,
    I am trying to import a java class in my jsp.
    ------------------jsp---------------
    <jsp:useBean id="form" class="com.company.portlets.searchApps.object.SearchOBJ" scope="request" />
    <jsp:setProperty name="form" property="*" />
    <input type="TEXT" name="projectID" value='<%= form.getProjectID() %>'>
    When I run the above JSP, it says that class 'com.company.portlets.searchApps.object.SearchOBJ' cannot be found.
    Why?
    My project structure looks like this:
    Project
    +Application Sources
    ++com.company.portlets.searchApps.object
    +++SearchOBJ.java
    +Web Content
    ++htdocs
    +++searchappsportlet
    ++++SearchAppsPortletShowPage.jsp
    ++WEB-INF
    +++index.jsp
    +Resources
    ++SearchApps.deploy
    Please advice...thanks!

    The way that JDeveloper organized the files was like this:
    C:\jdev1012\jdev\mywork\WksSearchApps\Project\classes\com\company\portlets\searchAPPS\object\SearchOBJ.class
    I am assuming that JDeveloper puts the file where they are suppose to be...if not, how do I change that?
    thanks,
    hussain

  • Accessing java classes from javascript

    Hi,
    I have the following javascript function
    function testjava {   
        var myString = new java.lang.String("Hello world"); // line 1
        alert("len:"+myString.length()); // line 2
    }It gives me a error at line 1 saying "'java' is undefined" in IE browser 5.5 sp2. But, both the lines execute correctly in netscape 6.
    Can someone please help..
    Thanks,
    Vijay.

    It seems that IE 5.5 doesn't support accessing java classes in JavaScript, so try to install IE 6 to see if it works or maybe, you doesn't have installed propertly support for JVM in IE.

  • How to open a new browser window from a JSP page?

    Hi,
    I am picking up records from the database and displaying each record in a seperate text area field using the JSP code. I should be able to display the content ( available in the text area) in a seperate window if the user clicks on one icon.
    Is it possible to open a new browser window using JSP? If yes, how can I write information on the new browser window?
    Thanks in advance.

    Is it possible to open a new browser window using JSP?a JSP page is also an HTML page, this is client side stuff, you can do it with JavaScript.

  • How do I get FF to focus on a new tab? I right-click and choose "Open in New Tab" and the Tab appears in the Tab bar but I cannot access or see the new page.

    I open FF ver.10. My Home page is Google Search. I use a Bookmark and open, say, Hulu.com. I select a link by right-clicking and choose "Open in New Tab" The little tab in the tab bar opens but I am still viewing the Hulu.com main page and cannot view the new tab.
    This happens even if I use middle-click to open a new tab. It happens with all links on any website I visit.

    Start Firefox in <u>[[Safe Mode]]</u> to check if one of the extensions or if hardware acceleration is causing the problem (switch to the DEFAULT theme: Firefox (Tools) > Add-ons > Appearance/Themes).
    *Don't make any changes on the Safe mode start window.
    *https://support.mozilla.org/kb/Safe+Mode
    *https://support.mozilla.org/kb/Troubleshooting+extensions+and+themes

  • Opening a new browser from jsp

    Hello All,
    I have a requirement in which i have to open a new browser when i click on a Submit button.
    In that browser a specific URL should run and then that browser should be closed.
    Does any one have any idea how to open a browser from jsp page?
    Thanks in advance

    You would need to use javascript, in firefox this would opena new tab, in IE it would open a new window. Google for window.open and you should find some examples of how to do this.

  • Open a new browser in Java?

    Like window.open("URI",...) in JavaScript, Any method in Java is available to open a new browser(window)?

    well u can acheive this by using 'target=_blank' in href tag whether you call href from servlet / jsp.
    Sonalp

  • I noticed when I restart Firefox 4, it opens my previous tabs even I set the option "Open a blank page" and it opens blank page when I have "Show my windows and tabs from last time". Please ignore my question if you're already aware of this issue. Thanks.

    I noticed when I restart Firefox 4, it opens my previous tabs even I set the option "Open a blank page" and it opens blank page when I have "Show my windows and tabs from last time". Please ignore my question if you're already aware of this issue. Thanks.

    Your previous tabs will not re-open or be available to re-open when starting Firefox if:
    *your previous session was in Private Browsing mode; see --> http://support.mozilla.org/en-US/kb/Private+Browsing
    *you use Clear Recent History (''Firefox button > History > Clear Recent History'' or ''Tools > Clear Recent History''); see --> https://support.mozilla.org/en-US/kb/Clear%20Recent%20History#w_how-do-i-clear-my-history
    *you clear History automatically when closing Firefox; see --> https://support.mozilla.org/en-US/kb/Clear%20Recent%20History#w_how-do-i-make-firefox-clear-my-history-automatically
    NOTE: Your third-party Plugins (Add-ons > Plugins) are not in the "Application Basics" (Troubleshooting Information) in the "More system details" of your original post. Third-party Plugins are categorized separately in "Installed Plugins" under "More system details". You should review but not change the Plugins as detected automatically by the software on this forum when posting a question.
    If you problem still exists after checking the above, the problem could be caused by one or more of your Extensions or Plugins:
    *See --> [http://support.mozilla.org/en-US/kb/Troubleshooting+extensions+and+themes Troubleshooting extensions and themes]
    *See --> [http://support.mozilla.org/en-US/kb/Troubleshooting+plugins Troubleshooting plugins]
    *See --> [http://support.mozilla.org/en-US/kb/Basic+Troubleshooting Basic Troubleshooting]
    '''If this reply solves your problem, please click "Solved It" next to this reply when <u>signed-in</u> to the forum.'''

  • Can only open one link at a time; any page in new tab will seem to load but appears blank. I have to open a new browser to go to a new page. Why?

    This just began to happen yesterday. I have a MacBook Pro 10.7.5.
    I can always get to the first page that I open in a new browser, but any page after that that I try to open in a new tab will seem to load but the page is blank.
    This does not just happen with one website I have tried myriad of different sites.. only the first tab loads in a new browser. I am having to open a new browser if i want to go to another link - very frustrating..

    Hi - This is Eddie from NTK.
    We just released an updated version handling the new Firefox Beta - please grab it from https://addons.mozilla.org/en-us/firefox/addon/new-tab-king/versions/
    Apologies for the bad experience. We're working hard to chase the never-ending Mozilla release train...
    --eddie

  • The main part of the safari page is grey and won't respond/can't type in any commands.  I can move back through the previous pages, and even open new ones via the URL, but can't get onto the main part of the page and I can't get onto the 9 page option. !?

    The main part of the safari page is grey and won't respond/can't type in any commands.  I can move back through the previous pages, and even open new ones via the URL, but can't get onto the main part of the page and I can't get onto the 9 page option. !?
    Help, please.

    Try clearing Safari's cache : Settings > Safari > Clear Cache (and Clear History)
    If that doesn't work then try closing Safari completely and then re-open it : from the home screen (i.e. not with Safari 'open' on-screen) double-click the home button to bring up the taskbar, then press and hold any of the apps on the taskbar for a couple of seconds or so until they start shaking, then press the '-' in the top left of the Safari app to close it, and touch any part of the screen above the taskbar so as to stop the shaking and close the taskbar.
    A third option is a reset : press and hold both the sleep and home buttons for about 10 to 15 seconds (ignore the red slider), after which the Apple logo should appear - you won't lose any content, it's the iPad equivalent of a reboot.

  • Have published iweb site for five years with no problems and just opened a new site and get - 404: Page not found  This error is generated when there was no web page with the name you specified at the web site.-is the problem with iweb or with hosting?  T

    I am sorry if thie is republished-My first time doing this and I am not sure what goes where and where to hear feedback.
    Have published iweb site for five years with no problems and just opened a new site and get -
    404: Page not found 
    This error is generated when there was no web page with the name you specified at the web site.-
    Troubleshooting suggestions:
    Ensure the page you are linking to exists in the correct folder.
    Check your file name for case sensitivity . Index.htm is not the same as index.htm!
    Temporarily disable any rewrite rules by renaming your .htaccess file if it exists
    is the problem with
    iweb or with hosting?
    One Apple tech started to fix Iweb and had to end session and the next said problem with hosting at Network Solutions as it published
    to local folder. NWS has checked sttting a few times-
    Any help would be extremely appreciated as trying to fix this for about five weeks
    Thanks VG
    <Email Edited by Host>

    It's a really bad idea to post your email address - it's an invitation to spam - and I've asked the Hosts to remove it. (Even though I've now noticed you mis-spelled it! - anyway, never post your address in a forum.)
    You have a site here: http://virginiagordon.com/www.virginiagordon.com/WELCOME.html
    If that's not the page you are having trouble with, what is that page's URL?

  • Added URL in Static Text To Open in New Browser Page

    Hi to all,
    We have added a static text with a url, to open in a new browser page. The url works as it opens in the current browser. But we would like to open in new browser page.
    we used a similar notation like the following in the static text:
    href=www.oracle.com
    target="_blank">Oracle</a>
    but this does not open in new browser.
    target="_blank" tag should open in new browser
    Does anyone have an idea what maybe happening.
    Edited by: KF~PTP on Feb 18, 2010 12:05 AM
    Edited by: KF~PTP on Feb 18, 2010 12:05 AM
    Edited by: KF~PTP on Feb 18, 2010 12:07 AM
    Edited by: KF~PTP on Feb 18, 2010 12:09 AM
    Edited by: KF~PTP on Feb 18, 2010 12:09 AM
    purposely left out <a tag from reference....as in my post....only the link was coming about.

    Introduce a "target=blank" into the HTML code!

  • TS2446 Trying to buy pages and numbers on my new macbook pro, and the apple store is asking me security questions of which I've never answered. It's indicating that my answers are wrong. Any help would me great!

    Trying to buy pages and numbers on my new macbook pro, and the apple store is asking me security questions of which I've never answered. It's indicating that my answers are wrong. Any help would me great!

    Welcome to the Apple Community.
    Contact Apple through iTunes Store Support

Maybe you are looking for

  • My apple ID has been disabled and I don't know why!

    I can't update my apps or download anything. what should i do?!

  • Best practice for developing with CRM 2013 (On Premises)

    Hello all.  I'm just starting to work with CRM, and I have some questions that hopefully will be simple for the seasoned developers.  It's mostly just some best practice or general how-to questions for the group. - When creating a new Visual Studio C

  • Camera connector and Samsung ST1000 - "too much power"?

    I purchased my iPad primarily to take on an overseas holiday so that I could access my email; and (ii) Download and manage photos off my Samsung St1000 digital camera. I also purchased the camera connector. However, whenever I try and connect the cam

  • Hide column, but show results.

    I am having trouble with hiding columns in BEx Analyser. The trick is not hiding the colomn, but hiding it and still showing the result. It is been a long time since someone answered a question of mine on the forums, so I hope this one isn't too diff

  • 22% discount still is appearing on my bill after one full year, why?

    I Was told by my salesman that after adding the new I Pad to my lines that I would receive the 22% discount. We'll, it has been a year, and after speaking to the manager of the South Asheville store (Omar), and being told by him that he would take ca