Re: Problem assiging elements in to list

2008-03-14 Thread Dave Newton
--- Cesar Arevalo <[EMAIL PROTECTED]> wrote:
> when you say "All of this is done automatically by the framework"
> do you mean if you populate from a form?

Actually, let me re-answer that: yes, with caveats.

For example, in the source provided the list isn't genericized, so without a
type conversion properties file I don't think it would work.

It can also depend on what type conversion(s) are being attempted; simple
property types are supported out-of-the-box. Sometimes custom type converters
would have to be written.

Without knowing what the original poster was trying to do it's hard to say
what problem s/he is experiencing.

Dave


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Problem assiging elements in to list

2008-03-14 Thread Dave Newton
--- Cesar Arevalo <[EMAIL PROTECTED]> wrote:
> when you say "All of this is done automatically by the framework" 
> do you mean if you populate from a form?

Yes.

Dave


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Problem assiging elements in to list

2008-03-14 Thread Cesar Arevalo
Just out of curiosity, when you say "All of this is done automatically by the 
framework" do you mean  if you populate from a form? or how do you mean the 
framework does this automatically?

Cesar

- Original Message 
From: Dave Newton <[EMAIL PROTECTED]>
To: Struts Users Mailing List 
Sent: Friday, March 14, 2008 10:27:19 AM
Subject: Re: Problem assiging elements in to list

--- Cesar Arevalo <[EMAIL PROTECTED]> wrote:
> 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);
> 
> e.persist(person);
> }
> 
> hope this helps.

That would create a list of empty Person instances (then persist the last
empty Person, but I'm assuming that's a typo).

All of this is done automatically by the framework.

> From: Vamsi Gmail! <[EMAIL PROTECTED]>
>
>  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 reference.
>
> [code]

You never really state how you're expecting the list to be filled: is this
from a form with multiple Person form fields, or...?

Dave


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]






Re: Problem assiging elements in to list

2008-03-14 Thread Dave Newton
--- Cesar Arevalo <[EMAIL PROTECTED]> wrote:
> 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);
> 
> e.persist(person);
> }
> 
> hope this helps.

That would create a list of empty Person instances (then persist the last
empty Person, but I'm assuming that's a typo).

All of this is done automatically by the framework.

> From: Vamsi Gmail! <[EMAIL PROTECTED]>
>
>  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 reference.
>
> [code]

You never really state how you're expecting the list to be filled: is this
from a form with multiple Person form fields, or...?

Dave


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Problem assiging elements in to list

2008-03-14 Thread Cesar Arevalo
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);

e.persist(person);
}

hope this helps.

Cesar

- Original Message 
From: Vamsi Gmail! <[EMAIL PROTECTED]>
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.
 
---Vamsi


-Inline Attachment Follows-

/*
 * $Id: PersonAction.java 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
 *
 *  http://www.apache.org/licenses/LICENSE-2.0

 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * 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;


@SuppressWarnings("serial")

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;
}

@SuppressWarnings("unchecked")

public String save()  {
EntityManager e = SfmsEntityManagerFactory.getEntityManager();
EntityTransaction txn  =e.getTransaction();
txn.begin();
try{
_logger.error("Person ::");
_logger.error("Person ::");
for (Object object :persons) {
Person person  = (Person) object;
_logger.error("Person ::" + person);

e.persist(person);
}
_logger.error("Person ::");
_logger.error("Person ::");
txn.commit();
addActionMessage("Record Added");
read(e);
}catch(ConstraintViolationException e1) {
addActionError("Record Already There");
}catch(IllegalStateException e1){

}catch(Exception e1) {
addActionError("Error Inserting");
txn.rollback();
}

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;

@Entity
public class Person implements Persister{


@Id
private String name;

@Basic(fetch=LAZY)
private int age;

public String getName() {
return name;
}

public int getAge() {
return age;
}

public void setName(String name) {
this.name = name;
}

public void setAge(int age) {
this.age = age;
}

@Override
public String toString() {

return name + "" + age;
}

}

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Problem assiging elements in to list

2008-03-13 Thread Vamsi Gmail!
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.

---Vamsi
/*
 * $Id: PersonAction.java 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
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * 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;


@SuppressWarnings("serial")

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;
}

@SuppressWarnings("unchecked")

public String save()  {
EntityManager e = SfmsEntityManagerFactory.getEntityManager();
EntityTransaction txn  =e.getTransaction();
txn.begin();
try{
_logger.error("Person ::");
_logger.error("Person ::");
for (Object object :persons) {
Person person  = (Person) object;
_logger.error("Person 
::" + person);

e.persist(person);
}
_logger.error("Person ::");
_logger.error("Person ::");
txn.commit();
addActionMessage("Record Added");
read(e);
}catch(ConstraintViolationException e1) {
addActionError("Record Already There");
}catch(IllegalStateException e1){

}catch(Exception e1) {
addActionError("Error Inserting");
txn.rollback();
}

return SUCCESS;
}

private void read(EntityManager e)  {   
persons = e.createQuery("From Person").getResultList();

}





   

}package test.examples;

import static javax.persistence.FetchType.LAZY;

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

@Entity
public class Person implements Persister{


@Id
private String name;

@Basic(fetch=LAZY)
private int age;

public String getName() {
return name;
}

public int getAge() {
return age;
}

public void setName(String name) {
this.name = name;
}

public void setAge(int age) {
this.age = age;
}

@Override
public String toString() {

return name + "" + age;
}

}
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]