10

I'm using thymeleaf as template engine in my spring project.

My Problem is: I'm trying to submit my form to url that contains two variables, something like:

mysite/bla/{id}/bla/{id2} (two variables in url). So, I'm trying with this:

th:href="@{/bla/{id}/bla/{id2} (id=${object1.id}, id2=${object2.id})}"

The console shows the error:

"Skipping URI variable 'id' since the request contains a bind value with the same name." So, someone has any ideia whats happening?

Update:

I changed the path to one variable, just to make some tests, and the problem still happening. The controller is very simple:

@PostMapping(value = "/{id}/bla")
    public ModelAndView salvarBug(MyObject object,
            @PathVariable("id") Long idObject1, Principal principal) {
                objectService.save(object);
                return new ModelAndView("redirect:"+idObject1);
    }

I updated the link in html too:

        <form method="POST" th:object="${object}"
            th:action="@{/{id}/bla (id=${object.id})}">

The real problem: an attribute was going null for database. Make no sense in this. I fix this.

5
  • And the two blas are the same in your example? Commented Jun 28, 2017 at 14:58
  • No, just a example, they really have another name. Commented Jun 28, 2017 at 16:11
  • 1
    Can you post your controller code? The link looks correct to me. Commented Jun 28, 2017 at 16:33
  • I add the updates in description. Commented Jun 28, 2017 at 16:58
  • I found the problem: an attribute was going null for the database, make no sense in this. Commented Jun 28, 2017 at 17:40

3 Answers 3

5

Your solution uses the Standard Syntax and looks correct. You can try this workaround with concatenation:

<a th:href="${'/blah1/' + {object1.id} + '/blah2/' + {object2.id}}">some link</a>

UPDATE:

Try changing the name of the variable to something other than id. There's a JIRA about this that I suspect may be causing an issue. You can also annotate with @ModelAttribute. You should also make sure you're on the latest version of Spring.

Also, you can just do @PostMapping("/{id}/bla")

Sign up to request clarification or add additional context in comments.

Comments

5

Try this method. It worked for me

<a th:href="@{/this/istheurl(parameter1 = val1, parameter2 = val2) }">

Comments

1

The real problem: an attribute was going null for database. Make no sense in this. I fix this.

2 Comments

That's an unusual error message for a null attribute.
Yes, it was an array, I've never seen it happen before.

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.