1

I'm trying to do a form action where I show selected lists for each of some grouped values. After the user chooses a value in one of these lists I want to put the name of this object into a button link as a parameter but the parameter values are empty. I don't know how can I do it.

Here is my code for that:

In my controller:

@RequestMapping(value="/teacher/depts", method=RequestMethod.GET)
public String depts(Model model) {
    model.addAttribute("deptsfields", fieldOfStudyService.findAllFieldsForAllDepartments());
    model.addAttribute("field", new FieldOfStudy());

    return "teacher/depts";
}

@RequestMapping(value="/deptsfields", method=RequestMethod.POST)
public String deptsfields(@ModelAttribute(value="field") FieldOfStudy field) {
    return "teacher/depts";
}

And my html page:

<form action="#" th:action="@{/deptsfields}" th:object="${field}" method="post">
    <table>
        <tr>
            <th>Wydział</th>
            <th>Kierunek</th>
        </tr>

        <tr th:each="entry : ${deptsfields}">
            <td th:text="${entry.getKey().details.departmentFullName}"
                th:value="${entry.getKey().details.departmentFullName}"
                th:field="*{details.department.details.departmentFullName}"></td>
            <td>
                <select id="fieldslist" class="form-control" th:field="*{details.fieldOfStudyName}">
                    <option selected="selected" value="">Wybierz...</option>
                    <option th:each="field : ${entry.getValue()}" th:value="${field.details.fieldOfStudyName}" th:text="${field.details.fieldOfStudyName}"></option>
                </select>
            </td>

        </tr>
    </table>

    <a th:href="@{/teacher/groups(field=${field.details.fieldOfStudyName}, dept=${field.details.department.details.departmentFullName})}" class="btn btn-info" role="button">Dalej</a>
</form>

After click the button I'm redirected to this page:

http://localhost:8080/teacher/groups?field={here should be name but is empty}&dept={here should be name but is empty}

What I'm doing wrong?

1
  • 1
    Ok I solved this problem. If someone want to know, I change for normal sumbit button and in my controller I use RedirectAttributes as method parameters and add parameters whose I wanted in method redirectAttributes.addAttribute). It works. Commented Jan 20, 2017 at 20:27

1 Answer 1

4

You have an error in your link, try this

  <a th:href="@{'/teacher/groups?field=' + ${field.details.fieldOfStudyName} + '&dept=' + ${field.details.department.details.departmentFullName}}" class="btn btn-info" role="button">Dalej</a>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.