0

How can I call javabeans methods inside javascript functions?

I need with no success the following code:

        <script type="text/javascript">
            function openFullContent(chosen){
                #{bean.choseValue(chosen)};
            }
        </script>
1
  • As per your question history, you're familiar with JSF 2.0. Are you also using it for this project? Why aren't you using <f:ajax>? Commented Jun 23, 2011 at 20:47

2 Answers 2

1

The javabeans are running on the server, and the javascript is running on the client. JSF is rendering the javascript completely, then sending it as plain text to the browser over the wire. The two processes aren't even running on the same machine.

To communicate with the server like this, you need to look into Ajax.

Here's a JSF-centric Ajax tutorial.

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

2 Comments

Roseindia.. Shudder. Alone that link is already worth a giant downvote, but ala. As per the question history, OP is already using JSF2, which has with <f:ajax> builtin Ajaxical facilities.
Heh, sorry, I've no JSF-experience. Replaced with a link that's hopefully better. Thanks for letting me know. :-)
1

Primefaces remoteCommand is the thing you are looking for!

Comments

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.