JasperException: equal symbol expected - java

I am using Spring form tag library & a select jquery plugin
An error occurs on running the jsp
org.apache.jasper.JasperException: /WEB-INF/view/home.jsp(51,4)
/WEB-INF/view/createpost.jsp(19,15) equal symbol expected
<li>
<form:select name="mood" class="selectpicker" data-style="btn-sm"
multiple data-width="100px" data-size="5" //Line 19
title='Feeling' path="mood">
<option value="1">A</option>
<option value="2">B</option>
<option value="3">C</option>
</form:select>
</li>
<li>
<form:select name="Working" class="selectpicker" data-style="btn-sm"
data-width="110px" data-size="5" title='WorkingAt ..' path="WorkingAt">
<option value="1">A</option>
</form:select>
</li>
When I remove the multiple attribute from the first select tag, error disappears, but if effects the functionality. multiple attribute enables multiple value selection in the select tag.
Seems like spring form is not allowing multiple attribute to run.
Can anyone help on this?

I had the same issue when i try to add disebbled selected disabled after adding it like below problem got solved.
<form:option value="0" label="Membership Type" selected="true" disabled="true"/>
for your answer,
<option value="1" multiple="true">A</option>

Related

How to display a Set property in a spring form?

I am working on a Spring MVC web app and I'm trying to figure out a way to display a property of type Set that is part of the entity in question. For the rest of the properties (String, boolean, int, etc) I can get away with the JSP file just using something like this to display them :
<li>
<label for="active">Active : </label>
<form:checkbox path="active" id="active" disabled="true"/>
<span><form:errors path="active" cssClass="error"/></span>
</li>
However, for a property of the entity which is a Set of other entities I cannot figure out how to display it. I'm thinking of using some sort of sub-table but I fiddled with it a lot with no success. I tried searching google and can't quite find what I need.
Thanks!
* New problem, but getting there! *
My OrderedMed class has a property of type StrengthUnit and I'm able to display its name using the method in the comments below :
<li>
<label for="meds[${loop.index}].strengthUnit.name">Strength Units : </label>
<form:input path="meds[${loop.index}].strengthUnit.name"/>
<form:errors path="meds[${loop.index}].strengthUnit.name" cssClass="error" />
</li>
However, I need this to be a drop-down that the user can change. My Med entity also has a property of type StrengthUnit and I'm able to accomplish what I want in its respective edit page by sending a list of all Strength Units from the controller and using the following code :
<select name="strengthUnit" path="strengthUnit.name" id="strengthUnit">
<option value="0" ${med.strengthUnit eq null ? 'selected' : ''}></option>
<c:forEach items="${strengthUnits}" var="strengthUnitSingle">
<option value="${strengthUnitSingle.id}" ${med.strengthUnit.name eq strengthUnitSingle.name ? 'selected' : ''}>${strengthUnitSingle.name}</option>
</c:forEach>
</select>
I'm trying to do the same thing with this entity and I cannot seem to make it work using the method suggested in the comments. I'm trying the below code :
<select name="strengthUnit" path="strengthUnit.name" id="strengthUnit">
<option value="0" ${meds[loop.index].strengthUnit eq null ? 'selected' : ''}></option>
<c:forEach items="${strengthUnits}" var="strengthUnitSingle">
<option value="${strengthUnitSingle.id}" ${meds[loop.index].strengthUnit.name eq strengthUnitSingle.name ? 'selected' : ''}>${strengthUnitSingle.name}</option>
</c:forEach>
</select>
Now i am getting this exception again :
javax.el.PropertyNotFoundException: Property '0' not found on type mdhis_webclient.entity.OrderedMed
I am using the same method to access the Set's index, what am I doing wrong?
Thanks!
You will probably need a forEach loop with the varStatus, example:
<c:forEach var="yourVar" items="${yourList}" varStatus="loop" >
<label for="yourVar[${loop.index}].something">Something ${loop.index + 1}</label>
<form:input path="yourVar[${loop.index}].someting" cssClass="form-control" autocomplete="off" />
<form:errors path="yourVar[${loop.index}].something" cssClass="text-danger" />
</c:forEach>
For the second part of my question, this is what i needed! I just needed a toString() method to my StrengthUnit entity (they should all have one anyway!)
<form:select name="strengthUnit" path="meds[${loop.index}].strengthUnit.name" id="strengthUnit">
<form:option value="0" label=""></form:option>
<form:options items="${strengthUnits}" />
</form:select>

