ASP.NET MVC 3: HTTP Post parameter allways null after deployment - asp.net

I've created a small website in ASP.NET MVC 3, and it works fine in debugenvironment.
After deployment (on a https website) the website gives problems and after figuring a while, it seems that the HTTPPOST parameters are allways null ...
I'll provide some information:
the .cshtml:
#using (#Html.BeginForm("Registration", "Home", FormMethod.Post)){
<div id="middle">
<div id="radio">
#foreach (var item in Model)
{
<input type="radio" id="#string.Format("radio{0}", item.ID)" name="radio" value="#item.ID" /><label for="#string.Format("radio{0}", item.ID)">#item.Description</label>
}
</div>
<div id="divOverig">
<label for="overig">
Overig:</label>
<input style="float:right; width:70%;" type="text" id="overig" name="overig" />
</div>
</div>
<div id="end">
</div>
<div id="left">
#Html.ActionLink("Terug", "Device")
</div>
<div id="right">
<input type="submit" id="next" value="Naar apparaat informatie" />
</div>
}
The controller:
public ActionResult Problem(string radio, string overig){ ... }
In debug environment the parameters are correctly filled and passed. On the webserver the parameter is allways empty.
When I change the POST in GET is works fine, but I want to use the POST (later in the website I use complex types).
Anyone a brilliant idea?

This problem is caused by the secure environment (https).
I put the website on a normal environment (http) and it works flawless ;)
Thanx for you're time.

decorate the ActionResult with HttpPost
[HttpPost]
public ActionResult Registration(string radio, string overig){ ... }

Related

How to submit an exisitng object from the view via a from in Thymeleaf with Spring MVC?

In my Thymeleaf view, I have some objects shown on the page:
Here's the HTML
<form method="post" action="#" th:action="#{/basket}" th:object="${itemOrder}">
<div class="card-body">
<h4 class="card-title">
item title
</h4>
<h5 th:text="${item.price} + ' €'">item price</h5>
<input type="hidden" th:field="*{sku}"/> <br>
<input type="submit" value="Add to basket" />
</div>
</form>
<div class="container" th:if="${itemOrder != null}">
<h4>Item in the basket:</h4><br>
<h5 th:text="${itemOrder.price} + ' €'">item price</h5>
</div>
Under each element, I have a form to submit this element to the controller.
All Thymeleaf and Spring MVC guides are showing how to submit a form when a user provides data through input fields. Here, I don't need to take in any data from the user, all the data is available already. I just need to wrap existing data and submit it with a form. How can I make it with Thymeleaf and Spring MVC?
Here's the BasketController that should handle the form reu
#PostMapping("/basket")
public String processItemOrder(#ModelAttribute ItemOrder itemOrder, Model model) {
model.addAttribute("itemOrder", itemOrder);
return "basket";
}

How can I send list from view to controller (ASP.NET MVC)?

I want to make export file using
ActionResult Download(List<UserProjectPercentReportViewModel> percentsByProjectsAndUsers)
method. But I can not pass a parameter. I try to send it like this:
<div class="col-md-2">
<p> </p>
<p><input type="button" onclick="location.href='#Url.Action("Download",new { percentsByProjectsAndUsers=Model})'"
class="btn btn-info" value="Export" /></p>
</div>
But I get percentsByProjectsAndUsers.Count() == 0 in my method.
When I tried to send just string, it works, but I need to pass a List<>.

No mapping found for HTTP request with URI - No dispatcherservlet / servletmapping error

I know this is a common question but I'm getting desesperated here, Im pretty newbie and have been stuck with this for a long time now... I know this is not a DispatcherServlet or Servlet Mapping error as I'm working on a really big project that has everything working already.
What I need to do is add a form on an already existing jsp page, here is what I have
CONTROLLER:
#Controller
#RequestMapping("/messaging")
public class MessagingController {
#GetMapping
public String messagingView(Principal principal, Model model) throws ServiceException {
model.addAttribute("messagingInformation", new MessagingInformation());
return foo; -> this returns me to the main jsp where I'm creating the form
}
#PostMapping(value = "/submitInformation") -> I've also tried with #RequestMapping(value = "/submitInformation", method = RequestMethod.POST)
public String submitInformation(#ModelAttribute(value = "messagingInformation") #Valid MessagingInformation messagingInformation) {
return "redirect:/messaging"; -> shouldn't this redirect me to the main jsp?
}
}
JSP:
<form:form action="messaging/submitInformation" modelAttribute="messagingInformation" method="POST">
<div class="row col-sm-12 margin-top-container">
<div class="col-sm-4">
<span class="titles-select-box uppercase-text">RECEIVER</span>
<input name="receiver" type="email" id="receiverId" name="receiverName"
placeholder="Receiver" multiple>
</div>
</div>
<div class="col-sm-12 no-padding-left">
<div class="button-container pull-right">
<input type="submit" value="Send" class="btn btn-default"
id="sendButton" />
</div>
</div>
</form:form>
I'm mainly getting --No mapping found for HTTP request with URI [/foo/messaging/submitInformation] in DispatcherServlet -- I've asked around and I shouldn't add nothing to any cofiguration file or anything, clearly it's something wrong on my side but I can't see it
Leaving this in case anyone finds out... I was requiered to do a manual build so the java changes would show up. This is done through Projects -> Build All

