I am not able to display the value in drop down. I am getting the below error when I try to display the newbFileNetStatus in drop down.
Error:
javax.el.ELException: Cannot convert G of type class java.lang.String to class java.lang.Long
JSP page:
[smm [newbID=4, planID=174, applID=18, taxqID=1, newbPolicyNo=551732891, newbEffectiveDate=null, newbIssueDate=null, newbDeliveryEMail=Admin#***.com, newbCreatedBy=C983990, newbFormsComment=document bharathi msss, newbFileNetStatus=D]]
<div class="formcontent">
<form method="post" action="update">
<c:forEach items="${filenetStatus}" var="filenetStatus">
<input type="hidden" name="newbID" value="${filenetStatus.newbID}" />
<div class="testimonials">
<div class="left">
<label>Plan ID</label>
</div>
<div class="right">
<input name="planID" type="text" value="${filenetStatus.planID}" />
</div>
</div>
<div class="testimonials">
<div class="left">
<label>New Policy Number</label>
</div>
<div class="right">
<input name="newbPolicyNo" readonly="readonly" type="text"
value="${filenetStatus.newbPolicyNo}" />
</div>
</div>
<div class="testimonials">
<div class="left">
<label>New Form Comment</label>
</div>
<div class="right">
<input name="newbFormsComment" type="text"
value="${filenetStatus.newbFormsComment}" />
</div>
</div>
<div class="testimonials">
<div class="left">
<label>Created By</label>
</div>
<div class="right">
<input name="newbCreatedBy" readonly="readonly" type="text"
value="${filenetStatus.newbCreatedBy}" />
</div>
</div>
<div class="testimonials">
<div class="left">
<label>Delivery Email</label>
</div>
<div class="right">
<input name="newbDeliveryEMail" type="text"
value="${filenetStatus.newbDeliveryEMail}" />
</div>
</div>
<div class="testimonials">
<div class="left">
<label>Delivery Email</label>
</div>
<div class="right">
<select class="dropmenu"
name="newbFileNetStatus">
<c:choose>
<c:when test="${filenetStatus.newbFileNetStatus =='G'}">
<option value="D">D</option>
<option value="C">C</option>
<option value="H">H</option>
<option value="S">S</option>
<option value="R">R</option>
<option value="${filenetStatus.newbFileNetStatus}" selected>G</option>
</c:when>
</c:choose>
</select>
</div>
</div> -
Related
i do jsp application and i have form who add evaluation in my jsp ListEvaluation.jsp
when i click on update button i want to display the value of my ListEvaluation in my updateform
here is what i do... its work for the input text but not for the button radio, select and date
<form id="form" method="post" action="/Labo2/ModifierServlet">
<div class="formulaire">
<h4>Formulaire pour modifier une évaluation</h4>
<hr />
<div class="form-group">
<label class="col-md-2 control-label">Numéro</label>
<div class="col-md-10">
<input type="text" id="numero" name="numero" value="<%=e.getNumero()%>" />
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label">Nom</label>
<div class="col-md-10">
<input type="text" id="nom" name="nom" value="<%=e.getNom()%>"/>
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label">Prénom</label>
<div class="col-md-10">
<input type="text" id="prenom" name="prenom" value="<%=e.getPrenom()%>"/>
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label">Téléphone</label>
<div class="col-md-10">
<input type="text" id="telephone" name="telephone" value="<%=e.getTelephone()%>"/>
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label">Courriel</label>
<div class="col-md-10">
<input type="text" id="courriel" name="courriel" value="<%=e.getCourriel()%>"/>
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label">Sexe</label>
<div class="col-md-10">
<input type="radio" value="F" id="sexe" name="sexe" />F
<input type="radio" value="M" id="sexe" name="sexe"/>M
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label">Note</label>
<div class="col-md-10">
<select id="note" name="note" value="<%=e.getNote()%>">
<option value=" "> </option>
<option value="tres bien">Trés bien</option>
<option value="bien">bien</option>
<option value="moyen">moyen</option>
<option value="mediocre">Médiocre</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label">Date d'évaluation</label>
<div class="col-md-10">
<input type="date" id="date" name="date" value="<%=e.getDateEvaluation()%>"/>
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label">Commentaire</label>
<div class="col-md-10">
<textarea id=commentaires" name="commentaires" value="<%=e.getCommentaire()%>"></textarea>
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Valider" class="butn" />
<input type="reset" value="Effacer" class="butn" />
<button class="butn">Retour à la liste</button>
</div>
</div>
</div>
</form>
how can i get values of my radio button and select?
thank you
I required input it's work but why invalid-feedback not show in modal
HTML use thymeleaf
<!-- AddStore Modal -->
<div class="modal fade" id="AddUserModal" tabindex="-1" role="dialog" aria-labelledby="deleteModalLabel"
aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="AddUserModalLabel">Add Store Form</h5>
<button class="close" type="button" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form autocomplete="off" action="#" th:action="#{/stores/add_store}"
th:object="${store}" method="post"
role="form" id="addModalForm">
<div class="form-row">
<div class="form-group col-md-6">
<label for="addstoreName">Store Name</label>
<input type="text" class="form-control" id="addstoreName" th:field="*{storeName}"
required="required"/>
<div class="invalid-feedback">
Please provide a store name.
</div>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6">
<label for="addStatus">Status</label>
<select id="addStatus" class="form-control" th:field="*{status}">
<option th:value="Ready_to_service">Ready to service</option>
<option th:value="Temporarily_closed">Temporarily closed</option>
<option th:value="Closed">Closed</option>
</select>
</div>
</div>
<div class="modal-footer">
<button class="btn btn-secondary" type="button" data-dismiss="modal">Cancel</button>
<button class="btn btn-success" type="submit" th:text="Save"></button>
</div>
</form>
</div>
</div>
</div>
</div>
Not sure if you found the solution or not as it looks like an old question.
You are missing to let Thymeleaf know about the field specific error. You havn't bind the invalid-feedback class to the "field" error. Try below piece of code.
<input type="text" class="form-control" id="addstoreName" th:field="*{storeName}" required="required"/>
<div class="invalid-feedback" th:if="${#fields.hasErrors('storeName')}" th:errors="*{storeName}"></div>
Take a look at the working example here. Here it will look like this:
here is my code, I have used this code in jsp now when i am using form tag it is showing--invalid location of tag (form)
<div class="col-sm-12">
<div id="collapseTwo" class="panel-collapse collapse">
<div class="panel-body classPadding">
<form role="form" id="js-upload-form" > //INVALID LOCATION OF TAG(FORM)
<div class="col-sm-8 md-pl-0">
<div class="form">
<div class="form-group">
<input type="file" onchange="loadFile(event)" name="econoDataFile" accept="image/*" id="js-upload-files">
</div>
<h5 id="id-text-setting">Upload an Image of size 192*192</h5>
<img id="output" src="" class="save-img" />
</div>
</div>
<div class="col-sm-4">
<button class="btn btn-sm btn-primary" type="submit" id="js-upload-submit">Save</button>
</div>
</form>
<div class="form-group col-md-6 md-pl-0">
<span>Send to a Segment</span> <select id="segment-name" class="form-control">
<option value="-1" >All Subscribers</option> </select>
</div>
</div>
</div>
</div>
I had the same error, in my case the problem was that I had the form nested inside another form
Hy I have a jsp with cv form with his fields:
<form:form commandName="cv" action="${pageContext.request.contextPath}/site/my-account/cv/save" id="cv-template-form" method="POST">
<h3><spring:message code="view.candidates.form.workExperience" /></h3>
<div id="workExperienceDiv">
<jsp:include page="/WEB-INF/views/site/commons/cv/workExperience.jsp"/>
</div>
<a href="javascript:void(0);" onclick="AjaxUtils.submitAttribute('${pageContext.request.contextPath}/site/my-account/cv/save/workExperience','workExperienceDiv');" class="btn btn-large btn-block btn-lightgray">
<spring:message code="button.labe.add.more"/>
</a>
<h3><spring:message code="view.candidates.form.education" /></h3>
<div id="educationDiv">
<jsp:include page="/WEB-INF/views/site/commons/cv/education.jsp"/>
</div>
<a href="javascript:void(0);" onclick="AjaxUtils.submitAttribute('${pageContext.request.contextPath}/site/my-account/cv/save/education','educationDiv');" class="btn btn-large btn-block btn-lightgray">
<spring:message code="button.labe.add.more"/>
</a>
Work experience jsp:
<%#taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%#taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%#taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<c:forEach var="workExperience" items="${cv.workExperiences}" >
<div class="row">
<label class="col-md-4"><spring:message code="view.candidates.form.workExperience.employer" /></label>
<div class="col-md-8">
<input value="${workExperience.employer}" id="employer" class="text block"/>
</div>
</div>
<div class="row">
<label class="col-md-4"><spring:message code="view.candidates.form.workExperience.period" /></label>
<div class="col-md-4">
<div class="datepicker">
<i class="fa fa-calendar"></i>
<input value="${workExperience.dateFrom}" class="text block date"/>
</div>
</div>
<div class="col-md-4">
<div class="datepicker">
<i class="fa fa-calendar"></i>
<input value="${workExperience.dateTo}" class="text date block"/>
</div>
</div>
</div>
<div class="row">
<label class="col-md-4"><spring:message code="view.candidates.form.workExperience.position" /></label>
<div class="col-md-8">
<input value="${workExperience.position}" id="position" type="text" class="text block"/>
</div>
</div>
<div class="row">
<label class="col-md-4"><spring:message code="view.candidates.form.workExperience.activities" /></label>
<div class="col-md-8">
<textarea class="textarea block">${workExperience.position}</textarea>
</div>
</div>
<div class="row">
<a class="editor_remove" href="#" onclick="AjaxUtils.submitAttribute('${pageContext.request.contextPath}/site/my-account/cv/delete/workExperience/${workExperience.tempId}');">
<i class="fa fa-times"></i>Remove
</a>
</div>
</c:forEach>
<div class="row">
<label class="col-md-4"><spring:message code="view.candidates.form.workExperience.employer" /></label>
<div class="col-md-8">
<form:errors id="employerError" path="workExperience.employer" cssClass="error"/>
<form:input path="workExperience.employer" id="employer" class="text block" cssErrorClass="text block error"/>
</div>
</div>
<div class="row">
<label class="col-md-4"><spring:message code="view.candidates.form.workExperience.period"/></label>
<div class="col-md-4">
<form:errors path="workExperience.dateFrom" cssClass="error"/>
<div class="datepicker">
<i class="fa fa-calendar"></i>
<form:input path="workExperience.dateFrom" cssClass="text block date" cssErrorClass="text block date error" placeholder="From"/>
</div>
</div>
<div class="col-md-4">
<div class="datepicker">
<form:errors path="workExperience.dateTo" cssClass="error"/>
<i class="fa fa-calendar"></i>
<form:input path="workExperience.dateTo" cssClass="text date block" cssErrorClass="text date block error" placeholder="To"/>
</div>
</div>
</div>
<div class="row">
<label class="col-md-4"><spring:message code="view.candidates.form.workExperience.position" /></label>
<div class="col-md-8">
<form:errors path="workExperience.position" cssClass="error"/>
<form:input path="workExperience.position" id="position" type="text" class="text block" cssErrorClass="text block error"/>
</div>
</div>
<div class="row">
<label class="col-md-4"><spring:message code="view.candidates.form.workExperience.activities" /></label>
<div class="col-md-8">
<form:errors path="workExperience.activities" cssClass="error"/>
<form:textarea path="workExperience.activities" cssClass="textarea block" cssErrorClass="textarea block error"/>
</div>
</div>
ajax function:
submitAttribute: function (url1,div){
$.ajax({
type: "POST",
url: url1,
data: $('#cv-template-form').serialize(),
cache: false,
success: function(data) {
$('#'+div).html(data);
Utils.Pikaday.init("input.date");
}
});
},
And education look like the workExperience jsp. Theoreticly I want to fill workExperience fields send it with ajax and put it in a workExperienceList and send back the list and a new workExperience. The problem is in ajax callback gives me an error cause he did not recognize the workExperience in workExperience.jsp.
This is the error:
SEVERE: Servlet.service() for servlet [spring-mvc-dispatcher] in context with path [/] threw exception [Request processing failed; nested exception is org.apache.tiles.request.render.CannotRenderException: ServletException including path '/WEB-INF/views/site/commons/cv/workExperience.jsp'.] with root cause
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'workExperience' available as request attribute
If i put a new form with commandName="cv" in workExperience.jsp it works fine but if I put in education that form to then he did not recognize first time, in java it comes null. I don`t want to put commandName="workExperience" in workExperience.jsp because if I want to save the big cv then he will not put the workExperience.jsp fields in cv object. Any solution?
I resolved it, its not so good but it is working fine I add a c:if if it is loaded first time with the big form then show it without workExperience form if it is returned from java the jsp page then show with workExperience form. Variable ajax is true just when the workExperience jsp page is returned from java. Now this is my workExperience form:
<%#taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%#taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%#taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<c:set var="index" value="0"/>
<c:if test="${ajax == true}">
<form:form commandName="cv">
<c:forEach var="workExperience" items="${cv.workExperiences}" >
<div class="row">
<label class="col-md-4"><spring:message code="view.candidates.form.workExperience.employer" /></label>
<div class="col-md-8">
<form:errors id="employerError" path="workExperiences[${index}].employer" cssClass="error"/>
<form:input path="workExperiences[${index}].employer" id="employer" class="text block" cssErrorClass="text block error"/>
</div>
</div>
<div class="row">
<label class="col-md-4"><spring:message code="view.candidates.form.workExperience.period"/></label>
<div class="col-md-4">
<form:errors path="workExperiences[${index}].dateFrom" cssClass="error"/>
<div class="datepicker">
<i class="fa fa-calendar"></i>
<form:input path="workExperiences[${index}].dateFrom" cssClass="text block date" cssErrorClass="text block date error" placeholder="From"/>
</div>
</div>
<div class="col-md-4">
<div class="datepicker">
<form:errors path="workExperiences[${index}].dateTo" cssClass="error"/>
<i class="fa fa-calendar"></i>
<form:input path="workExperiences[${index}].dateTo" cssClass="text date block" cssErrorClass="text date block error" placeholder="To"/>
</div>
</div>
</div>
<div class="row">
<label class="col-md-4"><spring:message code="view.candidates.form.workExperience.position" /></label>
<div class="col-md-8">
<form:errors path="workExperiences[${index}].position" cssClass="error"/>
<form:input path="workExperiences[${index}].position" id="position" type="text" class="text block" cssErrorClass="text block error"/>
</div>
</div>
<div class="row">
<label class="col-md-4"><spring:message code="view.candidates.form.workExperience.activities" /></label>
<div class="col-md-8">
<form:errors path="workExperiences[${index}].activities" cssClass="error"/>
<form:textarea path="workExperiences[${index}].activities" cssClass="textarea block" cssErrorClass="textarea block error"/>
</div>
</div>
<c:if test="${index < cv.workExperiences.size()-1 || cv.workExperiences[index].id != null}">
<a class="editor_remove" href="javascript:void(0);" onclick="AjaxUtils.submitAttribute('${pageContext.request.contextPath}/site/my-account/cv/delete/workExperience/${index}','workExperienceDiv');">
<i class="fa fa-times"></i><spring:message code="button.label.remove"/>
</a>
</c:if>
<c:set var="index" value="${index+1}"/>
</c:forEach>
</form:form>
</c:if>
<c:if test="${ajax != true}">
<c:forEach var="workExperience" items="${cv.workExperiences}" >
<div class="row">
<label class="col-md-4"><spring:message code="view.candidates.form.workExperience.employer" /></label>
<div class="col-md-8">
<form:errors id="employerError" path="workExperiences[${index}].employer" cssClass="error"/>
<form:input path="workExperiences[${index}].employer" id="employer" class="text block" cssErrorClass="text block error"/>
</div>
</div>
<div class="row">
<label class="col-md-4"><spring:message code="view.candidates.form.workExperience.period"/></label>
<div class="col-md-4">
<form:errors path="workExperiences[${index}].dateFrom" cssClass="error"/>
<div class="datepicker">
<i class="fa fa-calendar"></i>
<form:input path="workExperiences[${index}].dateFrom" cssClass="text block date" cssErrorClass="text block date error" placeholder="From"/>
</div>
</div>
<div class="col-md-4">
<div class="datepicker">
<form:errors path="workExperiences[${index}].dateTo" cssClass="error"/>
<i class="fa fa-calendar"></i>
<form:input path="workExperiences[${index}].dateTo" cssClass="text date block" cssErrorClass="text date block error" placeholder="To"/>
</div>
</div>
</div>
<div class="row">
<label class="col-md-4"><spring:message code="view.candidates.form.workExperience.position" /></label>
<div class="col-md-8">
<form:errors path="workExperiences[${index}].position" cssClass="error"/>
<form:input path="workExperiences[${index}].position" id="position" type="text" class="text block" cssErrorClass="text block error"/>
</div>
</div>
<div class="row">
<label class="col-md-4"><spring:message code="view.candidates.form.workExperience.activities" /></label>
<div class="col-md-8">
<form:errors path="workExperiences[${index}].activities" cssClass="error"/>
<form:textarea path="workExperiences[${index}].activities" cssClass="textarea block" cssErrorClass="textarea block error"/>
</div>
</div>
<c:if test="${index < cv.workExperiences.size()-1 || cv.workExperiences[index].id != null}">
<a class="editor_remove" href="javascript:void(0);" onclick="AjaxUtils.submitAttribute('${pageContext.request.contextPath}/site/my-account/cv/delete/workExperience/${index}','workExperienceDiv');">
<i class="fa fa-times"></i><spring:message code="button.label.remove"/>
</a>
</c:if>
<c:set var="index" value="${index+1}"/>
</c:forEach>
</c:if>
I am passing a value from a jsp page to bootstrap modal using jQuery and it is working. I want to pass the same value from bootstrap modal to the servlet. I tried with ajax, post, nothing seems to be working. Here is my html:
<div class="container" style="padding-top: 60px;" >
<select class="createAlarm" id="createAlarm" name="metrics">
<option value="cpuUsage">CPU Usage</option>
<option value="memoryUsage">Memory Usage</option>
<option value="diskRead">Disk Read</option>
<option value="diskWrite">Disk Write</option>
<option value="diskUsage">Disk Usage</option>
<option value="netUsage">Net Usage</option>
</select>
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal" data-whatever="Create Alarm">Create Alarm</button>
</div>
<!-- Modal- Create Alarm -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Create Alarm</h4>
</div>
<form action="/ProjectName/createAlarm" method="post" id="addcard" class="form-horizontal" role="form">
<div class="modal-body" style="height: 170px;">
<div class="form-group" style="height: 30px;">
<label for="title" class="col-md-3 control-label">Name</label>
<div class="col-md-9">
<input type="text" class="form-control" name="alarmName">
</div>
</div>
<div class="form-group" style="height: 30px; margin-bottom:30px;">
<label for="title" class="col-md-3 control-label">Description</label>
<div class="col-md-9">
<textarea class="form-control" name="desc"></textarea>
</div>
</div>
<div class="form-group">
<label for="priority" id="priority" name="priority" class="col-md-3 control-label">
<input type="text" class="form-control" name="name">
</label>
<div class="col-md-9">
<div class="col-md-3">
<select name="sign" class="form-control">
<option value="lessthan"><</option>
<option value="greaterthan">></option>
<option value="lessthanequalto"><=</option>
<option value="greaterthanequalto">>=</option>
</select>
</div>
<div class="col-md-3">
<input type="text" class="form-control" name="threshold">
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button class="btn btn-primary" id="formSubmit" type="submit">Create Alarm</button>
</div>
</form>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
Here is my jQuery part:
<script>
$('#myModal').on('show.bs.modal', function(e) {
var metrics_key = $('.createAlarm').val();
var metrics_label = $(".createAlarm option:selected").text();
// Now you have the key and label in variables.
// Write the key into the textfield.
$('#myModal input[name="name"]').val(metrics_key);
// Change the HTML of an element to the label.
$('#myModal label[for="priority"]').text(metrics_label);
$.post("/CMPE283_Project2/createAlarm", { val : $("#priority").text()});
alert($('#priority').text());
});
My Servlet:
String Metric = request.getParameter("val");
But, I am getting null for the String Metric. But alert pop up after clicking 'Create Alarm' button shows the correct value I want to pass the servlet. Please help. Thanks.
Your post looks ok, I believe it's just a matter of jquery syntax for accessing controls.
In particular, I'd expect a text input with id="priority" (not just a label as it appears in your code), and then you access it with '.val()' and not 'text()'
<input type="text" id="priority" ... />
$.post('your url', {priority: $("#priority").val()} ...
At least this works for me (jquery version 2.1.3). If you want to make sure, you can just start by posting hard coded data such as {priority: '7'}