Do not use on any
shared computer
July 24, 2008 07:48pm pdt
null
[x]
Attachment Details

Struts 2 s:select tag list property populate

Tags: struts, select, 2, tag
I have problem with populating select values using Struts 2. It is simple sample application that I am writing with purpose to learn Struts 2. Notice part:
<s:select label="Select owner" name="owners" headerKey="-1" headerValue="-- Please Select --" list="persons" listValue="firstName" listKey="id" emptyOption="true" />
I have list persons (java.util.List<Person>) in mystuff.action.PersonAction.

This doesn't work, causing error about list location. Exact question:

How to bind any list (in s:select tag) with some list in some class. I would appriciate some example please.

Here is part of code that I use:

<%@ taglib prefix="s" uri="/struts-tags"%>
<%@page import="mystuff.action.PersonAction"%>
<%@page import="mystuff.service.PersonServiceImpl"%>
<html>
      <head>
            <s:head theme="ajax" debug="true"/>
            <script type="text/javascript">
                  dojo.event.topic.subscribe("/savePerson", function(data, type, request) {
                      if(type == "load") {
                              dojo.byId("personId").value = "";
                              dojo.byId("firstName").value = "";
                              dojo.byId("lastName").value = "";
                              dojo.byId("email").value = "";
                        }
                  });
                  
                  dojo.event.topic.subscribe("/editPerson", function(data, type, request) {
                      if(type == "before") {
                              var id = data.split("_")[1];

                              var tr = dojo.byId("personRow_"+id);
                              var tds = tr.getElementsByTagName("td");

                              dojo.byId("personId").value = id;
                              dojo.byId("firstName").value = dojo.string.trim(dojo.dom.textContent(tds[0]));
                              dojo.byId("lastName").value = dojo.string.trim(dojo.dom.textContent(tds[1]));
                              dojo.byId("email").value = dojo.string.trim(dojo.dom.textContent(tds[2]));
                        }
                  });
                  
                  dojo.event.topic.subscribe("/saveBook", function(data, type, request) {
                      
                      if(type == "load") {
                            dojo.byId("bookId").value = "";
                              dojo.byId("title").value = "";
                              dojo.byId("author").value = "";
                              dojo.byId("pagesNo").value = "";
                        }
                  });
                  
                  dojo.event.topic.subscribe("/editBook", function(data, type, request) {
                      
                      if(type == "before") {
                              var id = data.split("_")[1];

                              var tr = dojo.byId("bookRow_"+id);
                              var tds1 = tr.getElementsByTagName("td");

                              dojo.byId("bookId").value = id;
                              dojo.byId("title").value = dojo.string.trim(dojo.dom.textContent(tds1[0]));
                              dojo.byId("author").value = dojo.string.trim(dojo.dom.textContent(tds1[1]));
                              dojo.byId("pagesNo").value = dojo.string.trim(dojo.dom.textContent(tds1[2]));
                        }
                  });
                  
            </script>
      </head>
      <body>
            <s:url action="listPerson" id="descrsUrl"/>
          <s:url action="listBook" id="descrsUrlBook"/>
          <s:url action="selectTag" id="descrsUrlTag"/>
          <table border="1" cellspacing="3">
            <tr>
                  <td>
                        <!-- First tag only define link for refresh and signal that will be sent when link is followed -->
                    <div style="text-align: right;">
                            <s:a theme="ajax" notifyTopics="/refreshPerson">Refresh</s:a>
                      </div>
                      <!-- This link defines ajax div that will be loaded on the page load and every time that listen topic signal is received
                            href is referenced by earlier defined descrsUrl=listenPerson. Action listenPerson is defined in struts.xml, as well as its result
                      -->
                      <s:div id="persons" theme="ajax" href="%{descrsUrl}" loadingText="Loading..." listenTopics="/refreshPerson"/>
              </td>
              <td>
                    <div style="text-align: right;">
                            <s:a theme="ajax" notifyTopics="/refreshBook">Refresh</s:a>
                      </div>
                      <s:div id="books" theme="ajax" href="%{descrsUrlBook}" loadingText="Loading..." listenTopics="/refreshBook"/>
              </td>
              
        </tr>

            <tr>
                  <td>
                        <p>Person Data</p>
                        <s:form action="savePerson" validate="true">
                            <s:textfield id="personId" name="person.id" cssStyle="display:none"/>
                              <s:textfield id="firstName" label="First Name" name="person.firstName"/>
                              <s:textfield id="lastName" label="Last Name" name="person.lastName"/>
                              <s:textfield id="email" label="E-mail" name="person.email"/>
                              <s:submit theme="ajax" targets="persons" notifyTopics="/savePerson"/>
                        </s:form>
                  </td>
                  <td>
                        <p>Book Data</p>
                        <s:form action="saveBook" validate="true">
                            <s:textfield id="bookId" name="book.id" cssStyle="display:none"/>
                              <s:textfield id="title" label="Book Title" name="book.title"/>
                              <s:textfield id="author" label="Book Author" name="book.author"/>
                              <s:textfield id="pagesNo" label="Book pages no" name="book.pagesNo"/>
                              <s:submit theme="ajax" targets="books" notifyTopics="/saveBook"/>
                              
                              <s:select label="Select owner" name="owners" headerKey="-1" headerValue="-- Please Select --" list="persons" listValue="firstName" listKey="id" emptyOption="true" />
                              
                        </s:form>
                  </td>
                  
            </tr>
            </table>
      </body>
</html>
Start your free trial to view this solution
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

Question Stats
Zone: Programming
Question Asked By: majkic
Solution Provided By: majkic
Participating Experts: 1
Solution Grade: B
Views: 835
Translate:
Loading Advertisement...
 
[+][-]Expert Comment by boonleng

Rank: Master

Expert Comment by boonleng:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by majkic
Author Comment by majkic:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by boonleng

Rank: Master

Expert Comment by boonleng:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by majkic
Author Comment by majkic:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by boonleng

Rank: Master

Expert Comment by boonleng:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by majkic
Author Comment by majkic:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by boonleng

Rank: Master

Expert Comment by boonleng:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by majkic
Author Comment by majkic:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by boonleng

Rank: Master

Expert Comment by boonleng:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by majkic
Author Comment by majkic:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by majkic
Author Comment by majkic:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Accepted Solution by majkic
Accepted Solution by majkic:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Administrative Comment by Vee_Mod
Administrative Comment by Vee_Mod:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Administrative Comment by Vee_Mod
Administrative Comment by Vee_Mod:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Administrative Comment by Vee_Mod
Administrative Comment by Vee_Mod:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
20080723-EE-VQP-34 / EE_QW_1_20070628