Add one more option field in the Struts2 select tag

i have one struts 2 select tag like below.
<s:select list="myList" listKey="myListVal" listValue="myListDesc"></s:select>
it rendered as below
<select data-inputs="myListInput" >
<option value="myListVal1" >myListDesc1</option>
<option value="myListVal2" >myListDesc2</option>
<option value="myListVal3" >myListDesc3</option>
</select>
i want to add one more option field with null value
<option value="" ></option>
to the Option field with modification in the list.
In struts 1 it is possible like below
<html:option value=""></html:option>
like that is it possible in the struts 2
note:i couldn't able to modifiy the list before the page load in the java
There is an Attribute called emptyOption in the select tag.
It worked as below.
<s:select list="myList" listKey="myListVal" listValue="myListDesc" emptyOption="true" ></s:select>
if you want to add one more option field with null value at the begining of the list you can use headerKey & headerValue attribute of s:select tag.
Check example given below.
<s:select list="myList" listKey="myListVal" listValue="myListDesc" headerKey="0" headerValue="" ></s:select>
So the first element of your list will be empty & it's value will be 0(zero) here.
It will be render as
<select data-inputs="myListInput" >
<option value="" >0</option>
<option value="myListVal1" >myListDesc1</option>
<option value="myListVal2" >myListDesc2</option>
<option value="myListVal3" >myListDesc3</option>
</select>
You can set any value on place of 0 (zero).
Hope this will help you.

How to avoid the duplicate entry of select box option while edit page?

Could anyone please explain me how to avoid the duplicate enters of records in to the select box options during editing the page.I am using java to develop web application I am very new to that,I need to remove the duplicates from the select box option while editing.Could anyone please help me .
Sample Code
<td><select property="employeestatus" value="" id="employeestatus">
<c:if test="${employee.employeestatus!=null}">
<option value="${employee.employeestatus}">${employee.employeestatus}</option>
</c:if>
<option value="">Select</option>
<option value="Active">Active</option>
<option value="Terminated">Terminated</option>
<option value="Deceased">Deceased</option>
<option value="Resigned">Resigned</option>
<option value="InActive">InActive</option>
</select>
<html:errors property="employeestatus"/>
<p id="employeestatus" style="color:red"/>
</td>
I would suggest to add the selected attribute on the option corresponding to your "employeestatus" variable instead of duplicating this option on the first line.
See HTML option selected Attribute
By the <html:errors ...>, I gess you use Struts 1. If it's true, I would use the
<html:select ...> tag and
<html:options or optionsCollection ...>
with java Map store in some context (servlet, session or request) to configure options. That struts tag will select the good option corresponding to your variable value.
See Struts <html:select ...> doc

combo box in spring web mvc

