java - JavaFX WebView: Start Program, Input Data, Serve and Display Local HTML -> Refresh Data = Refresh WebView -


i need able open application, input data via textfields, send said data through freemarker , generate html, display in webview.

here i'm falling off.

i have working cannot, life of me, figure out how refresh webview display new current html doc after data input , rewrite.

it's overwriting file fine, if close , reopen, re click button, webview shows new data.

i'm sure issue i'm using getclass().getresource(string):

url link = getclass().getresource("emailsigtest.html"); engine = webview.getengine(); engine.load(link.tostring()); 

how can thing change dynamically, i.e:

1. input data 2. write file 3. refresh webview reflect new html doc 

where need write , read file , make happen?

i have tried engine.reload(); reload webengine... nothing.

i have tried adding actionevent , .reload()... nothing.

full source below:

public class signaturegenfxmldoccontroller implements initializable {     private string firstname, lastname, directline, title, cellphone, lineone, linetwo;     boolean social = false;     @fxml private textfield txtfirstname, txtlastname, txtdirectline, txttitle, txtcellphone;     @fxml private checkbox chksocialicons;     @fxml button btngenerate;     @fxml webview webview;     @fxml webengine engine;      @fxml private void handlebuttonaction(actionevent event) throws interruptedexception {         system.out.println("you clicked me!");         firstname = txtfirstname.gettext();         lastname = txtlastname.gettext();         directline = txtdirectline.gettext();         title = txttitle.gettext();         cellphone = txtcellphone.gettext();          writehtml();         readhtml();     }      @override     public void initialize(url url, resourcebundle rb) {      }     private void writehtml(){         // configurae freemarker     configuration cfg = new configuration();     try {         // load template         template template = cfg.gettemplate("src/signaturegen/template.ftl");         map<string, object> data = new hashmap<string, object>();              data.put("fname", firstname);             data.put("lname", lastname);             data.put("title", title);             data.put("dline", directline);             data.put("social", social);              writer console = new outputstreamwriter(system.out);             template.process(data, console);             console.flush();             // file output             writer file = new filewriter (new file("build/classes/signaturegen/emailsigtest.html"));             template.process(data, file);             file.flush();             file.close();         } catch (ioexception e) {             e.printstacktrace();         } catch (templateexception e) {             e.printstacktrace();         }     }          private void readhtml(){         url link = getclass().getresource("emailsigtest.html");         engine = webview.getengine();         engine.load(link.tostring());     } } 

as discussed in this question, reloading same url in webview not work.

what might want try delegating reload javascript in page itself. define function in page:

function reloadme() {   location.reload(); } 

and call function java:

private void readhtml(){     url link = getclass().getresource("emailsigtest.html");     engine = webview.getengine();     engine.executescript("reloadme();");  } 

further reading:


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -