Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9017689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:20:08+00:00 2026-06-16T04:20:08+00:00

Struts2 + Freemarker. Below code is working fine but I want to know anyone

  • 0

Struts2 + Freemarker. Below code is working fine but I want to know anyone can simplify it more. I see repeated code to generate html tags.

Below code looks alot to generate custom menu with 3 links

Anyone got any better solution?

 <@s.set var="page" value="com.opensymphony.xwork2.ActionContext.name" />
    <@s.url action="home" var="urlHome" />
    <@s.url action="about" var="urlAbout" />
    <@s.url action="contact" var="urlContact" />

    <#if page=='home'>
        <@currentPage page="%{urlHome}" title="Home"/>
        <@s.a href="%{urlAbout}">About Us</@s.a>
        <@s.a href="%{urlContact}">Contact Us</@s.a>
    <#elseif page=='about' >
        <@s.a href="%{urlHome}">Home</@s.a>
        <@currentPage page="%{urlAbout}" title="About Us"/>
        <@s.a href="%{urlContact}">Contact Us</@s.a>
    <#elseif page=='contact' >
        <@s.a href="%{urlHome}">Home</@s.a>
        <@s.a href="%{urlAbout}">About Us</@s.a>
        <@currentPage page="%{urlContact}" title="Contact Us"/>
    <#else>
        <@currentPage page="%{urlHome}" title="Home"/>
        <@s.a href="%{urlAbout}">About Us</@s.a>
        <@s.a href="%{urlContact}">Contact Us</@s.a>
    </#if>

Macro

<#macro currentPage page title>
    <div class="menu-image">
        <img src="<@s.url value="/images/on-left.gif"/>"/>
    </div>
    <div class="on">
        <@s.a cssClass="over" href="${page}">${title}</@s.a>
    </div>
    <div class="menu-image">
        <img alt="" src="<@s.url value="/images/on-right.gif"/>"/>
    </div>
</#macro>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T04:20:09+00:00Added an answer on June 16, 2026 at 4:20 am

    Compare the name of the page inside the macro or set it as an attribute of the macro

    <@s.set var="page" value="com.opensymphony.xwork2.ActionContext.name" />
    
    <@aPage pageUrl=urlHome title="Home" name="home">
    <@aPage pageUrl=urAbout title="About us" name="about">
    <@aPage pageUrl=urlContact title="Contact us" name="contact">
    
    <@aPageWithBoolean pageUrl=urlHome title="Home" isOn=(page=="home")>
    <@aPageWithBoolean pageUrl=urAbout title="About us" isOn=(page=="about")>
    <@aPageWithBoolean pageUrl=urlContact title="Contact" isOn=(page=="contact")>
    

    Macro

    <#macro aPage pageUrl title name>
        <#if name == page>
            <div class="menu-image">
                <img src="<@s.url value="/images/on-left.gif"/>"/>
            </div>
            <div class="on">
                <@s.a cssClass="over" href="${pageUrl}">${title}</@s.a>
            </div>
            <div class="menu-image">
               <img alt="" src="<@s.url value="/images/on-right.gif"/>"/>
            </div>
        <#else>
            <@s.a cssClass="over" href="${pageUrl}">${title}</@s.a>
        </#if>
    </#macro>
    

    Or with a boolean

    <#macro aPageWithBoolean pageUrl title isOn=false>
        <#if isOn>
            <div class="menu-image">
                <img src="<@s.url value="/images/on-left.gif"/>"/>
            </div>
            <div class="on">
                <@s.a cssClass="over" href="${pageUrl}">${title}</@s.a>
            </div>
            <div class="menu-image">
               <img alt="" src="<@s.url value="/images/on-right.gif"/>"/>
            </div>
        <#else>
            <@s.a cssClass="over" href="${pageUrl}">${title}</@s.a>
        </#if>
    </#macro>
    

    You can also use a wrapper div with CSS and display/hide items based on that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am working on struts2-jquery plugin . the below snippet is working fine in
I am working on struts2. In my jsp page I want to assign the
One of actions in Struts2 is using below code: java.util.concurrent.ExecutorService myservice = Executors.newSingleThreadExecutor(); myservice.execute(new
I am using Struts2 Internationalization to support English & Arabic. I want to know
I have a simple Struts2 app that is serving JSP files just fine. But
In struts2 upload methods, can I choose where the uploaded file must be saved.
I am working on struts2. In my action class I have written some accessors
Using Struts2, I compute a link in my java code and expose the link's
I'm new to Struts2, but I'm consistently running into issues with jQuery selectors not
I am attempting to create a struts2 component using freemarker. I created an ftl

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.