I am using spring web mvc for my app's UI part..
By using following code, i am getting List Box where i can select more then 1 value..
<form:select path="domainsList">
<form:options items="${domainsList}" itemValue="domain" itemLabel="domain"/>
</form:select>
But I need a drop down combo box...
Can any one suggest how can i convert it to combo box ?
Thanks in advance..
Sorry, for asking silly question.. But i got working combo box by following code :
<form:select path="domainsList" multiple="false" size="1">
<form:options items="${domainsList}" itemValue="domain" itemLabel="domain"/>
</form:select>
</form:form>
Spring will decide the type of field to use depending on the type of data, so if the 'path' field is an object, it will show a dropdown, but if it is a "list" (array, collection, ...) it will show a list, unless you specify multiple="false"
This will show a list with multiple selection:
Integer[] ids;
<form:select path="ids" items="${whatever}" />
This will show a dropdown with single selection:
Integer id;
<form:select path="id" items="${whatever}" />
This will also show a dropdown with single selection:
Integer[] ids;
<form:select path="ids" items="${whatever}" multiple="false" />
The spring "form:select" tag just wraps the HTML select element. It also has an attribute size which has to be set to a value of 1 to let this selection become rendered as a combobox (in most browsers).
this is basic HTML:
http://www.w3.org/TR/html4/interact/forms.html#adef-size-SELECT
<form:select path="domainsList" size="1">
<form:options items="${domainsList}" itemValue="domain" itemLabel="domain"/>
</form:select>
#Nirmal please check your markup. This should work.
<html>
<SELECT name="selection" size="1">
<OPTION selected label="none" value="none">None</OPTION>
<OPTION label="1" value="1">OPTION 1</OPTION>
<OPTION label="2" value="2">OPTION 2</OPTION>
<OPTION label="3" value="3">OPTION 3</OPTION>
</SELECT>
</html>

how to retrieve multiple selected values from <select multiple > in java code?

code is below:
<select name="merTransactionTypeId" class="cbox" multiple>
<!--
<option value="0" <%=request.getParameter("merTransactionTypeId")!=null?"0".equalsIgnoreCase(request.getParameter("merTransactionTypeId"))?"selected":"":""%>>All</option>
-->
<option value="2" <%=request.getParameter("merTransactionTypeId")!=null?"2".equalsIgnoreCase(request.getParameter("merTransactionTypeId"))?"selected":"":""%>>Reload</option>
<option value="1" <%=request.getParameter("merTransactionTypeId")!=null?"1".equalsIgnoreCase(request.getParameter("merTransactionTypeId"))?"selected":"":""%>>Sale</option>
<option value="5" <%=request.getParameter("merTransactionTypeId")!=null?"5".equalsIgnoreCase(request.getParameter("merTransactionTypeId"))?"selected":"":""%>>CCMS_Recharge</option>
<option value="6" <%=request.getParameter("merTransactionTypeId")!=null?"6".equalsIgnoreCase(request.getParameter("merTransactionTypeId"))?"selected":"":""%>>Loyalty_Award</option>
<option value="7" <%=request.getParameter("merTransactionTypeId")!=null?"7".equalsIgnoreCase(request.getParameter("merTransactionTypeId"))?"selected":"":""%>>Loyalty_Redeem</option>
<option value="16" <%=request.getParameter("merTransactionTypeId")!=null?"16".equalsIgnoreCase(request.getParameter("merTransactionTypeId"))?"selected":"":""%>>FCC_Reload</option>
<option value="11" <%=request.getParameter("merTransactionTypeId")!=null?"11".equalsIgnoreCase(request.getParameter("merTransactionTypeId"))?"selected":"":""%>>Tracking</option>
<option value="12" <%=request.getParameter("merTransactionTypeId")!=null?"12".equalsIgnoreCase(request.getParameter("merTransactionTypeId"))?"selected":"":""%>>Fund_Transfer_From_Card</option>
</select>
i am trying to retrieve values from dropdown with code in scriplet as
<% String[] selectedTransactionTypes = request.getParameterValues("merTransactionTypeId"); %>
...but it's returning null. Please help me out.
Apparently the listbox isn't enclosed in the same <form>, or there's even no means of a <form>, or maybe you tried to access it at the wrong moment (e.g. before form submit), or maybe there's a typo in the parameter name (use getParameterNames() to view them all).
That said, I strongly recommend you to leave the old fashioned scriptlets aside and go ahead with a servlet class to preprocess and postprocess the request and taglibs/EL to control the flow and access data in JSP. It will make your code much cleaner.

Categories