Hi,
I am trying to create a kind of HTML form viewer using the BrowserFrame control but I am experiencing some difficulties. The main idea of our solution is that an administrator is allowed to create a template html form using a designer so that the users of the application will be able to fill-in this form and save the results in the database. You can think of our app as an embedded google forms-like system. According to our scenario the user selects a template and a new page is displayed - this page presents a new html form that is loaded into a BrowserFrame control. Our problem has to do with the fact that when the user fills in the form, we cannot get back the modified html content included into the BrowserFrame control. At the following example, we assume that we load the html form into a BrowserFrame control, the user enters some values in the form and using a button, we are trying to display into a textarea the new html content of the control. Unfortunately, the displayed content is always the same ignoring the data entered by the user. Please find below a sample of our code:
public class Formviewer extends Screen {
@Inject
BrowserFrame browserFrame;
@Inject
TextArea textArea;
@Inject
Button showContent;
@Subscribe
protected void onInit(InitEvent event) {
//Here, define the structure of the web form that is displayed to the user
//This structure will be usually stored in another database table
String htmlText ="<html>\n" +
" <head>\n" +
"............."
" </head>\n" +
" <body>\n" +
" <div id=\"form\"></div>\n" +
" <script type=\"text/javascript\">\n" +
" $(document).ready(function() {\n" +
" $(\"#form\").alpaca({\n" +
" ............"
" </body>\n" +
"</html>";
browserFrame.setSource(StreamResource.class)
.setStreamSupplier(()->new ByteArrayInputStream((htmlText).getBytes()))
.setMimeType("text/html");
showContent.addClickListener(e->{
try{
StreamResource resource = (StreamResource) browserFrame.getSource();
Supplier<InputStream> is = resource.getStreamSupplier();
BufferedReader r = new BufferedReader(new InputStreamReader(is.get(), StandardCharsets.UTF_8));
StringBuilder sb = new StringBuilder(8192);
String str = null;
while ((str = r.readLine()) != null)
{
sb.append(str);
}
String xx = sb.toString();
textArea.setValue(xx);
}
catch (IOException ioe){}
});
}
}
It seems that we are missing something regarding the usage of the BrowserFrame control. Do you have any idea about how we could implement this kind of functionality in CUBA.Platform? We are thinking of an alternative to post the data of the form into a REST service but we’d like to get the modified version of the form and store it into a database entry.
Thank you