Passing unused fields from form

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Passing unused fields from form

 I would like to get unused properties back after posting form, how to get field orderIngredients binded?

public String newIngredientForm(Model model){

    Ingredient ingredient=new Ingredient();
    OrderIngredient orderIngredient=new OrderIngredient();

        return "ingredients/ingredientForm";
I've tried to pass this field orderIngredient to form and hide it, but it didn't work

<form th:object="${ingredient}" th:action="@{'/ingredients/new'}" method="post">
            <input type="hidden" th:field="*{orderIngredients}"/>

field of ingredient class: private Set<OrderIngredient> orderIngredients= new HashSet<>();

There was an unexpected error (type=Bad Request, status=400).
Validation failed for object='ingredient'. Error count: 1
org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 1 errors
Field error in object 'ingredient' on field 'orderIngredients': rejected value [null]; codes [typeMismatch.ingredient.orderIngredients,typeMismatch.orderIngredients,,typeMismatch]; arguments [ codes [ingredient.orderIngredients,orderIngredients]; arguments []; default message [orderIngredients]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Set' for property 'orderIngredients'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [java.lang.Long] for value 'null'; nested exception is java.lang.NumberFormatException: For input string: "null"]

How could I pass object containing Set<> attribute , so I could edit this Set, and how could I pass attributes unhindered when I don't want to edit them but just send them via form