1

I have a JSF/primefaces managed bean.I am trying to pass managed bean variable to JavaScript function within the same managed bean but i am not successful. Can someone please help me in achieving this task.

My managed bean code snippet

reportName=report[0];
    url="http://cvgapp42q/Reports/Pages/Report.aspx?ItemPath=%2fLPSR%2f"+reportName;
    try {

        RequestContext.getCurrentInstance().execute("window.open('#{repBean.url}')");
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

url is the variable which i am trying to refer using the expression #{repBean.url} in the javascript function window.open()

Thanks in advance

2 Answers 2

1

just put your javascript code in a panel on your page:

<h:panelGroup id="scriptPanel">
    <script>
        window.open('#{repBean.url}');
    </script>
</h:panelGroup>

and update this panel after your ajax request, using update="scriptPanel" on your related primefaces component.

Sign up to request clarification or add additional context in comments.

Comments

0

Use

@ManagedProperty(value="#{repBean}")
RepBean repBean

and in your method

try {
    RequestContext.getCurrentInstance().execute("window.open('"+repBean.getUrl()+"')");
} catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

2 Comments

,thanks for the reply.repBean.getUrl() gets the url of the current page.But i am opening a new url cvgapp42q/Reports/Pages/Report.aspx..... as mentioned in the question.I just wanted to know how to pass variable url that holds url value to the js function so that the value is detectable and new web page is opened.
I don't know if I really understand what you want (it is probably because of my bad english). If you just want to open the url you can use `RequestContext.getCurrentInstance().execute("window.open('"+url+"')");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.