Skip to content
Advertisement

How to put variable in OGNL tag

JavaScript

In this code questions is a list which contain questions object with

JavaScript

In my program, I will make it appears in browser like

JavaScript

The list may contain multiple question objects so I made it to show 5 question per page. My problem is (for example) the user may go from page 4 to page 2 and I want to refill the answers the user have clicked in page 2. So in the action class, I create a HashMap and put question id (qid) and answered question (eg. ans2) into the map, then put this map into the session called map.

In above code, I use

JavaScript

in the HTML radio tag. I hard coded the question id (qid) as 1 and it works as planned. But the number in the get() must be variable. That must be real question id like I used in

JavaScript

I tried put the parameter as

JavaScript

but it doesn’t work. How to make the parameter variable?

Advertisement

Answer

To populate your question you need to use the s:iterator tag.

JavaScript

in the action use map questions by name (equivalent your qid)

JavaScript

the question class created from your description.

JavaScript

make sure you initialize the questions before return result.

JavaScript

In this example the first radio will be checked and second unchecked due to the session map values.

The input elements of the form are bound to the action by their names. If you need to get values when you submit the form you need to use indexed property names.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement