Array of command objects

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Array of command objects

Unknown
Dear people

I am stuck for 2 hours right now and I almost throwed my laptop out of the window.

This is the controller

@RequestMapping
@Controller
public class SettingController {

    @RequestMapping(method = RequestMethod.GET)
    public String index(Model model, Principal principal) {
        ShopUser activeUser = (ShopUser) ((Authentication) principal).getPrincipal();
       
        model.addAttribute("items", activeUser.getUserSettings());
       
        return "settings";
    }
}

The items attribute is a set of UserSettings.

This is how i create my forms.

<div th:each="item: ${items}">
        <form th:object="${item}" th:action="@{/settings}" method="post">
                <fieldset>
                        <input type="text" th:value="${item.settingKey}" th:field="*{settingKey}" />
                </fieldset>
        </form>
</div>

Because I use ajax to save the settings, I have a form around every setting.

So I iterate over my items. That works well. The problem is the th:field. If I remove it, it works. But I want to bind the value with the object in the set... How can I achieve this?

Thanks in advance
Reply | Threaded
Open this post in threaded view
|

Re: Array of command objects

Zemi
Administrator
You should use either th:value or th:field, not the two at the same time.

If you write
       <input type="text" th:field="*{settingKey}" />
what is the generated HTML? value attribute is empty?

Reply | Threaded
Open this post in threaded view
|

Re: Array of command objects

Unknown
I get an eror then...

Error during execution of processor 'org.thymeleaf.spring3.processor.attr.SpringInputGeneralFieldAttrProcessor'
Reply | Threaded
Open this post in threaded view
|

Re: Array of command objects

Unknown
If I do it like this

<input type="text" th:value="*{settingKey}" />

The value is what I expect. But if I try to bind it with th:field I will get the error in my previous post.
Reply | Threaded
Open this post in threaded view
|

Re: Array of command objects

Zemi
Administrator
In reply to this post by Unknown
> If I do this
> <input type="text" th:value="*{settingKey}" />

No, you have to use th:field if you want to bind the field.

Which is the type of settingKey property? Is it a String?

Could you post the complete stack trace of the Exception?