Search code examples
javasessionstruts2ognlvaluestack

Is there a way to bind OGNL with Struts2 UI tags


I'm developing a webapp using Struts2. I used to work with Struts1

is there a way to reference a session object directly to the JSP so that if I change the value in the formular, the value in the referenced session object will also be updated.

<s:textfield name="%{#session.order.amount}"/>

for e.g. I have a session object order which has attribute amount with getter and setter.

it seems like, after I put some values into the textfield and then submit the page, the value in the session didn't get updated.

currently I'm using another approach which involves session.put() inside the setter of an action attributes. Personally I dislike my current solution.


Solution

  • You could try having the name be the string session.order.amount and make your action implement SessionAware, and expose the session. Currently you're setting the name to the value of session.order.amount.

    I don't know if it would work, and you might need to use array/collection notation, but off the top of my head I don't know why it wouldn't work.

    That said, I feel like direct view-layer writes into web app internals is a Bad Idea.