Pradip Shenolkar
asked on
jstl c:if condition is not working
How program should work :
1) Once the user selects the file from first select box, second select box gets populated.
2) After selecting one option from second select box "hi there" must be displayed.
How the program is working
From above mentioned steps, once the user selects file from first select box the second select box is getting populated and at the same time before selecting any option from second select box "hi there" is displayed.
i want to display "hi there" after selecting an option from second select box.
I think it has something to do with : <c:if test='<%=cubeValue != "select" %>'> line of code.
Please help
thanks
1) Once the user selects the file from first select box, second select box gets populated.
2) After selecting one option from second select box "hi there" must be displayed.
How the program is working
From above mentioned steps, once the user selects file from first select box the second select box is getting populated and at the same time before selecting any option from second select box "hi there" is displayed.
i want to display "hi there" after selecting an option from second select box.
I think it has something to do with : <c:if test='<%=cubeValue != "select" %>'> line of code.
<jsp:useBean id="c1" class="mypkg.Cubes"></jsp:useBean>
<div id="file">
<form name="s_file" method="post" action="">
<select id="selected_file" name="selected_file" onchange="s_file.submit();">
<option value="Select">Select schema</option>
<c-rt:forEach var="file" items="<%=fileNames%>">
<option value="<c:out value="${file}"/>"><c:out value="${file}"/></option>
</c-rt:forEach>
</select>
<c:if test='${pageContext.request.method=="POST"}'>
<c:if test='${request.getParameter("selected_file") ne "Select"}' >
<c:set value="<%=fileValue %>" target="${c1}" property="schemaFile"/>
<c:out value="${c1.Connect()}"></c:out>
<select id="selected_cube" name="selected_cube" onchange="s_file.submit()">
<option value="select">Select Cube</option>
<c:forEach var="i" begin="0" end="<%=c1.getCubes().size()-1%>" step="1">
<option value='<c:out value="${i}"/>'><c:out value="${ c1.getCubes().get(i).getName()}"/></option>
</c:forEach>
</select>
<c:if test='<%=cubeValue != "select" %>'>
<c:out value="hi there"/>
</c:if>
</c:if>
</c:if>
</form>
</div>
</body>
Please help
thanks
ASKER
I tried your solution but its not working
Here is full code which makes it clear what cubeValue is.(see in scriptlet)
Here is full code which makes it clear what cubeValue is.(see in scriptlet)
<%
String fileValue = request.getParameter("selected_file");
if(fileValue == null)fileValue = "Select File";
String cubeValue = request.getParameter("selected_cube");
if(cubeValue == null)cubeValue = "Select Cube";
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script type="text/javascript">
function retainValue(){
var element1 = document.forms[0].selected_file;
for(x = 0; x < element1.length; x++){
if(element1.options[x].value == "<%=fileValue%>"){
element1.options[x].selected = true;
break;
}
}
var element2 = document.forms[0].selected_cube;
for(x = 0; x < element2.length; x++){
if(element2.options[x].value == "<%=cubeValue%>"){
element2.options[x].selected = true;
break;
}
}
}
</script>
</head>
<body onload="retainValue();">
<%
String folder=application.getRealPath("/WEB-INF/schemas");
File file=new File(folder);
String fileNames[]=file.list();
%>
<jsp:useBean id="c1" class="mypkg.Cubes"></jsp:useBean>
<div id="file">
<form name="s_file" method="post" action="">
<select id="selected_file" name="selected_file" onchange="s_file.submit();">
<option value="Select">Select schema</option>
<c-rt:forEach var="file" items="<%=fileNames%>">
<option value="<c:out value="${file}"/>"><c:out value="${file}"/></option>
</c-rt:forEach>
</select>
<c:if test='${pageContext.request.method=="POST"}'>
<c:if test='${request.getParameter("selected_file") ne "Select"}' >
<c:set value="<%=fileValue %>" target="${c1}" property="schemaFile"/>
<c:out value="${c1.Connect()}"></c:out>
<select id="selected_cube" name="selected_cube" onchange="s_file.submit()">
<option value="select">Select Cube</option>
<c:forEach var="i" begin="0" end="<%=c1.getCubes().size()-1%>" step="1">
<option value='<c:out value="${i}"/>'><c:out value="${ c1.getCubes().get(i).getName()}"/></option>
</c:forEach>
</select>
<c:if test='${param.selected_cube ne "select" }'>
<c:out value="hi there"/>
</c:if>
</c:if>
</c:if>
</form>
</div>
</body>
</html>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
It works like charm.
Thank you so much for helping.
Thank you so much for helping.
Open in new window
That won't work. You could try using.Open in new window