0

I want to open a new JSF page that displays external, transformed HTML that I got via a string from a web service, attach my own submit buttons to the page and capture the form data for my own purpose (not submitting back to the web service). The purpose is to try and save me a lot of work by being able to call the web service and receiving transformed HTML back in the form of a string. How can I display this html in JSF? Using IFrame is not the answer.

Rick
  • 485
  • 6
  • 23
  • I'm looking at creating a custom JSF component that will "grab" the html from the URL and render it in a new window. – Rick Feb 20 '13 at 07:46
  • You can get the `String` from your web service call and write it in the JSF code using ``, still that won't work if your `String` contains `` and that kind of HTML, and the input components won't be bounded to JSF managed bean attributes. – Luiggi Mendoza Feb 20 '13 at 08:13

2 Answers2

1

You can always use simple javascript to do that, here you have an example using jquery:

Writing HTML with jQuery

Also; you will need to access your JSF components with the "jQquery object", try something like this:

How to refer to a JSF component Id in jquery?

Regards,

Community
  • 1
  • 1
Rodmar Conde
  • 956
  • 1
  • 12
  • 24
  • Thanks, Rodmar. I'm going to get the HTML from the URL with an HTTP request via a bean and push it to my view. – Rick Feb 20 '13 at 10:59
1
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.connect();
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String input = null;
    while ((input = in.readLine()) != null) {
        result = input;  //result is String
    }

and I return the result containing HTML to my backing bean.

I render the HTML on my view with f:verbatim

connection = (HttpURLConnection) url.openConnection();
        connection.setDoInput(true);
        connection.setUseCaches(false);
        connection.setAllowUserInteraction(false);
        connection.setRequestProperty("Accept-Charset", "UTF-8");
        connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
        connection.connect();
        InputStream in = new BufferedInputStream(connection.getInputStream());
        Scanner scanner = new Scanner(in, "UTF-8").useDelimiter("\\A"); // \\A regex ensures that I get the whole stream in one go - Match only at beginning of string (same as ^)
        while (scanner.hasNext()) {
            result += scanner.next();
        }
Rick
  • 485
  • 6
  • 23