You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Satheesh Kannan A B <sa...@hcl.com> on 2010/12/09 18:24:18 UTC

Iterator: field errors.

Hi,

I have a requirement like, am iterating a list of values and populating in a text box. It may be more than 5 rows. I need to validate whether it's an integer and want to display error message below the field. For a normal field with a unique I have done it well. But I don't know how to do for list if validation fails. Since after validation fails the iterator grid also empty and am not able to display field values.
<s:iterator values="objectList">
<s:textfield name="bo.name" />
<s:fielderror name="bo.name" ></s:fielderror>
</s:iterator>
Please suggest me how to populate grid values in jsp if validation fails and also validation messages below field of each row.



Thanks  and Regards,

Satheesh Kannan A B


________________________________
::DISCLAIMER::
-----------------------------------------------------------------------------------------------------------------------

The contents of this e-mail and any attachment(s) are confidential and intended for the named recipient(s) only.
It shall not attach any liability on the originator or HCL or its affiliates. Any views or opinions presented in
this email are solely those of the author and may not necessarily reflect the opinions of HCL or its affiliates.
Any form of reproduction, dissemination, copying, disclosure, modification, distribution and / or publication of
this message without the prior written consent of the author of this e-mail is strictly prohibited. If you have
received this email in error please delete it and notify the sender immediately. Before opening any mail and
attachments please check them for viruses and defect.

-----------------------------------------------------------------------------------------------------------------------

Re: Iterator: field errors.

Posted by Li Ying <li...@gmail.com>.
>> Since after validation fails the iterator grid also empty

I think, you need separate the field names by list index -- since your
data model is a list--,
to indicate which [textfield] should be captured by which POJO element.





And also, you need separate the field name of validation error, to
indicate POJO element it belongs.

So, i think code should likes:

JSP:
<s:iterator values="myList" status="rowStatus">
  <s:textfield name="myList[#rowStatus.index].name" />
  <s:fielderror name="myList[#rowStatus.index].name" />
</s:iterator>

Validation:
addFieldError("myList[index].name",getText("error.code"));

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Iterator: field errors.

Posted by Satheesh Kannan A B <sa...@hcl.com>.
Hi,
Generic I have given a pojo class List<PojoClassBO> and am doing validation as a separate method in my action as given below.
 List<PojoClassBO> boList = new ArrayList< PojoClassBO >();

Public String save(){

        If(isValid())
        {
                Continue....
        }else{
Return "input";
}

Return "success";
}

Private Boolean isValid(){
        if(String.isEmpty()){
                addFieldError("bo.FieldName",getText("error.code"));
        }

        if (getFieldErrors().size() > 0) {
                        return true;
        } else{
                Return false;
        }
}



Thanks  and Regards,

Satheesh Kannan A B


-----Original Message-----
From: Li Ying [mailto:liying.cn.2010@gmail.com]
Sent: Friday, December 10, 2010 5:35 AM
To: Struts Users Mailing List
Subject: Re: Iterator: field errors.

What is the data type of objectList?

How did you execute the validation, and how did you add the field error?

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


::DISCLAIMER::
-----------------------------------------------------------------------------------------------------------------------

The contents of this e-mail and any attachment(s) are confidential and intended for the named recipient(s) only.
It shall not attach any liability on the originator or HCL or its affiliates. Any views or opinions presented in
this email are solely those of the author and may not necessarily reflect the opinions of HCL or its affiliates.
Any form of reproduction, dissemination, copying, disclosure, modification, distribution and / or publication of
this message without the prior written consent of the author of this e-mail is strictly prohibited. If you have
received this email in error please delete it and notify the sender immediately. Before opening any mail and
attachments please check them for viruses and defect.

-----------------------------------------------------------------------------------------------------------------------

Re: Iterator: field errors.

Posted by Li Ying <li...@gmail.com>.
What is the data type of objectList?

How did you execute the validation, and how did you add the field error?

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org