struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Cesar Arevalo <>
Subject Re: Problem assiging elements in to list
Date Fri, 14 Mar 2008 17:17:10 GMT
HI Vamsi,

by the time you get to the for loop I don't see the list initialized, unless you are doing
this from your jsp I don't think it will work as how you have it, a better way would be with
a normal for like this :

            for (int index = 0; index < someLimit; index++) {
               Person person = new Person();
               persons.add(index, person);
                _logger.error("Person ::::::::::::::::::::::::::" + person);

hope this helps.


----- Original Message ----
From: Vamsi Gmail! <>
To: Struts Users Mailing List <>
Sent: Thursday, March 13, 2008 11:14:53 PM
Subject: Problem assiging elements in to list

Hi all,
         I have a requirement where I need to assign a Objects to a list.
I tried the example given in showcase there is working (in the site).
But It is not assigning to that list
I am also attaching code for your refernce.

-----Inline Attachment Follows-----

 * $Id: 471756 2006-11-06 15:01:43Z husted $
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at

 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.

package test.actions;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import javax.persistence.PersistenceUnit;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.exception.ConstraintViolationException;

import test.examples.Person;

import com.opensymphony.xwork2.ActionSupport;


public class PersonAction extends ActionSupport {

    //private Person person;
    private List persons = new ArrayList();
    private Log _logger = LogFactory.getLog(PersonAction.class);
    public List getPersons() {
        return persons;

    public void setPersons(List persons) {
        this.persons = persons;

    public String save()  {
        EntityManager e = SfmsEntityManagerFactory.getEntityManager();
        EntityTransaction txn  =e.getTransaction();
            _logger.error("Person ::::::::::::::::::::::::::");
            _logger.error("Person ::::::::::::::::::::::::::");
            for (Object object :persons) {
                Person person  = (Person) object;
                _logger.error("Person ::::::::::::::::::::::::::" + person);
            _logger.error("Person ::::::::::::::::::::::::::");
            _logger.error("Person ::::::::::::::::::::::::::");
            addActionMessage("Record Added");
        }catch(ConstraintViolationException e1) {
            addActionError("Record Already There");
        }catch(IllegalStateException e1){
        }catch(Exception e1) {
            addActionError("Error Inserting");
        return SUCCESS;
    private void read(EntityManager e)  {                
        persons = e.createQuery("From Person").getResultList();



-----Inline Attachment Follows-----

package test.examples;

import static javax.persistence.FetchType.LAZY;

import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.Id;

public class Person implements Persister{

    private String name;    
    private int age;

    public String getName() {
        return name;

    public int getAge() {
        return age;

    public void setName(String name) { = name;

    public void setAge(int age) {
        this.age = age;
    public String toString() {
        return name + "::::" + age;

To unsubscribe, e-mail:
For additional commands, e-mail:

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message