隐藏字段值空白Thymeleaf [英] Hidden Field Value Blank Thymeleaf

查看:255
本文介绍了隐藏字段值空白Thymeleaf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个有两个隐藏领域的百里香形式。我使用th:value指定隐藏字段的值,并将这些字段绑定到对象。

 < div class =w-row> 
< div class =w-col w-col-6>
< div class =question_text_sc>
< p th:text =$ {questionVO.questionText}/>
< p th:text =$ {questionVO.questionStem}/>
< p th:text =$ {sequenceNo}/>
< p th:text =$ {quizID}/>
< / div>
< / div>
< div class =question_stem_sc>< / div>
< div class =w-col w-col-6>
< div>
< div class =w-form>
< div th:each =option:$ {questionVO.answerOptions}class =w-radio radio_selectth:id =$ {'radio_1'}>
< label class =w-form-labelid =answer_1for =radio>< p th:text =$ {option}/>< / label>
< / div>
< input type =hiddenname =sequenceNoth:field =* {sequenceNo}th:value =$ {sequenceNo}>< / input>
< input type =hiddenname =quizIDth:field =* {quizID}th:value =$ {quizID}>< / input>
< button class =button submit_answrtype =submit> Next问题< / button>
< / form>

我想将quizID和sequenceNo字段与对象中的各个字段绑定。第6行和第7行正确解析序列号/测验id的值并显示它。但是,表单中的th:value标记中未解析相同的值。该值为空,没有任何内容绑定到对象字段。





请在此寻求帮助。



编辑:



当我从隐藏元素中删除th:field属性时,但我想将它绑定到一个对象变量,以便服务器可以处理它。

解决方案

对于我帮助设置 th:field code $> $ <$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ code> th:value =$ {question.id}
th:attr =name ='questionIds ['+ $ {iter.index} +']'

在我的示例中,我想从 $ {question} 赋值,但输入的目标是 questionIDs [i]



简单的问题就像 name = answerId 应该足够。


I have a thymeleaf form which has 2 hidden fields. I specify the value of the hidden fields using th:value, and I bind these fields to an object.

<div class="w-row">
    <div class="w-col w-col-6">
        <div class="question_text_sc">
            <p th:text="${questionVO.questionText}" />
            <p th:text="${questionVO.questionStem}" />
            <p th:text="${sequenceNo}" />
            <p th:text="${quizID}" />
        </div>
    </div>
    <div class="question_stem_sc"></div>
    <div class="w-col w-col-6">
        <div>
            <div class="w-form">
                <form class="w-clearfix" id="email-form" name="email-form" data-name="Email Form" action="#" th:action="@{/quiz/question}" th:object="${userResponseVO}" method="post">
                    <div th:each="option: ${questionVO.answerOptions}" class="w-radio radio_select" th:id="${'radio_1'}">
                        <input class="w-radio-input" id="radio" type="radio" name="answer_sc" th:field="*{answerID}" th:value="${option}"/>
                        <label class="w-form-label" id="answer_1" for="radio"><p th:text="${option}" /></label>
                    </div>
                    <input type="hidden" name="sequenceNo" th:field="*{sequenceNo}" th:value="${sequenceNo}" ></input>
                    <input type="hidden" name="quizID"  th:field="*{quizID}" th:value="${quizID}"></input>
                    <button class="button submit_answr" type="submit">Next Question</button>
                </form>

I want to bind the quizID and sequenceNo fields with the respective fields in the object. Line 6 and 7 correctly resolve the value of sequence number/quiz id and display it. However, the same value is not resolved in the th:value tag inside the form. The value is empty and nothing gets bound to the object fields.

Request your help here.

EDIT:

The code works when I remove the th:field attribute from the hidden element. But I want to bind it to an object variable, so that the server can process it. `

解决方案

For me helped setting th:field (or actually name) using th:attr

th:value="${question.id}"
th:attr="name='questionIds[' + ${iter.index} + ']'"

In my example I wanted to have value from ${question} but the target in input is questionIDs[i]

In simple problem like your name=answerId should be enough.

这篇关于隐藏字段值空白Thymeleaf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