Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MVC redirect with variables doesn't work [SPR-10975] #15603

Closed
spring-projects-issues opened this issue Oct 9, 2013 · 2 comments
Closed

MVC redirect with variables doesn't work [SPR-10975] #15603

spring-projects-issues opened this issue Oct 9, 2013 · 2 comments
Assignees
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) in: web Issues in web modules (web, webmvc, webflux, websocket) status: invalid An issue that we don't feel is valid

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Oct 9, 2013

Igo opened SPR-10975 and commented

I have following Spring MVC 3.2.4 method:

@RequestMapping(value = "/products/{product}", method = RequestMethod.POST)
public String update(Product product, @Valid @ModelAttribute("productForm") ProductForm productForm, BindingResult bindingResult, Model model) {
    if (bindingResult.hasErrors()) {
        return "products/view";
    }
    mapper.map(productForm, product);
    productService.saveProduct(product);
    return "redirect:/products/{product}";
}

After success it should redirect back user to detail of product. Problem is that instead of redirecting to page "/products/1" I am redirected to page "/products/Product [code=1234567890, name=Nejaky]". It looks like placeholder {product} is replaced by product.toString() instead of original ID from URL. I am using built-in Spring Data 1.6.1 converter:

<mvc:annotation-driven conversion-service="conversionService">
    <mvc:argument-resolvers>
        <bean class="org.springframework.data.web.PageableHandlerMethodArgumentResolver" />
    </mvc:argument-resolvers>
</mvc:annotation-driven>

<bean id="conversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean" />

<bean class="org.springframework.data.repository.support.DomainClassConverter">
    <constructor-arg ref="conversionService" />
</bean>

Affects: 3.2.4

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Oct 10, 2013

Igo commented

Ok, finally found reason for this. I had to annotate product param with @PathVariable. Wondering that it worked without it.

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Oct 17, 2013

Rossen Stoyanchev commented

Without any annotations, by default the Product arg is considered a model attribute (i.e. as if annotated with @ModelAttribute).

@spring-projects-issues spring-projects-issues added type: bug A general bug status: invalid An issue that we don't feel is valid in: data Issues in data modules (jdbc, orm, oxm, tx) in: web Issues in web modules (web, webmvc, webflux, websocket) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues removed the type: bug A general bug label Jan 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) in: web Issues in web modules (web, webmvc, webflux, websocket) status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

2 participants