开发者

Use the value entered in a JSF page for Java Applet

I have created a JSF pa开发者_JAVA百科ge which asks the user to enter a value, and this value is being processed via Applet and create a barcode image based on the inputted value. My problem is how can i get the value from the JSF Page and use it in my Applet.. Thanks!


Use JavaScript. E.g.

<h:inputText ... onchange="updateBarcodeApplet(this.value)" />
...
<applet id="barcodeApplet" ...></applet>

with this JS

<script>
    function updateBarcodeApplet(value) {
        var barcodeApplet = document.getElementById("barcodeApplet");
        barcodeApplet.updateValue(value);
    }
</script>

and in Applet

public void updateValue(String value) {
    // Do your business here.
}

(yes, all Applet's public methods are just available as is in JS)

Needless to say, using an applet for this job is pretty clumsy. Not all clients support or even appreciate applets. I'd also opt for a simple <img> element with a servlet which returns the image as suggested by Denisk. You just have to update the <img src> by JSF or JavaScript.


Why do you do it in a hard way? You don't really want an applet here, create the image on server, serialize it to response stream and display it as plain image.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