Invalid property 'stCode' of bean class [java.lang.String]: Bean property 'stCode' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
Regist.jsp
<div class="container">
<div class="row centered-form">
<div class="col-xs-12 col-sm-8 col-md-4 col-sm-offset-2 col-md-offset-4">
<div class="panel panel-default">
<div class="panel-heading">
</div>
<div class="panel-body">
<f:form action="registSave" modelAttribute="r" method="post">
<div class="row">
<div class="col-xs-6 col-sm-6 col-md-6">
<div class="form-group">
State Name
</div>
</div>
<div class="col-xs-6 col-sm-6 col-md-6">
<div class="form-group">
<f:input path="stCode" class="form-control input-sm"/>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-6 col-sm-6 col-md-6">
<div class="form-group">
District Name
</div>
</div>
<div class="col-xs-6 col-sm-6 col-md-6">
<div class="form-group">
<f:input path="distCode" class="form-control input-sm"/>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-6 col-sm-6 col-md-6">
<div class="form-group">
Phone number
</div>
</div>
<div class="col-xs-6 col-sm-6 col-md-6">
<div class="form-group">
<f:input path="phone" class="form-control input-sm"/>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-6 col-sm-6 col-md-6">
<div class="form-group">
Name
</div>
</div>
<div class="col-xs-6 col-sm-6 col-md-6">
<div class="form-group">
<f:input path="name" class="form-control input-sm"/>
</div>
</div>
</div>
<!-- <div class="form-group">
<input type="email" name="email" id="email" class="form-control input-sm" placeholder="Email Address">
</div>
<div class="row">
<div class="col-xs-6 col-sm-6 col-md-6">
<div class="form-group">
<input type="password" name="password" id="password" class="form-control input-sm" placeholder="Password">
</div>
</div>
<div class="col-xs-6 col-sm-6 col-md-6">
<div class="form-group">
<input type="password" name="password_confirmation" id="password_confirmation" class="form-control input-sm" placeholder="Confirm Password">
</div>
</div>
</div> -->
<input type="submit" value="Register" class="btn btn-info btn-block">
</f:form>
</div>
</div>
</div>
</div>
</div>
RBean
package max.Bean;
public class RBean {
String stCode;
String distCode;
String phone;
String name;
public String getStCode() {
return stCode;
}
public void setStCode(String stCode) {
this.stCode = stCode;
}
public String getDistCode() {
return distCode;
}
public void setDistCode(String distCode) {
this.distCode = distCode;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Controller
package max;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import max.Bean.RBean;
#Controller
public class MainController {
#Autowired
RBean rBean;
#RequestMapping("home")
public String home()
{
return "registLayout";
}
#RequestMapping("regist")
public ModelAndView registration()
{
return new ModelAndView("reg","r","rBean");
}
#RequestMapping(value="registSave", method=RequestMethod.POST)
public ModelAndView registrationSave(#ModelAttribute("r") RBean rBean)
{
return new ModelAndView("reg","r","rBean");
}
}
if you are trying to set rBean into r variable which is available in view then you should remove the " used for rBean. Eg: return new ModelAndView("reg","r",rBean);
Related
This is my code
AdminAddProductComponent.php
<?php
namespace App\Http\Livewire\Admin;
use App\Models\Category;
use Livewire\Component;
use Illuminate\Support\Str;
use App\Models\Product;
use Livewire\WithFileUploads;
use Carbon\Carbon;
class AdminAddProductComponent extends Component
{
use WithFileUploads;
public $name;
public $slug;
public $short_description;
public $description;
public $regular_price;
public $sale_price;
public $SKU;
public $stock_status;
public $featured;
public $quantity;
public $image;
public $category_id;
public function mount()
{
$this->stock_status = 'instock';
$this->featured = 0;
}
public function generateSlug()
{
$this->slug = Str::slug($this->name,'-');
}
public function addProduct()
{
$product = new Product();
$product->name = $this->name;
$product->slug = $this->slug;
$product->short_description = $this->short_description;
$product->description = $this->description;
$product->regular_price = $this->regular_price;
$product->sale_price = $this->sale_price;
$product->SKU = $this->SKU;
$product->stock_status = $this->stock_status;
$product->featured = $this->featured;
$product->quantity = $this->quantity;
$imageName = Carbon::now()->timestamp.'.'.$this->image->extension();
$this->image->storeAs('products',$imageName);
$product->image = $imageName;
$product->category_id = $this->category_id;
$product->save();
session()->flash('message','Product has been created successfully!');
}
public function render()
{
$categories=Category::all();
return view('livewire.admin.admin-add-product-component',['categories'=>$categories])->layout('layouts.base');
}
}
admin-add-product-component.blade.php
<div>
<div class="container"style="padding:30px 0;">
<div class="row">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading">
<div class="row">
<div class="col-md-6">
Add New Product
</div>
<div class="col-md-6">
All Products
</div>
</div>
</div>
<div class="panel-body">
#if(Session::has('message'))
<div class="alert alert-success" role="alert">{{Session::get('message')}}</div>
#endif
<form class="form-horizontal" enctype="multipart/form-data"wire:submit.prevent="addProduct">
<div class="form-group">
<label class="col-md-4 control-label">Product Name</label>
<div class="col-md-4">
<input type="text" placeholder="Product Name" class="form-control input-md"wire:model="name"wire:keyup="generateSlug"/>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Product Slug</label>
<div class="col-md-4">
<input type="text" placeholder="Product Slug" class="form-control input-md"wire:model="slug"/>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Short Description</label>
<div class="col-md-4">
<textarea class="form-control" placeholder="Short Description"wire:model="short_description"></textarea>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Description</label>
<div class="col-md-4">
<textarea class="form-control" placeholder="Description"wire:model="description"></textarea>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Regular Price</label>
<div class="col-md-4">
<input type="text" placeholder="Regular Price" class="form-control input-md"wire:model="regular_price"/>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Sale Price</label>
<div class="col-md-4">
<input type="text" placeholder="Sale Price" class="form-control input-md"wire:model="sale_price"/>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">SKU</label>
<div class="col-md-4">
<input type="text" placeholder="SKU" class="form-control input-md"wire:model="SKU"/>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Stock</label>
<div class="col-md-4">
<select class="form-control"wire:model="stock_status">
<option value="instock">InStock</option>
<option value="outofstock">Out of Stock</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Featured</label>
<div class="col-md-4">
<select class="form-control"wire:model="featured">
<option value="0">No</option>
<option value="1">Yes</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Quantity</label>
<div class="col-md-4">
<input type="text" placeholder="Quantity" class="form-control input-md"wire:model="quantity"/>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Product image</label>
<div class="col-md-4">
<input type="file" class="input-file"wire:model="image"/>
#if($image)
<img src="{{$image->temporaryUrl()}}"width="120"/>
#endif
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Category</label>
<div class="col-md-4">
<select class="form-control"wire:model="category_id">
<option value="">Select Category</option>
#foreach ($categories as $category)
<option value="{{$category->id}}">{{$category->name}}</option>
#endforeach
</select>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label"></label>
<div class="col-md-4">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
I don't know why it's not working.. I mean the picture cant display on my Image show product page...
https://www.youtube.com/watch?v=IcGAM05UMwA&list=PLz_YkiqIHesvPtvLl2Wz5FtuW44dBt199&index=18&ab_channel=SurfsideMedia I follow this video<<< it just I dont know why my picture not showing out. it show the alt="picture" things
add use Livewire\Carbon; instead of usu carbo
I am working with Spring boot, Spring-data, ThymeLeaf. I have some fields. "Passenger Name", "Age", "Source", "Destination", "No of tickets", "Ticket Price", "Discount".
The following html code:
<div class="form-group has-error has-feedback" data-z="1b5278b0" id="passengerName1" data-th-classappend="${#fields.hasErrors('passengerName')}? 'has-error has-feedback'" data-th-class="form-group">
<label for="passengerName" class="col-md-3 control-label" data-th-text="#{label_ticketbooking_passengerName}">passengerName</label>
<div class="col-md-3">
<input id="passengerName" name="passengerName" data-th-value="*{{passengerName}}" type="text" class="form-control inputmask" placeholder="passengerName" data-th-placeholder="#{label_ticketbooking_passengerName}" data-toggle="tooltip" />
</div>
</div>
<div class="form-group has-error has-feedback" data-z="1b5278b0" id="age-field" data-th-classappend="${#fields.hasErrors('age')}? 'has-error has-feedback'" data-th-class="form-group">
<label for="age" class="col-md-3 control-label" data-th-text="#{label_ticketbooking_age}">age</label>
<div class="col-md-3">
<input id="age" name="age" data-th-value="*{{age}}" type="text" class="form-control inputmask" placeholder="age" data-th-placeholder="#{label_ticketbooking_age}" data-toggle="tooltip" data-inputmask-alias="numeric" data-inputmask-digits="0" min="1" />
</div>
</div>
<div class="form-group has-error has-feedback" data-z="1b5278b0" id="source1" data-th-classappend="${#fields.hasErrors('source')}? 'has-error has-feedback'" data-th-class="form-group">
<label for="source" class="col-md-3 control-label" data-th-text="#{label_ticketbooking_source}">source</label>
<div class="col-md-3">
<input id="source" name="source" data-th-value="*{{source}}" type="text" class="form-control inputmask" placeholder="source" data-th-placeholder="#{label_ticketbooking_source}" data-toggle="tooltip" />
</div>
</div>
<div class="form-group has-error has-feedback" data-z="1b5278b0" id="destination1" data-th-classappend="${#fields.hasErrors('destination')}? 'has-error has-feedback'" data-th-class="form-group">
<label for="destination" class="col-md-3 control-label" data-th-text="#{label_ticketbooking_destination}">destination</label>
<div class="col-md-3">
<input id="destination" name="destination" data-th-value="*{{destination}}" type="text" class="form-control inputmask" placeholder="destination" data-th-placeholder="#{label_ticketbooking_destination}" />
</div>
</div>
<div class="form-group has-error has-feedback" data-z="1b5278b0" id="noOfTickets-field" data-th-classappend="${#fields.hasErrors('noOfTickets')}? 'has-error has-feedback'" data-th-class="form-group">
<label for="noOfTickets" class="col-md-3 control-label" data-th-text="#{label_ticketbooking_noOfTickets}">noOfTickets</label>
<div class="col-md-3">
<input id="noOfTickets" name="noOfTickets" data-th-value="*{{noOfTickets}}" type="text" class="form-control inputmask" placeholder="noOfTickets" data-th-placeholder="#{label_ticketbooking_noOfTickets}" data-toggle="tooltip" aria-describedby="noOfTicketsStatus" data-inputmask-alias="numeric" data-inputmask-digits="0" min="1" />
</div>
</div>
<div class="form-group has-error has-feedback" data-z="ed99c550" id="ticketPrice-field" data-th-classappend="${#fields.hasErrors('ticketPrice')}? 'has-error has-feedback'" data-th-class="form-group">
<label for="ticketPrice" class="col-md-3 control-label" data-th-text="#{label_ticketbooking_ticketPrice}">ticketPrice</label>
<div class="col-md-3">
<input id="ticketPrice" name="ticketPrice" data-th-value="*{{ticketPrice}}" type="text" class="form-control inputmask" placeholder="ticketPrice" data-th-placeholder="#{label_ticketbooking_ticketPrice}" data-toggle="tooltip" />
</div>
</div>
<div class="form-group has-error has-feedback" data-z="d1a1d590" id="ticketdiscount-field" data-th-classappend="${#fields.hasErrors('ticketDiscount')}? 'has-error has-feedback'" data-th-class="form-group">
<label for="ticketDiscount" class="col-md-3 control-label" data-th-text="#{label_ticketbooking_ticketdiscount}">ticketDiscount</label>
<div class="col-md-3">
<input id="ticketDiscount" name="ticketDiscount" data-th-value="*{{ticketDiscount}}" type="text" class="form-control inputmask" placeholder="ticketDiscount" data-th-placeholder="#{label_ticketbooking_ticketdiscount}" data-toggle="tooltip" data-inputmask-alias="numeric" data-inputmask-digits="0" />
</div>
</div>
<div class="form-group has-error has-feedback" data-z="ed99c550" id="totalPrice-field" data-th-classappend="${#fields.hasErrors('totalPrice')}? 'has-error has-feedback'" data-th-class="form-group">
<label for="totalPrice" class="col-md-3 control-label" data-th-text="#{label_ticketbooking_totalPrice}">totalPrice</label>
<div class="col-md-3">
<input id="totalPrice" name="totalPrice" data-th-value="*{{totalPrice}}" type="text" class="form-control inputmask" placeholder="totalPrice" data-th-placeholder="#{label_ticketbooking_totalPrice}" data-toggle="tooltip" />
</div>
</div>
Here totalPrice should be calculated based on totalPrice = (noOfTickets * ticketPrice ) - ticketDiscount
Note: ticketDiscount may applicable or not. If applicable need to minus else no need to subtract it.
How can I achieve this?
There are several things you should take into account and several approaches you can use. Lets simplify things a little bit and suppose you have
Form DTO
#Data
public class TestDto {
private int ticketPrice;
private int noOfTickets;
private int ticketDiscount;
}
and Controller
#Controller
public class TestController {
#RequestMapping(name = "/", method = RequestMethod.GET)
public ModelAndView get() {
TestDto dto = new TestDto();
dto.setNoOfTickets(10);
dto.setTicketPrice(12);
return new ModelAndView("main", "dto", dto);
}
#RequestMapping(name = "/", method = RequestMethod.POST)
public String post(#ModelAttribute("dto") TestDto dto) {
System.out.println(dto);// can process input values
return "main";
}
}
Important. I assume you haveth:object="${dto}" in you form. If you don't, then just use dto.fieldName instead of fieldName like dto.ticketPrice instead of ticketPrice and $ instead of *
Option 1. Use Thymeleaf syntax. totalPrice will change after each form submit (POST request)
<form action="/" th:object="${dto}" method="post">
<input type="number" th:id="ticketPrice" th:field="*{ticketPrice}"/>
<input type="number" th:id="noOfTickets" th:field="*{noOfTickets}"/>
<input type="number" th:id="ticketDiscount" th:field="*{ticketDiscount}"/>
<span th:text="*{noOfTickets * ticketPrice - (ticketDiscount != 0 ? ticketDiscount: 0)}"
th:id="totalPrice"/>
<input type="submit" value="Subscribe!"/>
</form>
Option 2. Calculate value in java code POST changes to the server is also required to update the total value. Simple case can just use method with all the calculations in your DTO. This option works only if you have all the info for your calculations in this DTO
public class TestDto {
// ... same code as before
public int getTotalPrice() {
return noOfTickets * ticketPrice - (ticketDiscount != 0 ? ticketDiscount: 0);
}
}
This is easy to use just like any other field in your dto
<span th:text="*{totalPrice}"></span>
<span th:text="${dto.totalPrice}"></span>
<span th:text="*{getTotalPrice()}"></span>
If you need some extra info for your calculations, you probably can use service as suggested by #mrtasln. And for our simple case it can look like:
#Service("myService")
public class MyServices {
// Option 1
public int calculateTotal(MyDto dto){
return dto.getNoOfTickets() * dto.getTicketPrice() - (dto.getTicketDiscount() != 0 ? dto.getTicketDiscount(): 0);
}
// Option 2
public int calculateTotal2(int noOfTickets, int ticketPrice, int ticketDiscount){
return noOfTickets * ticketPrice - (ticketDiscount != 0 ? ticketDiscount: 0);
}
}
And xml part can be something like one of:
<span th:id="totalPriceFromService"
th:text="${#myService.calculateTotal(dto)}"></span>
<span th:id="totalPriceFromService2"
th:text="*{#myService.calculateTotal2(ticketPrice, noOfTickets, ticketDiscount)}"></span>
<span th:id="totalPriceFromService2"
th:with="tp=*{ticketPrice},nt=*{noOfTickets},td=*{ticketDiscount}"
th:text="${#myService.calculateTotal2(tp, nt, td)}"></span>
Option 3. The Javascript way is the only dynamic option to calculate changes. No need to perform POST to update the total value.
You can use some library to help you there, but simple case should
Define some JavaScript function like calculateTotal()
Put oninput="calculateTotal()" attribute on each input field you want to listen
Something like this:
<form action="/" th:object="${dto}" method="post">
<input type="number" th:id="ticketPrice" th:field="*{ticketPrice}" oninput="calculateTotal()"/>
<input type="number" th:id="noOfTickets" th:field="*{noOfTickets}" oninput="calculateTotal()"/>
<input type="number" th:id="ticketDiscount" th:field="*{ticketDiscount}" disabled="disabled"/>
<span th:id="totalPriceJS"></span>
<input type="submit" value="Subscribe!"/>
</form>
<script type="text/javascript">
function calculateTotal() {
var price = document.getElementById("ticketPrice").value;
var quantity = document.getElementById("noOfTickets").value;
var discount = document.getElementById("ticketDiscount").value;
var totalInput = document.getElementById("totalPriceJS");
//do all the calculations here
var total = price * quantity
if (discount) total -= discount;
totalInput.innerHTML = total
}
calculateTotal(); // don't forget to call this function on the first run
</script>
Try this calculation:
<div th: "${ticketDiscount !=null} ? result=${noOfTickets * totalPrice - ticketDiscount } : result=${noOfTickets * totalPrice}">
<span th:text="${result}"></span>
</div>
Here I am checking the value of ticketdiscount is null or not.
In Spring , you can do it with using service.Example code below :
Service class :
#Component("calculateService")
public class CalculateService {
public Integer calculateTotalPrice(Integer noOfTickets ,Integer ticketPrice, Integer ticketDiscount ){
return (noOfTickets * ticketPrice ) - ticketDiscount;
}
}
Html File :
<span th:text="${#calculateService.calculateTotalPrice(noOfTickets ,ticketPrice ,ticketDiscount)}"></span>
I'm trying to bind an edit action to a model which doesn't work. Here below the controller:
[Route("[controller]/[action]")]
public class CustomerController : Controller
{
private readonly IUnitOfWork _unitOfWork;
public CustomerController(IUnitOfWork unitOfWork)
{
_unitOfWork = unitOfWork;
}
[HttpGet("{_customerCode}")]
public IActionResult Edit(int _customerCode)
{
var customer = _unitOfWork.Customers.getCustomerByCode(_customerCode);
var customerDTO = Mapper.Map<CustomerModelDTO>(customer);
return View(customerDTO);
}
[HttpPost]
public IActionResult Edit(CustomerModelDTO model)
{
if (!ModelState.IsValid)
{
return View(model);
}
var _customer = _unitOfWork.Customers.getCustomerByCode(model.CustomerCode);
if (_customer==null)
{
return NotFound();
}
Mapper.Map(model, _customer);
_unitOfWork.Complete();
return RedirectToAction("Detail", new { customerCode = _customer.CustomerCode });
}
}
And here is the view I am using:
#model Almiz.Dtos.CustomerModelDTO
<form asp-action="Edit" method="post">
<div class="form-horizontal">
<h4>CustomerModelDTO</h4>
<hr />
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="CustomerCode" class="col-md-2 control-label"></label>
<div class="col-md-10">
<input asp-for="CustomerCode" class="form-control" />
<span asp-validation-for="CustomerCode" class="text-danger" />
</div>
</div>
<div class="form-group">
<label asp-for="FirstName" class="col-md-2 control-label"></label>
<div class="col-md-10">
<input asp-for="FirstName" class="form-control" />
<span asp-validation-for="FirstName" class="text-danger" />
</div>
</div>
<div class="form-group">
<label asp-for="MiddleName" class="col-md-2 control-label"></label>
<div class="col-md-10">
<input asp-for="MiddleName" class="form-control" />
<span asp-validation-for="MiddleName" class="text-danger" />
</div>
</div>
<div class="form-group">
<label asp-for="LastName" class="col-md-2 control-label"></label>
<div class="col-md-10">
<input asp-for="LastName" class="form-control" />
<span asp-validation-for="LastName" class="text-danger" />
</div>
</div>
<div class="form-group">
<label asp-for="Telephone" class="col-md-2 control-label"></label>
<div class="col-md-10">
<input asp-for="Telephone" class="form-control" />
<span asp-validation-for="Telephone" class="text-danger" />
</div>
</div>
<div class="form-group">
<label asp-for="Mobile" class="col-md-2 control-label"></label>
<div class="col-md-10">
<input asp-for="Mobile" class="form-control" />
<span asp-validation-for="Mobile" class="text-danger" />
</div>
</div>
<div class="form-group">
<label asp-for="Email" class="col-md-2 control-label"></label>
<div class="col-md-10">
<input asp-for="Email" class="form-control" />
<span asp-validation-for="Email" class="text-danger" />
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Save" class="btn btn-default" />
</div>
</div>
</div>
</form>
<div>
<a asp-action="Index">Back to Index</a>
</div>
#section Scripts {
#{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
}
When I call the view and with the ID http://localhost:65001/Customer/Edit/1001, I get the all the information. However when I edit it and post the edited form I get resource not found error. Please help. Here below the model:
public class CustomerModelDTO
{
public int CustomerCode { get; set; }
public string FirstName { get; set; }
public string MiddleName { get; set; }
public string LastName { get; set; }
public double Telephone { get; set; }
public double Mobile { get; set; }
public string Email { get; set; }
}
I got it working. Here below the change.
[HttpPost("{customerCode}")]
public IActionResult Edit(int customerCode, CustomerModelDTO data)
There are 3 one-to-many relationships into an entity Pta :
#Entity
#Table(name = "pta")
public class Pta {
#Id()
#SequenceGenerator(name="s_pta", sequenceName="pta.s_pta", allocationSize=1)
#GeneratedValue(strategy=GenerationType.SEQUENCE, generator="s_pta")
#Column(name="pta_code")
private Integer code;
#Column(name="pta_intitule")
private String lib;
#ManyToOne
#JoinColumn(name = "obj_code")
private Objectif objectif;
#ManyToOne
#JoinColumn(name = "struct_code")
private Structure structure;
#ManyToOne
#JoinColumn(name = "exer_code")
private Exer exercice;
public Pta() {
super();
}
public Pta(Integer code) {
super();
this.code = code;
}
// getters and setters
}
#Entity
#Table(name = "objectif")
public class Objectif {
#Id
#SequenceGenerator(name="s_objectif", sequenceName="pta.s_objectif", allocationSize=1)
#GeneratedValue(strategy=GenerationType.SEQUENCE, generator="s_objectif")
#Column(name = "obj_code")
private int code;
#Column(name="obj_intitule")
private String lib;
#ManyToOne
#JoinColumn(name = "prog_code")
private Programme programme;
#ManyToOne
#JoinColumn(name = "nat_obj_code")
private NatureObjectif nature_objectif;
public Objectif() {
super();
}
public Objectif(int code) {
super();
this.code = code;
}
public Objectif(int code, String lib) {
super();
this.code = code;
this.lib = lib;
}
// getters and setters
}
#Entity
#Table(name = "structure")
public class Structure {
#Id()
#Column(name="struct_code")
private String code;
#Column(name="struct_sigle")
private String sigle;
#Column(name="struct_lib")
private String lib;
public Structure() {
super();
}
public Structure(String code) {
super();
this.code = code;
}
// getters and setters
}
#Entity
#Table(name = "exercice")
public class Exer {
#Id()
#Column(name="exer_code")
private String exerCode;
#Column(name="exer_lib")
private String exerLibelle;
public Exer(){
super();
}
public Exer(String exer_code) {
super();
this.exerCode = exer_code;
}
// getters and setters
}
I want to insert a record into the Pta.
controller for page jsp :
modelView.addObject("exercices",exerDao.list());
modelView.addObject("structures",structureDao.list());
HashMap<String, String> criteres = new HashMap<String, String>();
criteres.put("nat_obj_code", "DdP");
modelView.addObject("docs_perf", objectifDao.lireParCritere(criteres));
criteres.clear();
criteres.put("nat_obj_code", "ODD");
modelView.addObject("odds", objectifDao.lireParCritere(criteres));
criteres.clear();
criteres.put("nat_obj_code", "PRO");
modelView.addObject("produits", objectifDao.lireParCritere(criteres));
modelView.addObject("action", request.getContextPath().concat("/elaboration/savePtaEtDetails"));
modelView.addObject("pta_formulaire", new Pta());
return modelView;
jsp :
<form:form cssClass="form-horizontal" servletRelativeAction="${action}" method="post" commandName="pta_formulaire">
<form:hidden path="code"/>
<div class="row">
<div class="col-sm-8">
<div class="form-group">
<label class="col-sm-4 control-label">Exercice</label>
<div class="col-sm-4">
<form:select path="exercice" cssClass="validate[required]">
<form:option value="" label=" -- Sélectionner -- "/>
<form:options items="${exercices}" itemValue="exerCode" itemLabel="exerLibelle" />
</form:select>
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label">Document de performance</label>
<div class="col-sm-4">
<form:select path="objectif" style="width:500px;" cssClass="validate[required]">
<form:option value="" label=" -- Sélectionner -- "/>
<form:options items="${docs_perf}" itemValue="code" itemLabel="lib" />
</form:select>
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label">ODD</label>
<div class="col-sm-4">
<select id="odd" name="odd" style="width:500px;">
<option value=""> -- Sélectionner -- </option>
<c:forEach items="${odds}" var="odd">
<option value="${odd.code}">${odd.lib}</option>
</c:forEach>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label">Axes du PND</label>
<div class="col-sm-4">
<select id="pnd" name="pnd" style="width:500px;" multiple></select>
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label">Programmes</label>
<div class="col-sm-4">
<select id="programme" name="programme" style="width:500px;" multiple></select>
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label">Effets</label>
<div class="col-sm-4">
<select id="effet" name="effet" style="width:500px;" multiple></select>
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label">Produits PMO</label>
<div class="col-sm-4">
<select id="produit" name="produit" style="width:500px;" multiple>
<option value=""> -- Sélectionner -- </option>
<c:forEach items="${produits}" var="produit">
<option value="${produit.code}">${produit.lib}</option>
</c:forEach>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label">Actions PMO</label>
<div class="col-sm-4">
<select id="action" name="action" style="width:500px;" multiple></select>
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label">Activité</label>
<div class="col-sm-4">
<select id="activite" name="activite" style="width:500px;">
<option value=""> -- Sélectionner -- </option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label">Résultat attendu</label>
<div class="col-sm-4">
<select id="resultat" name="resultat" style="width:500px;">
<option value=""> -- Sélectionner -- </option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label">Indicateur</label>
<div class="col-sm-8">
<select id="indicateur" name="indicateur" style="width:500px;">
<option value=""> -- Sélectionner -- </option>
</select>
</div>
</div>
<div class="form-group">
<div class="col-sm-12">
<fieldset>
<legend><label class="control-label">Programmation physique</label></legend>
<div class="row">
<div class="col-sm-3">
<div class="form-group">
<label class="col-sm-1 control-label">T1</label>
<div class="col-xs-10">
<input class="form-control" type="text" name="t1">
</div>
</div>
</div>
<div class="col-sm-3">
<div class="form-group">
<label class="col-sm-1 control-label">T2</label>
<div class="col-xs-10">
<input class="form-control" type="text" name="t2">
</div>
</div>
</div>
<div class="col-sm-3">
<div class="form-group">
<label class="col-sm-1 control-label">T3</label>
<div class="col-xs-10">
<input class="form-control" type="text" name="t3">
</div>
</div>
</div>
<div class="col-sm-3">
<div class="form-group">
<label class="col-sm-1 control-label">T4</label>
<div class="col-xs-10">
<input class="form-control" type="text" name="t4">
</div>
</div>
</div>
</div>
</fieldset>
</div>
</div>
<div class="form-group">
<div class="col-sm-12">
<fieldset>
<legend><label class="control-label">Programmation financière</label></legend>
<div class="row">
<div class="col-sm-12">
<div class="form-group">
<label class="col-sm-1 control-label">Montant</label>
<div class="col-xs-3">
<input class="form-control" type="text" name="progr_financiere">
</div>
</div>
</div>
</div>
</fieldset>
</div>
</div>
</div>
<div class="col-sm-4">
<div class="form-group">
<label class="col-sm-4 control-label">Structure</label>
<div class="col-sm-4">
<form:select path="structure" style="width:230px;" cssClass="validate[required]">
<form:option value="" label=" -- Sélectionner -- "/>
<form:options items="${structures}" itemValue="code" itemLabel="lib" />
</form:select>
</div>
</div>
</div>
<input class="btn btn-primary btn-sm" type="submit"/>
</form:form>
In the controller target :
#RequestMapping(value = "/savePtaEtDetails", method = RequestMethod.POST)
public ModelAndView savePtaEtDetails(#ModelAttribute("pta_formulaire") Pta pta, #RequestParam String exercice, #RequestParam int objectif,
#RequestParam String structure) {
System.out.println("eeeeeeeeeeeeeeee");
return new ModelAndView("redirect:/accueil");
}
At runtime when submitting the form then I got the error The request sent by the client was syntactically incorrect. So what is wrong ?
I found it :) The solution was to not set the attribute in the constructor of the "master" entities :
public Exer(String exer_code) {
super();
}
public Structure(String code) {
super();
}
public Objectif(String code) {
super();
}
Hi all i am trying to create one page which have relationship between client and Discharge. I have define one combo box which populate data of client form model and i want that client id in Discharge table but i am not getting value in back end if you inspect it in front end its look good but its null in back end so pls help me to solve this problem.
Here the code,
DischargeCard.java
#Entity
#Table(name = "Discharge_card")
public class DischargeCard {
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
#Column(name = "ID")
private int DischargeId;
#ManyToOne(cascade = {CascadeType.ALL})
#JoinColumn(name = "Client_id")
private Client Client_id;
#Column(name = "IPDNo")
private String ipdno;
#Column(name = "DOA")
private Date DOA;
#Column(name = "DOO")
private Date DOO;
#Column(name = "DOD")
private Date DOD;
#Column(name = "DOB")
private Date DOB;
#Column(name = "Age")
private int age;
#Column(name = "Sex")
private String sex;
#Column(name = "Phone")
private String phone;
#Column(name = "Address")
private String Address;
#Column(name = "Diagnosis")
private String diagnosis;
#Column(name = "Treatment")
private String treatment;
#Column(name = "Anesthesia")
private String anesthesia;
#Column(name = "Clinical_Presentation")
private String clinical_presentation;
#Column(name = "Investigation")
private String investigation;
#Column(name = "Given_Treatment")
private String given_treatment;
#Column(name = "Advice_on_Discharge")
private String advice;
< generates setter / getter >
Client.java
#Entity
#Table(name = "CLIENT")
public class Client {
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
#Column(name = "ID")
int clientId;
#NotEmpty(message = "Please Enter Client Name..." )
#Column(name = "Name")
String clientName;
#Column(name = "ContactName")
String contactName;
#NotEmpty(message = " Please Enter Client Address...")
#Column(name = "Address")
String clientAddress;
#NotEmpty(message = "Please Enter Client Phone...")
#Size (min = 10)
#Pattern (regexp = "[0-9]*")
#Column(name = "Phone")
String phone;
#Email (message = "Please Enter Proper Email Address of Client...")
#Column(name = "Email")
String email;
#NotEmpty (message = "Please Enter Client City...")
#Column(name = "City")
String city;
#NotEmpty (message = "Please Enter Client Zip Code...")
#Size (min = 6)
#Pattern (regexp = "[0-9]*")
#Column(name = "Zip")
String zip;
#NotEmpty(message = "Please Enter Client State...")
#Column(name = "State")
String state;
#NotEmpty (message = "Please Enter Client Country...")
#Column(name = "Country")
String country;
#Column(name = "Private")
String privateNote;
#Column(name = "Other")
String otherNote;
#ManyToOne
#JoinColumn(name = "Company_id")
private Company company;
#OneToMany(mappedBy = "Client_id")
private Set<Invoice> invoice;
#OneToMany(mappedBy = "Client_ID")
private Set<Estimate> estimate;
#OneToMany(mappedBy = "Client_id")
private Set<DischargeCard> discharges;
< generated setter / getter >
DischargeCardController.java
#Controller
public class DischargeCardController {
#Autowired
DischargeCardService ds;
#Autowired
ClientService service;
#RequestMapping(value = "/dishcharge", method = RequestMethod.GET)
public String showClientDetailsPage(Model m, HttpServletRequest req) {
m.addAttribute("dischargecard", new DischargeCard());
m.addAttribute("actionURL", "saveCard");
List<Client> obj = service.getAll("");
m.addAttribute("clientList", obj);
List<String> clientlist = new ArrayList<>();
for(Client c : obj)
{
clientlist.add(c.getClientName().toString());
}
m.addAttribute("client_name_list",clientlist);
return "dischargeCard";
}
#RequestMapping(value = "/saveCard", method = RequestMethod.POST)
public String saveCompanyDetails(#ModelAttribute("DischargeCard")DischargeCard dc, BindingResult result,
HttpServletRequest req) {
String redirectTo = "";
/*if(result.hasErrors())
{
redirectTo = "dischargeCard";
return redirectTo;
}
else
{*/
ds.saveData(dc);
redirectTo = "redirect:dishcharge";
return redirectTo;
}
#RequestMapping(value = "/searchDischargeCard", method = RequestMethod.GET)
public ModelAndView showUsersPage() {
ModelAndView mv = new ModelAndView("searchDischargeCard");
List<Client> obj = service.getAll("");
mv.addObject("clientList", obj);
List<String> clientlist = new ArrayList<>();
for(Client c : obj)
{
clientlist.add(c.getClientName().toString());
}
mv.addObject("client_name_list",clientlist);
mv.addObject("DischargeList",ds.getAll(""));
return mv;
}
}
DischargeCard.jsp
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%#taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%# taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%# taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<jsp:include page="header.jsp"></jsp:include>
<jsp:include page="menu.jsp"></jsp:include>
<!-- BEGIN Content -->
<div id="main-content">
<!-- BEGIN Page Title -->
<div class="page-title">
<div>
<h1>
<i class="fa fa-file-o"></i> Add Dishcharge Card
</h1>
<h4>Add data of new Discharge Card</h4>
</div>
</div>
<!-- END Page Title -->
<!-- BEGIN Breadcrumb -->
<div id="breadcrumbs">
<ul class="breadcrumb">
<li><i class="fa fa-home"></i> Home <span
class="divider"><i class="fa fa-angle-right"></i></span></li>
<li class="active">Discharge</li>
</ul>
</div>
<!-- END Breadcrumb -->
<div class="row">
<div class="col-md-12">
<div class="box box-pink">
<div class="box-title">
<h3>
<i class="fa fa-bars"></i> Discharge Card
</h3>
<div class="box-tool">
<a data-action="collapse" href="#"><i class="fa fa-chevron-up"></i></a>
<a data-action="close" href="#"><i class="fa fa-times"></i></a>
</div>
</div>
<div class="box-content">
<%-- <form action="#" > --%>
<form:form action="${actionURL}" class="form-horizontal"
id="wizard-validation" method="post"
modelAttribute="dischargecard">
<form:hidden path="DischargeId" id="DischargeId" />
<div class="form-wizard" id="form-wizard-2">
<ul class="row steps steps-fill">
<li class="col-xs-12 col-sm-6 col-lg-3"><a href="#tab2-1"
data-toggle="tab" class="step active"> <span class="number">1</span>
<span class="desc"><i class="fa fa-check"></i> Client
Details</span>
</a></li>
<li class="col-xs-12 col-sm-6 col-lg-3"><a href="#tab2-2"
data-toggle="tab" class="step"> <span class="number">2</span>
<span class="desc"><i class="fa fa-check"></i>
Treatment Details</span>
</a></li>
<li class="col-xs-12 col-sm-6 col-lg-3"><a href="#tab2-3"
data-toggle="tab" class="step"> <span class="number">3</span>
<span class="desc"><i class="fa fa-check"></i> Photo's</span>
</a></li>
<li class="col-xs-12 col-sm-6 col-lg-3"><a href="#tab2-4"
data-toggle="tab" class="step"> <span class="number">4</span>
<span class="desc"><i class="fa fa-check"></i> Confirm</span>
</a></li>
</ul>
<div class="progress progress-striped">
<div class="progress-bar progress-bar-primary"></div>
</div>
<div class="tab-content">
<div class="tab-pane active" id="tab2-1">
<div class="form-group">
<label for="firstname2"
class="col-sm-3 col-lg-2 control-label">Client Name</label>
<div class="col-sm-5 col-lg-3 controls">
<!-- <input type="text" name="firstname2" id="firstname2"
class="form-control" data-rule-required="true"> -->
<%-- <form:select path="Client_id"
class="form-control chosen" data-rule-required="true"
style="border-radius: 8px;"
data-placeholder="Choose a client" tabindex="1">
<option value=""></option>
<c:forEach var="client" items="${clientList}">
<form:option value="${client.clientId}">${client.clientName}</form:option>
</c:forEach>
</form:select> --%>
<form:select path="Client_id" items="${clientList}"
itemValue="clientId" itemLabel="clientName" />
</div>
</div>
<div class="form-group">
<label for="firstname2"
class="col-sm-3 col-lg-2 control-label">IPD Number</label>
<div class="col-sm-5 col-lg-3 controls">
<form:input path="ipdno" name="ipdno" type="text"
class="form-control" />
</div>
</div>
<div class="form-group">
<label class="col-sm-3 col-lg-2 control-label">Date of
Admission</label>
<div class="col-sm-5 col-lg-3 controls">
<form:input path="DOA" name="doa"
class="form-control date-picker" id="dp1" size="16"
type="text" value="" />
</div>
<div class="input-group col-sm-5 col-lg-2">
<a class="input-group-addon" href="#"><i
class="fa fa-clock-o"></i></a>
<form:input path="DOA" name="doa"
class="form-control timepicker-default" type="text" />
</div>
</div>
<div class="form-group">
<label class="col-sm-3 col-lg-2 control-label">Date of
Operation</label>
<div class="col-sm-5 col-lg-3 controls">
<form:input path="DOO" name="doo"
class="form-control date-picker" id="dp1" size="16"
type="text" value="" />
</div>
<div class="input-group col-sm-5 col-lg-2">
<a class="input-group-addon" href="#"><i
class="fa fa-clock-o"></i></a>
<form:input path="DOO" name="doo"
class="form-control timepicker-default" type="text" />
</div>
</div>
<div class="form-group">
<label class="col-sm-3 col-lg-2 control-label">Date of
Discharge</label>
<div class="col-sm-5 col-lg-3 controls">
<form:input path="DOD" name="dod"
class="form-control date-picker" id="dp1" size="16"
type="text" value="" />
</div>
<div class="input-group col-sm-5 col-lg-2">
<a class="input-group-addon" href="#"><i
class="fa fa-clock-o"></i></a>
<form:input path="DOD" name="dod"
class="form-control timepicker-default" type="text" />
</div>
</div>
<div class="form-group">
<label class="col-sm-3 col-lg-2 control-label">Date of
Birth</label>
<div class="col-sm-5 col-lg-3 controls">
<form:input path="DOB" name="dob"
class="form-control date-picker" id="dp1" size="16"
type="text" value="" />
</div>
</div>
<div class="form-group">
<label for="lastname2" class="col-sm-3 col-lg-2 control-label">Age</label>
<div class="col-sm-5 col-lg-3 controls">
<form:input path="age" name="Age" type="text" id="lastname2"
class="form-control" />
</div>
</div>
<div class="form-group">
<label class="col-sm-3 col-lg-2 control-label">Radio
Buttons</label>
<div class="col-sm-9 col-lg-10 controls">
<label class="radio-inline"> <form:radiobutton
path="sex" name="optionsRadios2" value="Male" /> Male
</label> <label class="radio-inline"> <form:radiobutton
path="sex" name="optionsRadios2" value="Female" /> Female
</label>
</div>
</div>
<div class="form-group">
<label for="firstname2"
class="col-sm-3 col-lg-2 control-label">Phone</label>
<div class="col-sm-5 col-lg-3 controls">
<form:input path="phone" name="Phone" type="text"
class="form-control" />
</div>
</div>
<div class="form-group">
<label class="col-sm-3 col-lg-2 control-label">Address</label>
<div class="col-sm-5 col-lg-5 controls">
<form:textarea path="Address" name="address"
class="form-control" rows="4"></form:textarea>
</div>
</div>
</div>
<div class="tab-pane" id="tab2-2">
<div class="form-group">
<label class="col-sm-3 col-lg-2 control-label">Diagnosis</label>
<div class="col-sm-5 col-lg-5 controls">
<form:textarea path="diagnosis" name="Diagnosis"
class="form-control" rows="4"></form:textarea>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 col-lg-2 control-label">Treatment</label>
<div class="col-sm-5 col-lg-5 controls">
<form:textarea path="treatment" name="Treatment"
class="form-control" rows="4"></form:textarea>
</div>
</div>
<div class="form-group">
<label for="firstname2"
class="col-sm-3 col-lg-2 control-label">Anesthesia</label>
<div class="col-sm-5 col-lg-3 controls">
<form:input path="anesthesia" name="Anesthesia" type="text"
class="form-control" />
</div>
</div>
<div class="form-group">
<label class="col-sm-3 col-lg-2 control-label">Clinical
Presentation</label>
<div class="col-sm-5 col-lg-5 controls">
<form:textarea path="clinical_presentation"
name="clinicalpresentation" class="form-control" rows="4"></form:textarea>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 col-lg-2 control-label">Investigation</label>
<div class="col-sm-5 col-lg-5 controls">
<form:textarea path="investigation" name="Investigation"
class="form-control" rows="4"></form:textarea>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 col-lg-2 control-label">Given
Treatment</label>
<div class="col-sm-5 col-lg-5 controls">
<form:textarea path="given_treatment" name="giventreatment"
class="form-control" rows="4"></form:textarea>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 col-lg-2 control-label">Treatment
Advice on Discharge</label>
<div class="col-sm-5 col-lg-5 controls">
<form:textarea path="advice" name="Advice"
class="form-control" rows="4"></form:textarea>
</div>
</div>
</div>
<div class="tab-pane" id="tab2-3">
<div class="form-group">
<label for="country2" class="col-sm-3 col-lg-2 control-label">Country</label>
<div class="col-sm-5 col-lg-3 controls">
<input type="text" name="country2" id="country2"
class="form-control">
</div>
</div>
<div class="form-group">
<label for="city2" class="col-sm-3 col-lg-2 control-label">City</label>
<div class="col-sm-5 col-lg-3 controls">
<input type="text" name="city2" id="city2"
class="form-control">
</div>
</div>
<%-- <div class="form-group">
<label class="col-sm-3 col-lg-2 control-label">Gender</label>
<div class="col-sm-5 col-lg-3 controls">
<label class="radio-inline">
<form:radiobutton path="sex" name="gender" value="Male" /> Male
</label> <label class="radio-inline">
<form:radiobutton path="sex" name="gender" value="Female" /> Female
</label>
</div>
</div> --%>
<div class="form-group">
<label for="textarea2" class="col-sm-3 col-lg-2 control-label">More
info</label>
<div class="col-sm-5 col-lg-3 controls">
<textarea name="textarea2" id="textarea2" rows="5"
class="form-control"></textarea>
</div>
</div>
</div>
<div class="tab-pane" id="tab2-4">
<div class="form-group">
<label class="col-sm-3 col-lg-2 control-label">First
Name</label>
<div class="col-sm-5 col-lg-3 controls">
<span class="text">Penny</span>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 col-lg-2 control-label">last
Name</label>
<div class="col-sm-5 col-lg-3 controls">
<span class="text">Rodrigez</span>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 col-lg-2 control-label">Gender</label>
<div class="col-sm-5 col-lg-3 controls">
<span class="text">Female</span>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 col-lg-2 control-label">Username</label>
<div class="col-sm-5 col-lg-3 controls">
<span class="text">PennyRod</span>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 col-lg-2 control-label">Email</label>
<div class="col-sm-5 col-lg-3 controls">
<span class="text">pennyrod#domain.com</span>
</div>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-9 col-sm-offset-3 col-lg-10 col-lg-offset-2">
Back Continue
<button type="submit" class="btn btn-success button-submit">Submit</button>
</div>
</div>
</div>
</form:form>
</div>
</div>
</div>
</div>
</div>
<!-- END Main Content -->
<jsp:include page="footer.jsp"></jsp:include>