<!-- f:metadata on this page -->
<f:metadata>
<f:viewParam name="b" value="#{viewParamJsonController.b}"/>
<f:viewParam name="l" value="#{viewParamJsonController.l}"/>
<f:viewParam name="ints" value="#{viewParamJsonController.ints}">
<pe:convertJson type="int[]"/>
</f:viewParam>
<f:viewParam name="chars" value="#{viewParamJsonController.chars}">
<pe:convertJson type="char[]"/>
</f:viewParam>
<f:viewParam name="s" value="#{viewParamJsonController.s}">
<pe:convertJson type="java.lang.String"/>
</f:viewParam>
<f:viewParam name="i" value="#{viewParamJsonController.i}"/>
<f:viewParam name="d" value="#{viewParamJsonController.d}">
<pe:convertJson type="java.util.Date"/>
</f:viewParam>
<f:viewParam name="list" value="#{viewParamJsonController.list}">
<pe:convertJson type="#{typesJsonController.typeGenericList}"/>
</f:viewParam>
<f:viewParam name="map" value="#{viewParamJsonController.map}">
<pe:convertJson type="#{typesJsonController.typeGenericMap}"/>
</f:viewParam>
<f:viewParam name="fooNonGeneric" value="#{viewParamJsonController.fooNonGeneric}">
<pe:convertJson type="org.primefaces.extensions.showcase.model.jsonconverter.FooNonGeneric"/>
</f:viewParam>
<f:viewParam name="fooGenericSimple" value="#{viewParamJsonController.fooGenericSimple}">
<pe:convertJson type="#{typesJsonController.typeGenericSimple}"/>
</f:viewParam>
<f:viewParam name="fooGenericComplex" value="#{viewParamJsonController.fooGenericComplex}">
<pe:convertJson type="#{typesJsonController.typeGenericComplex}"/>
</f:viewParam>
</f:metadata>
<h:panelGrid columns="2" columnClasses="formColumn" style="margin-bottom:15px;">
<h:outputText value="boolean" styleClass="bold"/>
<h:outputText value="#{viewParamJsonController.b}"/>
<h:outputText value="long" styleClass="bold"/>
<h:outputText value="#{viewParamJsonController.l}"/>
<h:outputText value="int[]" styleClass="bold"/>
<h:outputText value="#{viewParamJsonController.prettyInts}"/>
<h:outputText value="char[]" styleClass="bold"/>
<h:outputText value="#{viewParamJsonController.prettyChars}"/>
<h:outputText value="String" styleClass="bold"/>
<h:outputText value="#{viewParamJsonController.s}"/>
<h:outputText value="Integer" styleClass="bold"/>
<h:outputText value="#{viewParamJsonController.i}"/>
<h:outputText value="Date" styleClass="bold"/>
<h:outputText value="#{viewParamJsonController.d}"/>
<h:outputText value="Generic List" styleClass="bold"/>
<h:outputText value="#{viewParamJsonController.list}"/>
<h:outputText value="Generic Map" styleClass="bold"/>
<h:outputText value="#{viewParamJsonController.map}"/>
<h:outputText value="Non Generic" styleClass="bold"/>
<h:outputText value="#{viewParamJsonController.fooNonGeneric}"/>
<h:outputText value="Generic Simple" styleClass="bold"/>
<h:outputText value="#{viewParamJsonController.fooGenericSimple}"/>
<h:outputText value="Generic Complex" styleClass="bold"/>
<h:outputText value="#{viewParamJsonController.fooGenericComplex}"/>
</h:panelGrid>
<p:inputText id="inputUrl" value="#{viewParamJsonController.generatedUrl}" style="width:100%"/>
<p:commandButton value="Open Link" type="button" style="margin-top:15px;"
onclick="openLinkInPopup()"/>
<h:outputScript id="jsonConverterJS" target="body">
function openLinkInPopup() {
var inputValue = $('#inputUrl').val();
if (inputValue !== null) {
window.open(inputValue, 'Test JsonConverter with URL parameters',
'width=auto,height=auto,resizable=yes,scrollbars=yes,toolbar=yes,menubar=yes,location=yes');
}
}
</h:outputScript>
<h:outputStylesheet id="jsonConverterCSS">
table .formColumn {
padding-right: 10px;
text-align: right;
white-space: nowrap;
width: 1%;
}
.bold {
font-weight: bold;
}
</h:outputStylesheet>
@Named
@SessionScoped
public class TypesJsonController implements Serializable {
private static final long serialVersionUID = 1L;
public String getTypeGenericList() {
return "java.util.Collection<java.lang.Integer>";
}
public String getTypeGenericMap() {
return "java.util.Map<java.lang.String, org.apache.commons.lang3.tuple.ImmutablePair<java.lang.Integer, java.util.Date>>";
}
public String getTypeGenericSimple() {
return "org.primefaces.extensions.showcase.model.jsonconverter.FooGeneric<java.lang.String, java.lang.Integer>";
}
public String getTypeGenericComplex() {
return "org.primefaces.extensions.showcase.model.jsonconverter.FooGeneric"
+ "<int[], org.primefaces.extensions.showcase.model.jsonconverter.FooGeneric"
+ "<org.primefaces.extensions.showcase.model.jsonconverter.FooNonGeneric, java.lang.Boolean>>";
}
}
@Named
@ViewScoped
public class ViewParamJsonController implements Serializable {
private static final long serialVersionUID = 1L;
@Inject
private TypesJsonController typesJsonController;
private boolean b;
private long l;
private int[] ints;
private char[] chars;
private String s;
private Integer i;
private Date d;
private Collection<Integer> list = new ArrayList<Integer>();
private Map<String, ImmutablePair<Integer, Date>> map = new HashMap<String, ImmutablePair<Integer, Date>>();
private FooNonGeneric fooNonGeneric = new FooNonGeneric();
private FooGeneric<String, Integer> fooGenericSimple = new FooGeneric<String, Integer>();
private FooGeneric<int[], FooGeneric<FooNonGeneric, Boolean>> fooGenericComplex = new FooGeneric<int[], FooGeneric<FooNonGeneric, Boolean>>();
private String generatedUrl;
@PostConstruct
protected void initialize() {
// creates a builder instance by the current request URL
final RequestParameterBuilder rpBuilder = new RequestParameterBuilder(true);
try {
rpBuilder.param("b", true);
rpBuilder.param("l", 5000L);
rpBuilder.paramJson("ints", new int[] {1, 2, 3, 4, 5});
rpBuilder.paramJson("chars", new char[] {'x', 'y', 'z'});
rpBuilder.paramJson("s", "Hallo World");
rpBuilder.param("i", 99);
rpBuilder.paramJson("d", new Date());
final Collection<Integer> list = new ArrayList<Integer>();
list.add(11);
list.add(22);
list.add(33);
rpBuilder.paramJson("list", list, typesJsonController.getTypeGenericList());
final Map<String, ImmutablePair<Integer, Date>> map = new HashMap<String, ImmutablePair<Integer, Date>>();
GregorianCalendar calendar = new GregorianCalendar(2012, 1, 20);
map.put("cat", new ImmutablePair<Integer, Date>(1, calendar.getTime()));
calendar = new GregorianCalendar(2011, 6, 1);
map.put("dog", new ImmutablePair<Integer, Date>(2, calendar.getTime()));
calendar = new GregorianCalendar(1999, 10, 15);
map.put("unknow", new ImmutablePair<Integer, Date>(3, calendar.getTime()));
rpBuilder.paramJson("map", map, typesJsonController.getTypeGenericMap());
final FooNonGeneric fooNonGeneric = new FooNonGeneric();
fooNonGeneric.setCount(1001);
fooNonGeneric.setStartDate(new Date());
fooNonGeneric.setEndDate(new Date(fooNonGeneric.getStartDate().getTime() + 360000));
fooNonGeneric.addMessage("Message string 1");
fooNonGeneric.addMessage("Message string 2");
rpBuilder.paramJson("fooNonGeneric", fooNonGeneric);
final FooGeneric<String, Integer> fooGenericSimple = new FooGeneric<String, Integer>();
fooGenericSimple.setA("test");
fooGenericSimple.setB(25);
rpBuilder.paramJson("fooGenericSimple", fooGenericSimple, typesJsonController.getTypeGenericSimple());
final FooGeneric<int[], FooGeneric<FooNonGeneric, Boolean>> fooGenericComplex = new FooGeneric<int[], FooGeneric<FooNonGeneric, Boolean>>();
final FooNonGeneric fooNonGeneric2 = new FooNonGeneric();
fooNonGeneric2.setCount(909);
fooNonGeneric2.setStartDate(new Date());
fooNonGeneric2.setEndDate(new Date(fooNonGeneric.getStartDate().getTime() + 7200000));
fooNonGeneric2.addMessage("Message string 11");
fooNonGeneric2.addMessage("Message string 22");
final FooGeneric<FooNonGeneric, Boolean> fooGenericInnner = new FooGeneric<FooNonGeneric, Boolean>();
fooGenericInnner.setA(fooNonGeneric2);
fooGenericInnner.setB(false);
final int[] ints = {11, 22};
fooGenericComplex.setA(ints);
fooGenericComplex.setB(fooGenericInnner);
rpBuilder.paramJson("fooGenericComplex", fooGenericComplex, typesJsonController.getTypeGenericComplex());
}
catch (final UnsupportedEncodingException e) {
// handle exception ...
}
// build URL
generatedUrl = rpBuilder.build();
}
public String getGeneratedUrl() {
return generatedUrl;
}
public boolean isB() {
return b;
}
public void setB(final boolean b) {
this.b = b;
}
public long getL() {
return l;
}
public void setL(final long l) {
this.l = l;
}
public int[] getInts() {
return ints;
}
public String getPrettyInts() {
return Arrays.toString(ints);
}
public void setInts(final int[] ints) {
this.ints = ints;
}
public char[] getChars() {
return chars;
}
public String getPrettyChars() {
return Arrays.toString(chars);
}
public void setChars(final char[] chars) {
this.chars = chars;
}
public String getS() {
return s;
}
public void setS(final String s) {
this.s = s;
}
public Integer getI() {
return i;
}
public void setI(final Integer i) {
this.i = i;
}
public Date getD() {
return d;
}
public void setD(final Date d) {
this.d = d;
}
public Collection<Integer> getList() {
return list;
}
public void setList(final Collection<Integer> list) {
this.list = list;
}
public Map<String, ImmutablePair<Integer, Date>> getMap() {
return map;
}
public void setMap(final Map<String, ImmutablePair<Integer, Date>> map) {
this.map = map;
}
public FooNonGeneric getFooNonGeneric() {
return fooNonGeneric;
}
public void setFooNonGeneric(final FooNonGeneric fooNonGeneric) {
this.fooNonGeneric = fooNonGeneric;
}
public FooGeneric<String, Integer> getFooGenericSimple() {
return fooGenericSimple;
}
public void setFooGenericSimple(final FooGeneric<String, Integer> fooGenericSimple) {
this.fooGenericSimple = fooGenericSimple;
}
public FooGeneric<int[], FooGeneric<FooNonGeneric, Boolean>> getFooGenericComplex() {
return fooGenericComplex;
}
public void setFooGenericComplex(final FooGeneric<int[], FooGeneric<FooNonGeneric, Boolean>> fooGenericComplex) {
this.fooGenericComplex = fooGenericComplex;
}
public TypesJsonController getTypesJsonController() {
return typesJsonController;
}
public void setTypesJsonController(final TypesJsonController typesJsonController) {
this.typesJsonController = typesJsonController;
}
}