Struts2 {} inside a configuration

By : KyelJmD
Source: Stackoverflow.com
Question!

I was following a tutorial on Struts2 upon looking at its config file I saw this

<package name="events" namespace="/events" extends="struts-default">
    <action name="*" class="actions.events.{1}">
        <result>/views/events/{1}.jsp</result>
        <result name="redirect" type="redirect">${redirectUrl}</result>
    </action>
</package>

Everything here is no rocket science, but what boggles my mind is this class="actions.events.{1} what does the {1} mean or do? what it is purpose?

By : KyelJmD


Answers

The above is a wildcard mapping. {1} is a placeholder that will be replaced with the matched action name. So, if you have two actions Action1 and Action2, the above is similar to

<action name="Action1" class="actions.events.Action1">
    <result>/views/events/Action1.jsp</result>
    <result name="redirect" type="redirect">${redirectUrl}</result>
</action>
<action name="Action2" class="actions.events.Action2">
    <result>/views/events/Action2.jsp</result>
    <result name="redirect" type="redirect">${redirectUrl}</result>
</action>

More info in the documentation.

By : JB Nizet


This video can help you solving your question :)
By: admin