I'm trying to include a page listusers.jsp which simply says "Hello World". I'm reading the name of the listusers.jsp from a parameter as shown below from profile.jsp.
<!-- profile.jsp -->
<table width="100%" border="0px">
<tr><td>
<table border="0px">
<tr>
<td>
<dsp:a page="profile.jsp">List Users
<dsp:param name="includepage" value="listusers.jsp"/>
</dsp:a>
<dsp:a page="profile.jsp">Shop
<dsp:param name="includepage" value="shop.jsp"/>
</dsp:a>
</td>
</tr>
</table>
</td>
<td>
<dsp:getvalueof param="includepage" id="subpage" >
<dsp:include page="<%= subpage %>" />
</dsp:getvalueof>
</td></tr>
</table>
This is giving me the following error when I'm trying to open profile.jsp
A:\Tomcat\apache-tomcat-7.0.37\atgbases\ATG\work\Catalina\localhost\MyStore\org\apache\jsp\profile_jsp.java:168: error: method setPage in class IncludeTag cannot be applied to given types;
_jspx_th_dsp_005finclude_005f1.setPage( subpage );
^
required: String
found: Object
reason: actual argument Object cannot be converted to String by method invocation conversion
1 error
1 warning
Please let me know the right way of including a dynamic page using
You are simply giving the getvalueof the wrong attribute for the variable.
Instead of:
<dsp:getvalueof param="includepage" id="subpage" >
<dsp:include page="<%= subpage %>" />
</dsp:getvalueof>
Rather try:
<dsp:getvalueof param="includepage" var="subpage" >
<dsp:include page="<%= subpage %>" />
</dsp:getvalueof>
Note the attribute is var not id.
I think specifying idtype="java.lang.String" to the <dsp:getvalueof /> tag might resolve your problem. It looks like currently the variable, subpage is created as Object rather than String.
<dsp:getvalueof param="includepage" id="subpage" idtype="java.lang.String">
<dsp:include page="<%= subpage %>" />
</dsp:getvalueof>
Related
I am setting status property as true in the background but still check box not checked:
JSP:
<c:forEach var="list" items="${someFormList}" varStatus="status">
<tr>
<td>
<form:checkbox path="status" items="${list.status}" />
</td>
</tr>
</c:forEach>
Controller:
model.addObject("someFormList", someFormList);
Path gets you partway there. Add the value property to the form:checkbox tag:
<form:checkbox path="status" value="${status}" />
Instead of addObject, you may want to try addAttribute (see also this solution).
I have been working on a system that provides bilingual support to a website from a database using the <spring:message /> tag library.
I can read/write to the applications en/fr properties files. When I hardcode what would be a new key <spring:message /> will display it correctly. Ex) <spring:message code="f12345' /> will display "test data".
What I am having problems doing is using a dynamic key. No matter how I try to attach the key it fails.
Here are the methods I have tried group by end result.
500 error org.apache.jasper.JasperException: (line: [104], column: [29]) [quote/equal] symbol expected
<spring:message var><c:out value="${CLUObject.SpringKey_name()}" /></spring:message>
<spring:message var='<c:out value=\"${CLUObject.SpringKey_name()}\" />" text="wrong" />
<spring:message code="<c:out value="${CLUObject.SpringKey_name()}" />" text="${CLUObject.SpringKey_name()}" />
<spring:message code=<c:out value="${CLUObject.SpringKey_name()}" /> text="${CLUObject.SpringKey_name()}" />
<spring:message code= <c:out value="${CLUObject.SpringKey_name()}" /> />
Next we have the non-server crash which simply causes the table to not display
<spring:message var='<c:out value="application.message" />' arguments="${CLUObject.SpringKey_name()}" />
<spring:message var='<c:out value="${CLUObject.SpringKey_name()}" />' text="wrong" />
<spring:message code="<c:out value=\"${CLUObject.SpringKey_name()}\" />" />
<spring:message code="${CLUObject.SpringKey_name()}" />
<spring:message code="messageCode" arguments="$value1}" />
<c:set var="temp" > <c:out value="${CLUObject.SpringKey_name()}" /> </c:set><td><spring:message code="messageCode" arguments="${temp}" htmlEscape="false" /></td>
The best I have managed to get to simply displays the text of the key instead of the value. Which can already be done using <spring:message text="${CLUObject.SpringKey_name()}" />'
In the applicationResources file
messageCode=Test message for {0}.
Then inside the jsp page
<c:set var="temp" > <c:out value="${CLUObject.SpringKey_name()}" /> </c:set>
displays "Test message for CLUVALUE.C1111."
I found one site online which appeared to be doing the same thing.
<form:select path="${path}">
<c:forEach var="i" items="${items}">
<form:option value="${i[itemValue]}">
<c:choose>
<c:when test="${localize}">
<spring:message code="${i[itemLabel]}" text="${i[itemLabel]}"/>
</c:when>
<c:otherwise>
<c:out value="${i[itemLabel]}"/>
</c:otherwise>
</c:choose>
</form:option>
I have found a second example where they have a dynamic key with the spring message being used in a forEach loop. Search for spring:message and its 14/17.
<c:forEach items="${errors.allErrors}" var="error">
<spring:message code="${error.code}" text="${error.code}"/><br/>
</c:forEach>
I have found a third example.
In the three examples I have found, the spring:message are all used the same, with the code and text attributes being the same.
I cant see the output, and I cant be sure that their text argument isnt being displayed instead.
Here is the controller block
List<CLU_STRUT> myCLUs = cluService.BuildCLUs();
model.addAttribute("CommonLookUp", myCLUs);
And here is the JSP
<c:forEach var="CLUObject" items="${CommonLookUp}" varStatus="vs">
<tr>
<c:set var="temp" > <c:out value="${CLUObject.SpringKey_name()}" /> </c:set>
<td><spring:message code="messageCode" arguments="${temp}" htmlEscape="false" /></td>
<td><c:if test="${CLUObject.getCountNew() gt 0}"> <a href='drillview?drillvalue=${CLUObject.SpringKey_name()}&mode=drill&drilltype=I'><c:out value="${CLUObject.getCountNew()}" /></a></c:if><c:if test="${CLUObject.getCountNew() eq 0}">0</c:if></td>
<td><c:if test="${CLUObject.getCountMod() gt 0}"> <a href='drillview?drillvalue=${CLUObject.SpringKey_name()}&mode=drill&drilltype=U'><c:out value="${CLUObject.getCountMod()}" /></a></c:if><c:if test="${CLUObject.getCountMod() eq 0}">0</c:if></td>
<td><c:if test="${CLUObject.getCountDelete() gt 0}"> <a href='drillview?drillvalue=${CLUObject.SpringKey_name()}&mode=drill&drilltype=D'><c:out value="${CLUObject.getCountDelete()}" /></a></c:if><c:if test="${CLUObject.getCountDelete() eq 0}">0</c:if></td>
<td><c:out value="${CLUObject.getCountTotal()}" /></td>
</tr>
</c:forEach>
TLDR; How to use spring:message where the key is dynamic in a jsp page.
I finally figured out what the issue was.
Short Answer: the inversion of control was causing things to happen now how I expected. I was trying to access a function or member, and it kept trying to use a get version of it. Since I did not have specifically getmember() to access the variable, it was doing strange and wrong things.
By introducing public String getspring_name() {return spring_name;} all of a sudden the <spring:message code="${CLUObject.spring_name}" /> works.
Long Answer: In another section of my code I discovered what I thought was a private string member being accessed in a jsp page. After considerable testing of other private variable types and functions, my original thought that I was gaining access to the private member was disproved. Yet, this specific one was being accessed. After more testing I discovered when I had a get function in a very specific naming convention this behavior was reproducible. So in this case I had a private String CLU_Name, and was lucky enough to have created the get function as getCLU_Name(). Having named other get functions like getCountDelete() for Count_Delete was not allowing me to reproduce the behavior for THEM, because they did not fit the naming pattern.
My code is as follows:
<c:forEach items="${cashInList}" var="list" varStatus="stat">
<tr>
<td>${list.dateandtime}
</td>
<td><fmt:formatNumber type="number" pattern="###,###,###,##0.00" value="${list.cashAmount}" />
</td>
<td>
<input id="checkBoxID" type="checkbox" name="checkBoxValues" value="${list.checkBoxValue}" />
${list.checkBoxValue}
</td>
</tr>
</c:forEach>
in the controller bean
String[] checkedValues = req.getParameterValues("checkBoxValues");
However I got a null value.
When an HTML page is submitted, no parameters are sent on the HTTP request for inputs of type "checkbox" if they are not checked.
Try a simple sample with a static HTMl page containing a simple form with two checkboxes, one checked and the other one not checked. In the development tools of your browser you should see that only a parameter for one input is added on the request.
There is also a problem in your code, you have several inputs with the same ID. You should have a different ID for each checkbox.
<c:forEach var = "student" items="${result}">
<tr>
<th>${student.name}</th>
<th>Notify</th>
</tr>
</c:forEach>
This is my output.jsp. Notice that I've put a link "Notify" to forward it on display.jsp. But I'm not sure how to display a record of student.name onto my display.jsp 's textbox. Thanks
You have to pass the student name over to the display.jsp (e.g. using a GET parameter).
Modify your link as follows:
<th>Notify</th>
Inside your display.jsp your textbox may look like this:
<input type="text" name="studentName" value="${param['studentName']}" />
I am implementing a search functionality in a website I am building, which involves searching by the md5 hash of the name of the file submitted and searching by the notes associated with each submitted file. So, I should detect as to which button is pressed "Search by MD5" or "Search by Notes". This is the code I have:
JSP code for the form:
<form id="search" name="search" action = "search.do"
method="POST" enctype="multipart/form-data">
<table align = "center">
<tr>
<th colspan="4" bgcolor="#004276"><font color="white">
Search for Sample
</th>
</tr>
<tr>
<td><input name="md5" type="text" value="${form.md5}"/></td>
<td><input name="md5search" type="submit" value="Search by MD5"/>
</tr>
<tr>
<td><input name="notes" type="text" value="${form.notes}"/></td>
<td><input name="notessearch" type="submit" value="Search by Notes"/>
</tr>
</table>
</form>
search.do is mapped to SearchResultsAction.java. Code in Java action class (SearchResultsAction) which handles the request is:
if(request.getParameter("md5search").toString().equals("Search by MD5")){
searchSubmissionsList = submissionsDAO.searchSubmissionsByMD5(form.getMD5());
}
if(request.getParameter("notessearch").toString().equals("Search by Notes")){
searchSubmissionsList = submissionsDAO.searchSubmissionByNotes(form.getNotes());
}
But the problem I am facing here is that, request.getParameter("md5search") and request.getParameter("notessearch") return null for some reason. I have been working on this for a while and have not been able to figure it out. The weird thing is that it once worked for me sometime back when I was working on another project. Am I missing something here?
It's null because you used multipart/form-data form encoding instead of (default) application/x-www-form-urlencoded. Basically, you have to (let Struts) extract the text fields from the multipart form data body the same way as you (or Struts) extracted the uploaded file. Or, as there is actually no <input type="file"> field in your form at all, just remove the enctype attribute altogether.
See also
Does form with enctype="multipart/form-data" cause problems accessing a hidden field