Re: saving a value in jsp?

2005-11-26 Thread hem hem
Hi ,
   
  you said
   
  But if you stick to this then you can create a hidden field called name and
on the onChange of the dropdown list set the value of the hidden field to
the selected name.
   
  i was struct here mate.i already used hidden field to achieve this but i am 
getting the (name)value of the last selected item in the drop down.
  can you please help me how can i achieve this by onclick?
   
  my code is like this
   
  
 
 
   
   

  "/>
  
   
  here the last item in the dropdown is getting populated to my name field not 
the selected one.
   
  can you plese help me to get the selected one(on using onclick)?
   
  regards and many thanks in advance
   
  
 
   
   
  

Tamas Szabo <[EMAIL PROTECTED]> wrote:
  Hi,

I think somebody already explained you that you don't need the name.
In the Action to which you forward you can loop up the name based on the
code.

But if you stick to this then you can create a hidden field called name and
on the onChange of the dropdown list set the value of the hidden field to
the selected name.


Tamas


On 11/25/05, Kanuri, Chand wrote:
>
> hi all,
> i have a dropdown list in my struts web app,
> i am having a form in which a bean is instatiated(bean has 2 properties
> "name" and "code").
>
> i am using like this in the jsp:
>
> 
>
> >
> name="">
> > name="ItemType" property="code"/>'>> name="ItemType"
> property="name" />
> 
>
>
> 
>
> each "itemType" has "code" and "name".
> when the user clicks on the item name on the dropdown item beans "code" is
> populating.now i need to populate "name" aswell at the sametime using
> hidden
> property.
>
> i want to save tha value of name in the jsp to use it later to populate
> "name" in my form using hidden property?
>
> do anyone have idea how to save the value in jsp?
>
> regards and thanks in advance
>
>
> This e-mail (and any attachments) may contain privileged and/or
> confidential information. If you are not the intended recipient please do
> not disclose, copy, distribute, disseminate or take any action in reliance
> on it. If you have received this message in error please reply and tell us
> and then delete it. Should you wish to communicate with us by e-mail we
> cannot guarantee the security of any data outside our own computer systems.
> For the protection of Legal & General's systems and staff, incoming emails
> will be automatically scanned.
>
> Any information contained in this message may be subject to applicable
> terms and conditions and must not be construed as giving investment advice
> within or outside the United Kingdom.
>
> The following companies are subsidiary companies of the Legal & General
> Group Plc which are authorised and regulated by the Financial Services
> Authority for advising and arranging the products shown: Legal & General
> Partnership Services Limited (insurance and mortgages), Legal & General
> Insurance Limited (insurance), Legal & General Assurance Society Limited
> (life assurance, pensions and investments), Legal & General Unit Trust
> Managers Limited and Legal & General Portfolio Management Services Limited
> (investments).
>
> They are registered in England under numbers shown.
> The registered office is Temple Court, 11 Queen Victoria Street, London
> EC4N 4TP.
>
> Legal & General Partnership Services Limited: 5045000 Legal & General
> Assurance Society Limited: 166055 Legal & General (Unit Trust Managers)
> Limited: 1009418 Legal & General (Portfolio Management Services) Limited:
> 2457525 Legal & General Insurance Limited: 423930
>
> They are registered with the Financial Services Authority under numbers
> shown. You can check this at www.fsa.gov.uk/register
>
> Legal & General Partnership Services Limited: 300792 Legal & General
> Assurance Society Limited: 117659 Legal & General (Unit Trust Managers)
> Limited: 119273 Legal & General (Portfolio Management Services) Limited:
> 146786 Legal & General Insurance Limited: 202050
>
>
> -
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
  



-
 Yahoo! Music Unlimited - Access over 1 million songs. Try it free.

user@struts.apache.org

2005-11-07 Thread hem hem
hi all,
i am new to struts validation.
i foung some nice tutorials which validates action forms using 
validator-rules.xml and validation.xml(which connects  validator-rules.xml and 
formbean name in stuts-config.xml).
 
but my form bean looks like this(i am using 2 more beans in my action 
form) which results in nested properties.
 
here is my UsersForm:
 
 
 
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.validator.ValidatorForm;
 
public class UsersForm extends ValidatorForm {
 
