I am fairly new to working with Struts2 and currently, I am faced with the challenge of retrieving a session object using a dynamic session key.
Here's how my application flow goes: The user will trigger the action from their browser
http://localhost:8080/prjcr/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="76061712581715021f191849030513041f124b06620041">[email protected]</a>
Within the action class, I fetch a list of values from a web service by utilizing the [email protected] request parameter, and then proceed to store them in the session as shown below:
// Extracting the request parameter
userid = ServletActionContext.getRequest().getParameter("userid");
QDefn[] qDefn = proxy.getQDefns(userid); // making a call to the webservice
List<QDefn> qdList = new ArrayList<QDefn>();
qdList.add(Arrays.asList(qDefn));
We then extract the userid portion of the request parameter to serve as the session key:
userid = userid.substring("UserId", userid.substring(0, userid.indexOf('@'));
// Using the received request parameter itself as the key
ActionContext.getContext().getSession().put("UserId", userid);
Subsequently, we insert the associated list of values into the session:
ActionContext.getContext().getSession().put(userid, qdList);
The next step involves forwarding to a JSP that showcases this list in a select drop down menu:
<s:select name="qdefn"
id="qdefn"
list="#session.%{#session.UserId}" ---What exactly does this notation mean??
listKey="defnName"
listValue="defnName"
headerKey="ALLQD"
headerValue="All" > </s:select>
I have been attempting to retrieve the qdList from the session in JSP using a dynamic session key such as the userid. In Java, we usually achieve this as session.get(userid). However, the OGNL notation used in Struts2/OGNL is posing some difficulties for me at the moment. Any help would be greatly appreciated.
Thank you in advance!