In my Facelets page I have a <div>
and that contains some input text boxes for user to enter values to submit. I will generate the PDF using this HTML source.
<div id="wrapper">
<h:form prependId="false">
<h:inputHidden id="source" value="#{bean.source}" />
<h:inputText id="fName" value="#{bean.firstName}"/>
<h:inputText id="lName" value="#{bean.lastName}"/>
<h:inputText id="age" value="#{bean.age}"/>
</h:form>
</div>
Like this I have other form fields too. When user enters all the data in the form and click on submit button I am getting the source inside this <div>
using JavaScript.
function getHtml() {
document.getElementById('source').value = document.getElementById('wrapper').innerHTML;
}
And passing to bean on click of submit.
<h:commandButton type="submit" id="appl-submit" action="#{bean.submit}"
value="Submit" onclick="javascript:getHtml();"/>
In the backing bean class
@ManagedBean
@SessionScoped
public class Bean{
private String firstName;
private String lastName;
private int age;
private String source;
// Getters and setters for all properties.
}
But I am only getting the form with empty input fields instead of HTML source along with user entered values. How can I get the HTML source along with form values?