sections.converters.jsonConverterVP.xhtml Maven / Gradle / Ivy
JsonConverter can be used for setting a value from an URL request parameter into a bean.
This can be achieved with f:viewParam and attached pe:convertJson.
Any primitive type, array, non generic or generic type is supported.
Use RequestParameterBuilder from PrimeFaces Extensions to build any URL parameters in JSON representation
and pe:convertJson to convert values back from JSON before they are set into bean.
This feature allows to pre-initialize any UI forms with defaul values passed in URL on initial page load (GET request).
Primitive, plain values don't need to be converted to / from JSON.
The attribute "type" in the pe:convertJson specifies data type of the value object.
Data type is sometimes required to convert a complex or generic value from the JSON representation.
All data types should be fully qualified. Examples:
- "boolean"
- "int"
- "long[]"
- "java.lang.String"
- "java.util.Date"
- "java.util.Collection<java.lang.Integer>"
- "java.util.Map<java.lang.String, com.prime.FooPair<java.lang.Integer, java.util.Date>>"
- "com.prime.FooNonGenericClass"
- "com.prime.FooGenericClass<java.lang.String, java.lang.Integer>"
- "com.prime.FooGenericClass<int[], com.prime.FooGenericClass<com.prime.FooNonGenericClass, java.lang.Boolean>>"
This example demonstrate using with primitive (like boolean and long), arrays (like int[] and char[]),
simple data types (like String and Integer), date (java.util.Date), parametrized collections and maps,
complex generic and non generic classes. Click on the button "Open Link" to see that values of URL parameters
are set into the bean on intial page load.
Attention: URLs longer than 2083 characters may not work properly in old IE versions.
Modern Firefox, Opera, and Safari can handle at least 80000 characters in URL.
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');
}
}
table .formColumn {
padding-right: 10px;
text-align: right;
white-space: nowrap;
width: 1%;
}
.bold {
font-weight: bold;
}
${showcase:getFileContent('/sections/converters/metadata.xhtml')}
${showcase:getFileContent('/sections/converters/jsonConverterVP.xhtml')}
${showcase:getFileContent('/org/primefaces/extensions/showcase/controller/jsonconverter/TypesJsonController.java')}
${showcase:getFileContent('/org/primefaces/extensions/showcase/controller/jsonconverter/ViewParamJsonController.java')}
${showcase:getFileContent('/org/primefaces/extensions/showcase/model/jsonconverter/FooGeneric.java')}
${showcase:getFileContent('/org/primefaces/extensions/showcase/model/jsonconverter/FooNonGeneric.java')}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy