bean.getValue() only pulling in part of the value not entire value
I am currently using a javaBean to save/load values to and from a jsp. Here what is happening:
I have the following line in my jsp:
<td><input class="partDescription" name="partDescription" style="width: 250px" type="text" readonly="readonly" value=<%=affectedBean.getPartDescription().get(i) %> /></td>
When I debug through the code this is value stored in the affectedBean.getPartDescription at index 0: BK SLOPE CO开发者_如何学JAVANTROLLER
However, when it the page finishes loading the only thing it shows is in that location is: BK
Other examples:
Value: ROLF REDESIGNED UL SUPPLY; Displays: ROLF
Value: 18 FUEL SENSOR; Displays: 18Anybody have any ideas
In HTML elements, spaces are a special separator character for HTML element attributes like type
, value
, etc.
When printing attribute values without doublequotes like follows
<input type="text" value=<%=affectedBean.getPartDescription().get(i) %> />
then the generated HTML ends up as
<input type="text" value=BK SLOPE CONTROLLER />
All parts beyond the space are been interpreted as another attributes. A bit intelligent syntax highlighter should already have turned on some light above your head. It's colored differently!
So, you need to put quotes around the value
<input type="text" value="<%=affectedBean.getPartDescription().get(i) %>" />
so that the generated HTML ends up as
<input type="text" value="BK SLOPE CONTROLLER" />
Unrelated to the concrete problem, using scriptlets is discouraged, you should prefer using taglibs/EL. Assuming that you've put the affectedBean
as attribute of the request, do so:
<c:forEach items="${affectedBean.partDescription}" var="partDescription">
<input type="text" value="${partDescription}" />
</c:forEach>
精彩评论