Java Reference
In-Depth Information
<h:head>
<title>Object to JSON With the JSON-P Object Model API</title>
</h:head>
<h:body>
<h:form>
<h:panelGrid columns="2">
<h:outputLabel for="firstName" value="First Name"/>
<h:inputText id="firstName" value="#{person.
firstName}"/>
<h:outputLabel for="middleName" value="Middle Name"/>
<h:inputText id="middleName"
value="#{person.middleName}"/>
<h:outputLabel for="lastName" value="Last Name"/>
<h:inputText id="lastName" value="#{person.
lastName}"/>
<h:outputLabel for="gender" value="Gender"/>
<h:inputText id="gender" value="#{person.gender}"/>
<h:outputLabel for="age" value="Age"/>
<h:inputText id="age" value="#{person.age}"/>
<h:panelGroup/>
<h:commandButton value="Submit"
action="#{jsonPModelApiBean.generateJson()}"/>
</h:panelGrid>
</h:form>
</h:body>
</html>
As we can see, the preceding markup is very simple. It consists of a form with
several input text fields bound to properties in the Person CDI named bean. There is
also a command button that transfers control to the generateJson() method of the
JsonPModelApiBean class we discussed in the previous section.
Here is the source code for the Person bean:
package com.ensode.jsonpmodelapi;
import java.io.Serializable;
import javax.enterprise.context.SessionScoped;
import javax.inject.Named;
@Named
@SessionScoped
public class Person implements Serializable {
 
Search WWH ::




Custom Search