I have a String getter and setter that i am setting in my bean.
I am trying to get the value in my jsp using jstl like this :
<jsp:useBean class="com.test.MyBean" id="results" scope="request"/>
<script type="text/javascript">
function setMyFields(){
var flag="<c:out value='${results.sdateFlag}'/>";
alert(flag);
var text_box = document.getElementById('mySelectedDate');
if(flag=="true"){
text_box.setAttribute('disabled', 'disabled');
}
}
window.onload = setMyFields;
</script>
I have imported jstl core as well in my jsp.
But when i do this i get an error like this :
javax.servlet.ServletException: Unable to find a value for "sdateFlag" in object of class "com.test.MyBean" using operator "."
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:660)
at com.ibm._jsp._pageMyAmount._jspService(_pageMyAmount.java:306)
at com.ibm.ws.jsp.runtime.HttpJspBase.service(HttpJspBase.java:87)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1101)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:569)
at com.ibm.ws.wswebcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:478)
at com.ibm.wsspi.webcontainer.servlet.GenericServletWrapper.handleRequest(GenericServletWrapper.java:122)
at com.ibm.ws.jsp.webcontainerext.AbstractJSPExtensionServletWrapper.handleRequest(AbstractJSPExtensionServletWrapper.java:226)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:321)
But ihave been debugging the java class using the java debugger and it seems the value is getting set. Then why is it not getting the value ?
EDIT : These are the setter and getter of my bean :
public void setDateFlag(String b) { sDateFlag = b; }
public String isDateFlag() { return sDateFlag; }
What's wrong here ? Am i missing something ?
You're treating the dateFlag
as a boolean property, but it is in fact a String
. So you "getter" should be called getDateFlag
, not isDateFlag
. As mentioned, the isPropertyName
syntax is only applicable to properties of type boolean
.
Also, <c:out value='${results.dateFlag}'/>
isn't really needed. You should be able to simply do ${results.dateFlag}
.
So , i got the problem fixed and it was a bizarre solution. The problem it seems is, any variable declared must follow java standards. And my problem was , i had given the variable name as sDateFlag
in my original proprietary code, which does not follow the java naming conventions. When i removed it and gave it as flag
, it started working. I R&D ed the answer using this link here : JSTL . Though it's not fully correct, it led me to the root cause of my problem. And i will like to convey my thanks to all of you guys , who have replied to me, to make the process easy .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.