Spring MCV 3 showErrors doesn't display anything

I try to validate a simple form. The validation is well executed but the result page doesn't display the errors.
I use velocity to render the page.
I've used as example the PetClinic project from spring website.
Here is my controller when I hit the "post form" button:
#Controller
#RequestMapping("/subscription")
public class SubscriptionController {
#RequestMapping(value = "/newCustomer", method = RequestMethod.POST)
public String processSubmit(#ModelAttribute Customer customer, BindingResult result, SessionStatus status) {
new CustomerValidator().validate(customer, result);
if (result.hasErrors()) {
return "subscription";
}
else {
status.setComplete();
return "redirect:/admin";
}
}
}
When I go in debug, I see the errors. I'm successfully redirected on the subscription page but the errors are not displayed.
My webpage (simplified):
...
#springBind("customer")
#springShowErrors("<br/>" "")
<form class="form-horizontal" method="post" action="#springUrl("/subscription/newCustomer/")">
....
<!-- Button -->
<div class="controls">
<button class="btn btn-primary">#springMessage("website.subscription.signup")</button>
</div>
</form>
...
if you need anything else, don't hesitate to tell me. Thanks for your help! I'm stuck on this since several days.
EDIT :
I finally found the error. It was with the springBind tag. I didn't well understand that you need to bind the field to show the associated error. Here is the fixed code for one field for twitter bootstrap framework.
#springBind("customer.name")
<div class="control-group #if(${status.error})error#end">
<!-- Prepended text-->
<label class="control-label">#springMessage("website.subscription.name")</label>
<div class="controls">
<div class="input-prepend">
<span class="add-on"><i class="icon-user"></i></span>
<input class="input-xlarge"
placeholder="John Doe" id="name" name="name" type="text">
</div>
<p class="help-block">
#springShowErrors("<br/>" "")
</p>
</div>
</div>
springShowErrors(...) will show all the errors associated with the field name of the POJO customer.

Spring 3 checkbox list objects have null properties

I may be hopelessly lost here, but having come from a MVC.NET world I cannot for the life of me figure this one out. I'm not getting any error messages, but all object properties submitted on a form submission are null. The objects themselves are not null, just their properties.
All I want to do is have a series of objects, represented by checkboxes on the form, after the forms submits. It's a little tricky as you can can see because of a nested list arrangement. The view renders perfectly on the GET request, but seems to forget everything when posted to the server. Does anyone have any examples of such a set-up? Could anyone suggest why all my objects loose their bindings?
My Controller:
#RequestMapping(value="/Search", method = RequestMethod.GET)
public String search(Model model)
{
Period periods = new Period();
SearchModel search = new SearchModel();
search.periods = periods.BuildPeriodList();
model.addAttribute("periods", periods.BuildPeriodList());
model.addAttribute(search);
return "search";
}
#RequestMapping(value = "/Search", method = RequestMethod.POST)
public String search(#ModelAttribute("searchModel") SearchModel search, BindingResult result)
{
System.out.println(Arrays.deepToString(search.periods));
return "search";
}
My View:
<div id="searchPage">
<div id="searchForm">
<form:form action="Search" method="post" modelAttribute="searchModel">
<h2>Search</h2>
<h2>Periods</h2>
<c:forEach items="${periods}" var="period" varStatus="index">
<form:checkbox path="periods[${index.count - 1}]" id="${period.name}" name="${period.name}" value="${period.name}"/>
<label for="${period.name}">${period.displayName}</label>
<div class="subPeriods">
<c:forEach items="${period.subPeriods}" var="subPeriod" varStatus="subIndex">
<form:checkbox path="periods[${subIndex.count - 1}].subPeriods" id="${subPeriod.name}" name="${subPeriod.name}" value="${period.name}"/>
<label for="${subPeriod.name}">${subPeriod.displayName}</label>
</c:forEach>
</div>
</c:forEach>
<div class="clear"></div>
<h2>Extras</h2>
<form:checkbox path="hasImage" name="hasImage" id="hasImage"></form:checkbox>
<label for="hasImage">Image</label>
<form:checkbox path="hasPaper" name="hasPapaer" id="hasPapaer"></form:checkbox>
<label for="hasPaper">Paper Data</label>
<form:checkbox path="hasExtended" name="hasExtended" id="hasExtended"></form:checkbox>
<label for="hasExtended">Extended Info</label>
<input type="submit" name="search" value="Search"></input>
</form:form>
</div>
<div id="searchResults">
</div>
<div class="clear"></div>
It's due to some of your checkboxes being bound to your "periods" model, while others being bound to your SearchModel model. The path attribute of the form:checkbox element tells how to bind the information.
Either include this within your SearchModel, or have another #ModelAttribute("periods") in your POST method.
I'd recommend sticking to one model, plus I'm not sure if you can have more than one #ModelAttribute in a controller method, something to try, though.

Resources