provençal le breton
provençal le breton

Reputation: 1438

Spring MVC : tag form: not interpreted

I'm facing a probleme very disturbing.

I have a jsp, which display a form like this, and works perfectly fine.

<form:form action="${Form}" class="form-options" commandName="Form">

<div id="clonable" class="clonable">


                    <fieldset id="monfield">
                        <p>
                            Lien source :
                            <form:input id="urlSource_0" path="mesFormulaires[0].urlSource"
                                type="text" name="urlSource_0" />

                            <br />
                        </p>

                <p>
                    <input class="input" type="submit" value="Save" /> <br />
                </p>

            </form:form>

And, I have a button, which add another similar form, using javascript

<script>

    var formCount = 0;
        $(function() {

            $('.add').click(function() {
                formCount++;
                var template = "<fieldset id='field'>"
                + "<p>Lien source : "
                + "&lt;input id='urlSource_"+formCount+"' path='mesFormulaires["+formCount+"].urlSource' type='text' name='urlSource_"+formCount+"' /&gt;"
                + "<br /></p>"
                + "</fieldset>";
                template=template.replace(/&lt;/g,"<");
                template=template.replace(/&gt;/g,">");
                $(template).appendTo('#clonable');              
            });
        });
    </script>

But, when I add a new form in my page, I only have the text, and my "form:" aren't interpreted, so my generated form isn't working. And I need this for my form working.

Yes, I have this (regular question in other similar posts)

<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>

It is only the form: which don't work, because if i remove it, the form appears well.

Regards.

Thank you.

Upvotes: 0

Views: 355

Answers (1)

DeejUK
DeejUK

Reputation: 13471

The markup you're outputting in the JavaScript includes attributes that are from the Spring Form JSP tag (path).

The JavaScript is executed after the page has been rendered and sent to the client, so there's no way the Spring Form JSP tags can be executed to output the correctly bound value. The JSP tags only work before the page has been sent to the client, whilst it is still being rendered on the server.

Upvotes: 2

Related Questions