So recently I have run into an error that I have never encountered.
The code of method _jspService(HttpServletRequest, HttpServletResponse) is exceeding the 65535 bytes limit
I set the model attribute in the controller, granted the object is fairly large I wouldn't expect for it to throw an error. I started by limiting the code to figure out what was causing the issue. I have read here to remove the <jsp:include and use <%# include.
Next step I took was to break up the JSP. I realize now that I am building out my Colors and Fonts individually like this
<form:select path="bottom.backgroundColor" class="form-control">
<form:option value="#000000">Black</form:option>
<form:option value="#FFFFFF">White</form:option>
<form:option value="#FF0000">Red</form:option>
<form:option value="#00FF00">Green</form:option>
<form:option value="#0000FF">Blue</form:option>
<form:option value="#F0F000">Yellow</form:option>
<form:option value="#FF7000">Orange</form:option>
<form:option value="#600060">Purple</form:option>
<form:option value="#905030">Brown</form:option>
</form:select>
Removing these items has fixed my issues.
QUESTION: Why? My understanding is that a JSP builds out its own class however it doesn't seem like it took much to break it. Is the problem the size of the modelAttribute that was passed in? It sounds like others have solved issues with loops and such. Can anyone point me to a resource or explain this better? I can supply more code if necessary.
The problem is that your JSP is too large, even after reducing several parts of it. Seems that you still are repeating this part of the JSP code several times (or similar):
<form:select path="bottom.backgroundColor" class="form-control">
<form:option value="#000000">Black</form:option>
<form:option value="#FFFFFF">White</form:option>
<form:option value="#FF0000">Red</form:option>
<form:option value="#00FF00">Green</form:option>
<form:option value="#0000FF">Blue</form:option>
<form:option value="#F0F000">Yellow</form:option>
<form:option value="#FF7000">Orange</form:option>
<form:option value="#600060">Purple</form:option>
<form:option value="#905030">Brown</form:option>
</form:select>
which in the end is fill the _jspService method in the auto generated servlet. A solution for this problem is to store this static data in application scopde a.k.a. ServletContext, and fill the values of your <form:option>s from it.
Related
in my jsp I list Projects and Home Office states. Projects is a nice drop-down that is collapsed, but Home Office drop-down shows first several entries. Why does Home Office drop-down act differently than Projects? I want it to be collapsed like Projects. getProjects() returns a List of Project objects and getHomeOffice() returns a List of String objects.
<p>
Project: <form:select path="project">
<form:option value="NONE" label="--- Select ---" />
<form:options items="${filterBoard.getProjects()}" />
</form:select>
</p>
<p>
Home Office: <form:select path="homeOffice">
<form:option value="NONE" label="--- Select ---" />
<form:options items="${employee.getHomeOffice()}" />
</form:select>
</p>
I figured it out. I needed to change the data type of the homeOffice field in my java class from List to String.
The "project" field that corresponds with <form:select path="project"> is a String in my java class and filterBoard.getProjects() returns a List. And that works. I had both the "homeOffice" field and employee.getHomeOffice() as Lists. I changed the "homeOffice" field to be a String and renamed my getHomeOffice() method to getHomeOfficeList() and still had it return a List and that fixed it.
I'm newbie about Spring
I cannot solve this problem although I try </form:option> or <form:option ..../>
JSP
<form:select path="status"
id="cbo-position-status" class="editable-select">
<c:forEach items="${statusMap}" var = "stt">
<form:option value="<c:out value="${stt.id}"/>" label="<c:out value="${stt.name}"/>"/>
</c:forEach>
</form:select>
Controller
List<StatusBean> statuses = commonService.getAllStatus(6);
Map<Integer, String> status = new HashMap<Integer, String>();
status.put(statuses.get(0).getId(), statuses.get(0).getName());
model.addAttribute("statusMap", status);
You are using double quotes within double quotes :) Use single quotation within double quotations if they are nested.
Change the as follows:
<form:option value="<c:out value='${stt.id}'/>" label="<c:out value='${stt.name}'/>"/>
Let me know if this resolves.
you can direct map like below.
jsp page
<form:options items="${user}" itemLabel="tbuser_username" itemValue="tbuser_id"/>
controller
model.addObject("user", projectservice.getUsers());
I hope you are understand and improve your code.
Remove your
<c:out value='${stt.id}'/>
by
<form:option>
and try example below:
<c:forEach items="${statusMap}" var = "stt">
<core:set var="actionValueId" value="${stt.id}"/>
<core:set var="actionValueName" value="${stt.name}"/>
<form:option value="${actionValueId}" label="${actionValueName}"/>
</c:forEach>
Do not use JSP Tags inside the attributes of other JSP Tags. You can use the var attribute instead.
<c:out value="${stt.id}" var="id"/>
<c:out value="${stt.name}" var="name"/>
<form:option value="${id}" label="${name}"/>
I am facing problem in getting a default value selected in the dropdown.
Code in my jsp is as below
<form:select path="codes" multiple="false">
<form:option value="NONE" label="--- Select Code ---" />
<form:options items="${statusQueryForm.codes}" />
</form:select>
Below is the code in statusQueryForm:
public void setCodes(Collection<String> codes) {
this.codes = codes ;
}
public Collection<String> getCodes() {
return codes;
}
Codes contains array list of Strings contains data like {"123","345"}
Now when the page is getting loaded,last option is selected 345.What I want is "Select code" should be selected by default.
Please someone can guide me in right direction. I tried to understand the documentation but have failed to arrive at some sense in this example.
Well I was able to fix this by adding one more property code to the StatusQueryForm. Jsp code was changed as below:.path was changed from codes to code
<form:select path="code" multiple="false">
<form:option value="NONE" label="--- Select Code ---" />
<form:options items="${statusQueryForm.codes}" />
</form:select>
I have a Spring MVC application. My JSP allows the user to select a value from a drop down list - this is optional - they do hot HAVE to make a selection.
On my JSP I have code similar to
<form:select path="referral.gpsurgery.id" >
<form:option value="-1" label="--- Select ---"/>
<form:options items="${gpsurgery}" itemValue="id" itemLabel="practiseName"/>
</form:select>
If the user does not make a selection, a referral.gpsurgery object is passed thru to my controller method with an id value of "-1" ( which is what I would expect ). What this actually means as far as my code is concerned is that when the data is persisted, the gpsurgery field on my referral entity should be set to null.
It feels like Spring should sort this out for me, rather than me having to look at my object graph and remove any gpsurgery instances which have an id of "-1", but I am drawing a blank on how to achieve this. It seems like such a common use case that there must be a standard way of doing it.
As also stated in this question, you can use:
<form:select path="referral.gpsurgery.id">
<form:option value=""> </form:option>
<form:options items="${gpsurgery}" itemValue="id" itemLabel="practiseName"/>
</form:select>
The Spring 3 MVC docs state that option tags can be rendered like this:
<tr>
<td>Country:</td>
<td>
<form:select path="country">
<form:options items="${countryList}" itemValue="code" itemLabel="name"/>
</form:select>
</td>
</tr>
I am using FreeMarker with Spring MVC, so I interpret this as:
<tr>
<td>Place:</td>
<td>
<#form.select path="place">
<#form.options items="${places}" itemValue="id" itemLabel="name"/>
</#form.select>
</td>
</tr>
When I hit the page I get the following exception:
freemarker.core.NonStringException: Error on line 40, column 73 in event.ftl
Expecting a string, date or number here, Expression places is instead a freemarker.template.SimpleSequence
What should I use instead of ${places} in my FreeMarker template so that the above works?
Thanks.
I was looking for exactly the same thing. I've no idea why this isn't included in Spring's Freemarker macro library, but fortunately enough it's quite easy to implement: Best practice would be to start your own macro library (say mylib.ftl for example) and put the macro there:
<#macro selectOptions path options key value>
<#spring.bind path/>
<select id="${spring.status.expression}" name="${spring.status.expression}">
<#list options as option>
<option value="${option[key]?html}"<#spring.checkSelected option[key]/>>${option[value]?html}</option>
</#list>
</select>
</#macro>
You can then use your new macro in your Freemarker template like so:
<#import "/mylib.ftl" as mylib />
...
<#mylib.selectOptions "country" countryList "code" "name" />
HTH
You could try the following (not tested personally)
<#form.select path="place">
<#list Request.places as place>
<#form.option value="${place}" label="name" />
</#list>
</#form.select>
Hope this helps!
a little bit weird but it works.
remove ${"places"} and use it straigh as places
remove the itemid and let spring handle it for you
so you will have
<#form.select path="place">
<#form.options items=places itemLabel="name"/>
</#form.select>