user1761680
user1761680

Reputation:

How to change a property's value of the session scoped variable using OGNL in Struts 2?

Is it possible to change a property's value of the session scoped variable using OGNL?

For example, if I have in my session an attribute called PROCESS_CONFIG, which is an object with a property name, how can I change this property name in a JSP?

I've tried the following but it didn't work:

<s:textfield value="%{#session.PROCESS_CONFIG.name}" id="PROCESSNAME" name="#session.PROCESS_CONFIG.name"/> 

When I submit the form and access the session object in my action, through

ServletActionContext.getRequest().getSession().getAttribute("PROCESS_CONFIG")

the attribute name has not changed.

EDIT:

The object saved in session as PROCESS_CONFIG, is a very deep, complex object (composed by numerous references to other objects, with lists of lists of objects), and on my view I just want to present a very tiny subset of its attributes (including attributes from its composed objects). So, polluting my JSP with all other fields as hidden is impractical!

The view in the question is a form where I can change the value of those fields, and I would like to directly and automatically update the object saved on my Struts 2 session, PROCESS_CONFIG, as if PROCESS_CONFIG object was a property of my action. For example, given the previous code snippet, PROCESSNAME is an attribute of PROCESS_CONFIG object, and I would like to update it automatically as PROCESS_CONFIG object, instead of having an PROCESSNAME property in my action, and then having to do it explicitly by setting of PROCESSNAME in my PROCESS_CONFIG object.

Upvotes: 0

Views: 1144

Answers (1)

Roman C
Roman C

Reputation: 1

The session in S2 is a map where you could put the attributes before you use it with OGNL in the JSP. To have this working around let your action implement the SessionAware and look at the official site for the description and usages, and read How do we access to the session from the FAQ.

To your question: why didn't you get the attribute in JSP. Because you are using S2 and OGNL to get it (via #session reference) and you didn't put the attribute to S2 session. S2 session implementation differs from the standard http session. However, if you set attribute to the standard http session you can still access it in JSP 2.0 manner. The opposite is also true.

Upvotes: 1

Related Questions