Link to home
Start Free TrialLog in
Avatar of csaexperts
csaexpertsFlag for United States of America

asked on

I'm having a problem with accessing variables using JSTL ...

First, I started web development only a few months ago.  So, my question may seem generic, but I need help.

I have a filen events.jsp with 2 forms.  The first form is an input form, the second form is a search form which pulls query results into a datagrid (I'm using displaytag for the table).  These records can be edited in the first form.  When I select a record in form 2, in my control.jsp, I pull the record from the DB, and c:redirect to events.jsp using the reults as parameters (in results, .  When I make changes to the record, my control.jsp completes the action and I c:redirect the results and msg to events.jsp from control.jsp.  

Everthing works, except I not able to use ${param.results} to take action.  I've put debug code to display the value and my results shows in events.jsp.  But, my condition (c:if) cannot see the value.  I even tried using a session scope variable declared in control.jsp, but this doesn't seem to work either.  

My c:set statements from control.jsp:
   <c:set var='results' value='Event Add Error!' scope='session' />
   <c:set var='msg' value='${errMsg}' scope='session' />

I tried to access the sessionScope variable in events.jsp by using the following with no luck, results is empty:
   <c:if test="${!empty sessionScope.results}" >
         <script language="JavaScript">
         <!--
                   //Do some things here ...
      if ("${sessionScope.results}" == "Event Add Error!"){
          validateEventForm(document.eventsEditform);
          messageWindow("${sessionScope.results}", "${sessionScope.msg}");
      }
          //-->
         </script>
   </c:if>

I also tried to access the parameter variable in events.jsp by using the same code with simple change as follows with results being empty:
   <c:if test="${!empty param.results}" >
         <script language="JavaScript">
         <!--
                   //Do some things here ...
      if ("${param.results}" == "Event Add Error!"){
          validateEventForm(document.eventsEditform);
          messageWindow("${param.results}", "${sessionScope.msg}");
      }
          //-->
         </script>
   </c:if>


Is there something I'm not understanding about using the c:set?  If I set a session variable in control.jsp, shouldn't I be able to see it in events.jsp?  Why would the param.results and param.msg be empty (but print out in my debug statements?  Do you have any suggestions?

Thanks in advance.

ASKER CERTIFIED SOLUTION
Avatar of darkapple
darkapple
Flag of Nepal image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of csaexperts

ASKER

I already have the <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> .  It's a different order,
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>, would that make a difference??

I also tried the c:out for param.msg, which printed the message (I see the value) and for what ever reason (?) the param annotation now works.  But the sessionScope variable is still not showing.

I'm not sure how to use the suggestion  logic:notPresent ....   Could you elaborate?

</logic:notPresent>

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The logic:present annotation was helpful, although not a complete solution.  I'm able to get around my dilemma by passing parameters from control.jsp to events.jsp.  This seems to be working now.  Thank for you help, I learned something which is always good.  MJ