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 6955381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:43:44+00:00 2026-05-27T14:43:44+00:00

I have a iterator which goes through a list and create their name and

  • 0

I have a iterator which goes through a list and create their name and for each of them a button. I want when the user click the button put the same name that has been clicked in the session
This is my code

        <s:iterator value="packageCities" status="portStatus">
            <tr>
                <td>
                    <s:property value="cityName" />
                </td>
            </tr>
            <s:if test="%{status == 0}">
                <tr>
                    <td>
                        <s:submit method="open"  align="center" value="" cssStyle="background: transparent url(image/open.png) no-repeat center top; border: 0px; width: 150px; height: 30px;" >
                            <s:set name="button" value="cityName" scope="session"/>
                        </s:submit>
                    </td>
                </tr>
            </s:if>
        </s:iterator>

But The problem is it only sets the last property , And it doesn’t set it when user clicked the button! so it like when its creating the button it is putting the cityName in the session! But I only want to put different thing in session by clicking different buttons!
Can Any Body Help?

  • 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-05-27T14:43:45+00:00Added an answer on May 27, 2026 at 2:43 pm

    There are two solutions:

    1. Submit the value along with the form (a hidden field may be used for this purpose). Then set the session variable in the action class.
    2. Make a synchronous ajax request to set the session value onclick of the submit buttons.

    As Dave mentioned when the jsp is loaded the values are already set you cannot change them from client side.

    EDIT

    Ok, as you requested, here is a basic idea of the first method. The idea is to set the id of submit buttons with the respective cityName and then onclick of button call a javascript function to set a hidden field’s value with the clicked button’s id (i.e. its cityName)

    <s:form>
    <s:hidden id="value_to_submit" name="value_to_submit"/>
    <s:iterator value="packageCities" status="portStatus"><s:form>
        ....
                    <s:if test="%{status == 0}">
                        <tr>
                            <td>
                                <s:submit id="%{cityName}" onclick="set_hidden_value(this.id)" method="open"  align="center" value="" cssStyle="background: transparent url(image/open.png) no-repeat center top; border: 0px; width: 150px; height: 30px;" >
                                </s:submit>
                            </td>
                        </tr>
                    </s:if>
    
        </s:iterator>
    </s:form>
    

    Javascript

    function set_hidden_value(myvalue){
    document.getElementById("value_to_submit").value=myvalue;
    }
    

    Now you can capture the value of the variable value_to_submit in your action class and set the session variable there.

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

Sidebar

Related Questions

I have a function which searches an STL container then returns the iterator when
Suppose I have a function which can either take an iterable/iterator or a non-iterable
Let's say I have a List object and an iterator for that list. Now
I need an input file stream which would have a bidirectional iterator/adapter. Unfortunately std::ifstream
I have a function which needs to go through a class' types and identify
I have a producer/consumers design in my application which implement Produce/Consume functions on user
I have class which implements Countable, ArrayAccess, Iterator and Serializable. I have a public
Is there a simple or standard way to have a multimap iterator which iterate
I have a Abstract Iterator class which has this function void iterate(){ while(this.hasnext()){ ..this.next()..
I have a method to which a vector's iterator is passed. In this method

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.