Jonathan Hagen
Jonathan Hagen

Reputation: 732

What does "var" mean in JSP?

I am trying to understand jsp code in the project that calls a method from main code. I have jsp code like this:

<s:iterator value="eventsDisplay" var="event">
    <s:set var="eventExtra" value="%{getEventExtra(#event)}" />

This getEventExtra is in the main code like this:

public Map<String, String> getEventExtra(AbstractEventDisplay eventDisplay) {
        Map<String, String> map = new HashMap<>();
        ...
        ...

I am guessing there is connection between jsp code and main code, but in getEventExtra method, where does parameter comes from? I see that in jsp we got event and it is passed in, but I don't know what var means. AbstractEventDisplay is something like this:

public abstract class AbstractEventDisplay implements Serializable {

    private static final long serialVersionUID = 1L;

    private Long id;

    private Date updateTimestamp;

    private String type;

    private String userName;
    private boolean userDeleted;
    ...
    ...
    ...

Can anyone explain to me how event in jsp (or I am guessing from webpage?) is translated into java object.

Upvotes: 1

Views: 1511

Answers (1)

JustAnotherDeveloper
JustAnotherDeveloper

Reputation: 2256

You are using the set tag. For that tag, the value of var is the name of the variable where you store information. <s:set var="eventExtra" value="%{getEventExtra(#event)}" />means "create a variable named eventExtra and store the result of calling getEventExtra(#event) in it".

Upvotes: 1

Related Questions