0

I am developing a Struts2 application and have been using <sj:accordion> (https://code.google.com/p/struts2-jquery/wiki/AccordionTag).

Until now, I have been initializing it on my jsp page by hardcoding the value I want in the tags but is there anyway to initialize it using JavaScript?

Here is what I'm trying to solve. I have an accordion that I initialize using (all values are hard-coded):

<sj:accordion
    id="accordionremote"
    active="0"
            />

The 'active' element allows me to decide which <sj:accordionItem> is active/open on page load. Is there any other way to initialize the active element or which <sj:accordionItem> is open on page-load without hard-coding it?

I have tried using $("#accordion").accordion('activate', 0); as described by jquery accordion: activate option using Struts <sj:accordion> but it does not work when I place it inside a <script> element.

Community
  • 1
  • 1
c f
  • 196
  • 2
  • 14
  • I dont get any error. – c f Feb 28 '15 at 16:00
  • Actually I think you can assign an OGNL expression as the value of `active` e.g. `active="{#parameters.activeWindow}"` so it can be changed dynamically. – Quincy Mar 04 '15 at 07:56

2 Answers2

0

Is there any other way to initialize the active element or which is open on page-load without hard-coding it?

$("#accordionremote").accordion('option', 'active', 0);
Roman C
  • 49,761
  • 33
  • 66
  • 176
0

Figured it out! You have to use $("#accordion").accordion({active : 1});

<sj:accordion id="accordion"
              heightStyle="content"
              animate="true"
              collapsible="true"
              active="0"
              onCreateTopics="initAccd"

              >
    <sj:accordionItem title="item1"></sj:accordionItem>
    <sj:accordionItem title="item2"></sj:accordionItem>
</sj:accordion>

<script>

    //going to initialize the accordion
    $.subscribe("initAccd", function (event, data){
        //activate the 2nd item i.e. item2
        $("#accordion").accordion({active : 1});
    });
</script>
Aleksandr M
  • 24,264
  • 12
  • 69
  • 143
c f
  • 196
  • 2
  • 14