 private static final int MAX_NUMBER_OF_USERS = 5;
 private int numberOfUsers = 0;
 private static final String mandatoryFields = "madatory field"; // 
Mandatory error category
 private static final String dateFormat = "date error"; // user error 
category
 private ProductBean product = new ProductBean();
 private String purpose = "";
 private List users = new ArrayList(MAX_NUMBER_OF_USERS);
 public UsersForm() {
  super();
  
  for (int i = 0; i < MAX_NUMBER_OF_USERS; i++) {
   UsersBean ub = new UsersBean();
   users.add(ub);
  }
 }
 public void reset(ActionMapping mapping, HttpServletRequest request) {
 }
 public ActionErrors validate(ActionMapping mapping, HttpServletRequest 
request) {
  ActionErrors errors = null;
  
  boolean mandatoryError = false;
  Iterator i = users.iterator();
  while (i.hasNext()) {
   UsersBean bean = (UsersBean)i.next();
   
   if (bean.getSurname() != null && !bean.getSurname().equals("")) {
++numberOfUsers;

if (! mandatoryError){
 
 if ((bean.getDob() == null) || (bean.getDob().equals(""))) {
  errors = addError(errors, UsersForm.mandatoryFields);  
  
  mandatoryError = true;
 } else {
  
  
  SimpleDateFormat sdf = new 
SimpleDateFormat(DateHelper.dateFormatddmm);
  sdf.setLenient(false);
  try {
   Date dob = sdf.parse(bean.getDob());
  } catch (ParseException e) {
   errors = addError(errors, UsersForm.dateFormat);
  }
 }
}
   }
   
   if (numberOfUsers == 0 && mandatoryError == false) {
errors = addError(errors, UsersForm.mandatoryFields);

mandatoryError = true;
   }
  }
  
  return errors;
 }
 
 private ActionErrors addError(ActionErrors errors, String messageKey) 
{ 
  if (errors == null) {
   errors = new ActionErrors();
  }
  ActionMessage error = new ActionMessage(messageKey);
  errors.add(messageKey, error);
  return errors;
 }
 
 /**
  * @return
  */
 public String getPurpose() {
  return basis;
 }
 /**
  * @param string
  */
 public void setPurpose(String string) {
  purpose = string;
 }
 /**
  * @return
  */
 public ProductBean getProduct() {
  return product;
 }
 /**
  * @param bean
  */
 public void setProduct(ProductBean bean) {
  product = bean;
 }
 /**
  * @return
  */
 public List getUsers() {
  return users;
 }
 /**
  * @param list
  */
 public void setUsers(List list) {
  users = list;
 }
 public void setUsers(int index, Object value) {
  users.add(index, value);
 }
 
 public Object getUsers(int index) {
  return users.get(index);
 }
 /**
  * @return
  */
 public int getNumberOfUsers() {
  return numberOfUsers;
 }
}

 
and here is my ProductBean:
 
 

public class ProductBean {
 private String code;
 /**
  * 
  */
 public ProductBean() {
  super();
  
 }
 public ProductBean(String aCode) {
  this.code = aCode;
 }
 /**
  * @return
  */
 public String getCode() {
  return code;
 }
 /**
  * @param string
  */
 public void setCode(String string) {
  code = string;
 }
}

and here is my UsersBean:
 

public class UsersBean {
 private String title = null;
 private String forename = null;
 private String surname = null;
 private String dob = null;
 
 public UsersBean() {
  super();
 }
 /**
  * @return
  */
 public String getDob() {
  return dob;
 }
 
 /**
  * @return
  */
 public String getTitle() {
  return title;
 }
 /**
  * @param string
  */
 public void setDob(String string) {
  dob = string;
 }
 
 /**
  * @param string
  */
 public void setTitle(String string) {
  title = string;
 }
 /**
  * @return
  */
 public String getForename() {
  return forename;
 }
 
 /**
  * @return
  */
 public String getSurname() {
  return surname;
 }
 /**
  * @param string
  */
 public void setForename(String string) {
  forename = string;
 }
 
 /**
  * @param string
  */
 public void setSurname(String string) {
  surname = string;
 }

 
}

 
i want to validate all the fields 5users*4 =20 and purpose filed and 
code in productbean and save the errors?
 
