Search code examples
muleanypoint-studiomulesoft

In mule 4, is there a way to grab the payload in html page using Load static resources connector to display the html with the payload?


I'm unable to display an array of strings from payload to the html page being loaded using the Load static resources connector. Is this possible or is there a better way of displaying the payload? I'm attempting to put the payload within a form tag with each string in the array being a checkbox.

<flow name="Flow">
    <http:listener doc:name="Listener" config-ref="HTTP_Listener_config" path="/*"/>
    <ee:transform doc:name="Transform Message" >
        <ee:message >
        </ee:message>
        <ee:variables >
            <ee:set-variable variableName="attributes" >
<![CDATA[%dw 2.0 output application/java ---
attributes]]></ee:set-variable>
        </ee:variables>
    </ee:transform>
    <flow-ref doc:name="Flow Reference" name="Flow1"/>
    <http:load-static-resource doc:name="Load static resource" resourceBasePath="src\main\resources\web\" attributes="#[vars.attributes]"/>
</flow>

HTML

<html>
<body>
<h1>data retrieval</h1>

<form action="#" method="POST">
    Objects:
    //loop each string in array 
    <input type="checkbox" name="objects" >
        <script>eval('(' + payload +')');</script>
    </input>
    <br/>
    <input type="button" name="Submit" value="Submit" id="submit"/>
</form>
</body>
</html>

Solution

  • The load static resource operation, as its name says, it for static resources that do not change dynamically, ie with data.

    The Parse Template operation seems to be what you are looking for. You can use DataWeave expressions inside the file.

    Example:

    Flow:

    <parse-template location="form.html" doc:name="Parse Template"/>
    

    HTML:

    <html>
        <body>
            <table>
             <tr>
                <td>#[payload['name']]</td>
                <td>#[payload['address']]</td>
             </tr>
            </table>
        </body>
    </html>