Theme
arya
luna-amber
luna-blue
luna-green
luna-pink
nova-dark
nova-light
saga
vela
JsonConverter
The following example shows how JsonConverter can be applied to RemoteCommand. This can be achieved with pe:assignableParam and attached pe:convertJson. JsonConverter only has one optional attribute "type". It specifies data type of the value object. Any primitive type, array, non generic or generic type is supported. Data type is sometimes required to convert a value to a 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>>"


- - -

Source

<p:growl id="growl" showDetail="true"/>

    <pe:remoteCommand id="applyDataCommand" name="applyData" process="@this" update="subject date circle growl"
                      actionListener="#{remoteCommandController.parametersAssigned}">

        <pe:assignableParam name="subject" assignTo="#{remoteCommandController.subject}"/>
        <pe:assignableParam name="date" assignTo="#{remoteCommandController.date}">
            <f:convertDateTime type="both" pattern="MM/dd/yyyy HH:mm:ss"/>
        </pe:assignableParam>
        <pe:assignableParam name="circle" assignTo="#{remoteCommandController.circle}">
            <pe:convertJson/>
        </pe:assignableParam>
    </pe:remoteCommand>

    <script type="text/javascript">
        circle = {
            radius: 50,
            backgroundColor: "#FF0000",
            borderColor: "#DDDDDD",
            scaleFactor: 1.2
        };
        circle2 = {
            radius: 32,
            backgroundColor: "#FF0320",
            borderColor: "#DDFFFD",
            scaleFactor: 1.6
        };
    </script>

    <h:outputLabel for="subject" value="Subject: "/>
    <h:outputText id="subject" value="#{remoteCommandController.subject}"/>
    <br/>
    <h:outputLabel for="date" value="Date: "/>
    <h:outputText id="date" value="#{remoteCommandController.date}"/>
    <br/>
    <h:outputLabel for="circle" value="Circle: "/>
    <h:outputText id="circle"
                  value="#{remoteCommandController.circle.radius} - #{remoteCommandController.circle.backgroundColor} - #{remoteCommandController.circle.borderColor} - #{remoteCommandController.circle.scaleFactor}"/>
    <br/><br/>

    <p:commandButton value="Apply Data" type="button" onclick="applyData('hello world', '05/14/2007 12:55:42', JSON.stringify(circle))"/>
    <p:commandButton value="Apply Second Data" type="button" onclick="applyData('hello user', '07/11/2001 11:55:42', JSON.stringify(circle2))"/>
            
Components and more
Documentation pe:convertJson
Attributes (move mouse over the names to see data types)
Name Description
type Data type of the value object (optional). Any primitive type, array, non-generic or generic type is supported. Data type is sometimes required to convert a value to a JSON representation. All data types should be fully qualified. Default is null.
PrimeFaces Extensions Showcase - © 2011-2023,PrimeFaces: 14.0.5,PrimeFaces Extensions: 14.0.5,JSF: Apache MyFaces JSF-2.3 Core Impl 2.3.10,Server: jetty/9.4.36.v20210114,Build time: 2024-09-10 21:01