can any one give me an out line idea to do validation using 
struts(using the files validator-rules.xml,validation.xml and struts-config.xml 
where we write form bean definitions
 
 
regards 

how to use Struts validator to this action form-please help me

2005-11-07 Thread hem hem
hi all,
i am new to struts validation.
i foung some nice tutorials which validates action forms using 
validator-rules.xml and validation.xml(which connects  validator-rules.xml and 
formbean name in stuts-config.xml).
 
but my form bean looks like this(i am using 2 more beans in my action form) 
which results in nested properties.
 
here is my UsersForm:
 
 
 
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.validator.ValidatorForm;
 
public class UsersForm extends ValidatorForm {
 
 private static final int MAX_NUMBER_OF_USERS = 5;
 private int numberOfUsers = 0;
 private static final String mandatoryFields = "madatory field"; // Mandatory 
error category
 private static final String dateFormat = "date error"; // user error category
 private ProductBean product = new ProductBean();
 private String purpose = "";
 private List users = new ArrayList(MAX_NUMBER_OF_USERS);
 public UsersForm() {
  super();
  
  for (int i = 0; i < MAX_NUMBER_OF_USERS; i++) {
   UsersBean ub = new UsersBean();
   users.add(ub);
  }
 }
 public void reset(ActionMapping mapping, HttpServletRequest request) {
 }
 public ActionErrors validate(ActionMapping mapping, HttpServletRequest 
request) {
  ActionErrors errors = null;
  
  boolean mandatoryError = false;
  Iterator i = users.iterator();
  while (i.hasNext()) {
   UsersBean bean = (UsersBean)i.next();
   
   if (bean.getSurname() != null && !bean.getSurname().equals("")) {
++numberOfUsers;

if (! mandatoryError){
 
 if ((bean.getDob() == null) || (bean.getDob().equals(""))) {
  errors = addError(errors, UsersForm.mandatoryFields);  
  
  mandatoryError = true;
 } else {
  
  
  SimpleDateFormat sdf = new 
SimpleDateFormat(DateHelper.dateFormatddmm);
  sdf.setLenient(false);
  try {
   Date dob = sdf.parse(bean.getDob());
  } catch (ParseException e) {
   errors = addError(errors, UsersForm.dateFormat);
  }
 }
}
   }
   
   if (numberOfUsers == 0 && mandatoryError == false) {
errors = addError(errors, UsersForm.mandatoryFields);

mandatoryError = true;
   }
  }
  
  return errors;
 }
 
 private ActionErrors addError(ActionErrors errors, String messageKey) { 
  if (errors == null) {
   errors = new ActionErrors();
  }
  ActionMessage error = new ActionMessage(messageKey);
  errors.add(messageKey, error);
  return errors;
 }
 
 /**
  * @return
  */
 public String getPurpose() {
  return basis;
 }
 /**
  * @param string
  */
 public void setPurpose(String string) {
  purpose = string;
 }
 /**
  * @return
  */
 public ProductBean getProduct() {
  return product;
 }
 /**
  * @param bean
  */
 public void setProduct(ProductBean bean) {
  product = bean;
 }
 /**
  * @return
  */
 public List getUsers() {
  return users;
 }
 /**
  * @param list
  */
 public void setUsers(List list) {
  users = list;
 }
 public void setUsers(int index, Object value) {
  users.add(index, value);
 }
 
 public Object getUsers(int index) {
  return users.get(index);
 }
 /**
  * @return
  */
 public int getNumberOfUsers() {
  return numberOfUsers;
 }
}

 
and here is my ProductBean:
 
 

public class ProductBean {
 private String code;
 /**
  * 
  */
 public ProductBean() {
  super();
  
 }
 public ProductBean(String aCode) {
  this.code = aCode;
 }
 /**
  * @return
  */
 public String getCode() {
  return code;
 }
 /**
  * @param string
  */
 public void setCode(String string) {
  code = string;
 }
}

and here is my UsersBean:
 

public class UsersBean {
 private String title = null;
 private String forename = null;
 private String surname = null;
 private String dob = null;
 
 public UsersBean() {
  super();
 }
 /**
  * @return
  */
 public String getDob() {
  return dob;
 }
 
 /**
  * @return
  */
 public String getTitle() {
  return title;
 }
 /**
  * @param string
  */
 public void setDob(String string) {
  dob = string;
 }
 
 /**
  * @param string
  */
 public void setTitle(String string) {
  title = string;
 }
 /**
  * @return
  */
 public String getForename() {
  return forename;
 }
 
 /**
  * @return
  */
 public String getSurname() {
  return surname;
 }
 /**
  * @param string
  */
 public void setForename(String string) {
  forename = string;
 }
 
 /**
  * @param string
  */
 public void setSurname(String string) {
  surname = string;
 }

 
}

 
i want to validate all the fields 5users*4 =20 and purpose filed and code in 
productbean and save the errors?
 
can any one give me an out line idea to do validation using struts(using the 
files validator-rules.xml,validation.xml and struts-config.xml where we write 
form bean definitions
 
 
regards an

Re: testing struts

2005-10-20 Thread hem hem
Hi Adam,
thanks for your reply,
i my struts(version 1.2) web app,i am using tiles,
action form are submitted through tiles(jsp)templates.
i am having a helper class which copies property values from form bean to model 
object.
i call the methods in this helper class from my action class and put some data 
in the session.
i think you got complete picture of my app.there is no businees logic in my 
action(just copying proprties and putting them in session).
i want to test my action class for below:
1.when the form is populated or not properly
2.am i going to the next page properly(testing action forward and action 
mapping)
3.us the information is properly set into the session all these
common struts action things.
 
if you can suggest me the best approach i will start with that.
i heard mockstrutstestcase is there.
i dont know how to use it.
can you please suggest me the best simple tutorial so thst it saves my time.
struts version=1.2
mochstrutstestcase version=2.3
 
your suggestions are very much appreciated
 
regards and thanks in advance

Adam Hardy <[EMAIL PROTECTED]> wrote:
hem hem on 20/10/05 22:57, wrote:
> 
> i am using struts jar 1.2 in my web app.
> i want to test my struts action classes and jsps using Junit
> are there any nice tutorials on this.
> i want to use MockStrutsTestcase in my junit tests

What precisely do you want to test? There are many different junit 
compatible test tutorials but when I went looking, I was disappointed 
because they all focused on a little niche of testing rather than a 
broad basis offering the whole range.

Right now what comes to mind is:

(1) the model, if you have any model / business logic in your actions 
(which is not advisable, since it's easier testing it if seperate), or 
perhaps validation of http request params.

(2) the controller, or flow of control logic - testing ActionForwards 
returned, looking in mock request or session scopes for expected objects

(3) view logic, presentation code - do JSPs compile, are all required 
Tiles defined, do JSPs throw exceptions at runtime.


Adam


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



-
 Yahoo! FareChase - Search multiple travel sites in one click.  

testing struts

2005-10-20 Thread hem hem
hi all,
i am using struts jar 1.2 in my web app.
i want to test my struts action classes and jsps using Junit
are there any nice tutorials on this.
i want to use MockStrutsTestcase in my junit tests
your suggestions are very much appreciated
 
regards and thanks in advance


-
 Yahoo! FareChase - Search multiple travel sites in one click.  

Re: struts bean utils-problems with properties

2005-10-20 Thread hem hem
how can i resolve this mate?
is there any help from struts bean utils that do the conversion automatically?

Aldo Vadillo Batista <[EMAIL PROTECTED]> wrote:
Maybe it fails because types are incompatible for BeanUtils. All the same
getters and setters must return or accept the same type of Object.

2005/10/19, hem hem :
>
> Hi all,
> i am new to this forum.this is my first post.i hope this mailing list
> helps me.
>
> in the first page in my struts web app, i need to enter the details of 5
> persons.
> they have proprties name,sex,rollnumber and age
> for that i created a bean with these 4 properties which have getter and
> setter methods in it.
> then i instantiated the bean 5 times for the properties of 5 persons
> the bean name is person
> in my action form i instatiated like this:
> Person person1=new Person();
> Person person2=new Person();
> Person person3=new Person(); and so on
> in my jsp i used the property names as person1.name ,
> person1.sex like that.
>
> so far its ok
> but i need to populate the model objects from this form.
> for that
> i used apache commons beanutils as below:
> PersonModel is exactly the same bean as my Person bean with exactly the
> same properties and same getter and setter methods.
> but the datatypes of properties in PersonModel are diffrent from Person
> bean(all the properties are Strings in Person but 2 are Strings,1Long,1int
> in PersonModel)
> PersonModel person1Model=new PersonModel ();
>
> BeanUtils.copyProperties(person1Model,personForm.getPerson1());
>
> but this is failing to copy the properties and throwing
> illegalargumentexception.
>
> can anyone help how can i achieve this(copying properties)
> it seems to be nested property problem.i am new to struts.
>
> your suggestion are very much appreciated.
>
> regards and thanks in advance
>
>
>
>
> -
> Yahoo! Music Unlimited - Access over 1 million songs. Try it free.
>

__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

struts bean utils-problems with properties

2005-10-19 Thread hem hem
Hi all,
i am new to this forum.this is my first post.i hope this mailing list helps me.
 
in the first page in my struts web app, i need to enter the details of 5 
persons.
they have proprties name,sex,rollnumber and age
for that i created a bean with these 4 properties which have getter and setter 
methods in it.
then i instantiated the bean 5 times for the properties of 5 persons
the bean name is person
in my action form i instatiated like this:
Person person1=new Person();
Person person2=new Person();
Person person3=new Person(); and so on
in my jsp i used the property names as person1.name,person1.sex like that.
 
so far its ok
but i need to populate the model objects from this form.
for that 
i used apache commons beanutils as below:
PersonModel is exactly the same bean as my Person bean with exactly the same 
properties and same getter and setter methods.
but the datatypes of properties in PersonModel are diffrent from Person 
bean(all the properties are Strings in Person but 2 are Strings,1Long,1int in 
PersonModel)
PersonModel  person1Model=new PersonModel ();
 
BeanUtils.copyProperties(person1Model,personForm.getPerson1());
 
but this is failing to copy the properties and throwing 
illegalargumentexception.
 
can anyone help how can i achieve this(copying properties)
it seems to be nested property problem.i am new to struts.
 
your suggestion are very much appreciated.
 
regards and thanks in advance




-
 Yahoo! Music Unlimited - Access over 1 million songs. Try it free.