You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Oliver Reflé <o....@gmx.de> on 2002/02/20 10:21:35 UTC
form looses valuse when validation maps back
Hello All,
i have for me a real strange problem. When i validate my form and there are
missing
fields then it is mapped back to the input page. All the error messages are
shown correctly.
The only thing is that my form is empty and the user has to reenter all
values, which is
really annoying.
This is my entry in the struts-config.xml
<action path="/admin/createCompany"
type="com.transwide.services.uma.web.action.admin.CreateCompanyAction"
name="companyForm"
scope="session"
input="/uma/admin/create-company-step1.jsp"
validate="false">
<forward name="success"
path="/uma/admin/create-company-step2.jsp">
</forward>
<forward name="failure"
path="/uma/admin/failure.jsp">
</forward>
</action>
The validation is done in the action class(business reason), but i tried it
also in the Form which
makes no difference. Here is part of my Action which handles the validation
ActionErrors errors = new ActionErrors();
try{
CompanyForm companyForm = (CompanyForm)form;
// some validations
if (companyForm.getAccountName()==null ||
StringUtils.isEmpty(companyForm.getAccountName())) {
errors.add("accountname", new
ActionError("error.accountname"));
}
if (companyForm.getCompanyName()==null ||
StringUtils.isEmpty(companyForm.getCompanyName())) {
errors.add("companyname", new
ActionError("error.companyname"));
}
if (companyForm.getPrefix()==null ||
StringUtils.isEmpty(companyForm.getPrefix())) {
errors.add("prefixlength", new ActionError("error.prefix"));
} else if (companyForm.getPrefix().length() != 3) {
errors.add("prefixlength", new
ActionError("error.prefixlength"));
}
if(companyForm.getCompanyTypes()==null ||
StringUtils.isEmpty(companyForm.getCompanyTypes())) {
errors.add("companytypes", new
ActionError("error.companytypes"));
}
if(companyForm.getVatNumber()==null ||
StringUtils.isEmpty(companyForm.getVatNumber())) {
errors.add("vatnumber", new ActionError("error.vatnumber"));
}
if (!errors.empty()) {
saveErrors(request, errors);
return (new ActionForward(mapping.getInput()));
}
I can take the form data out of the session with a scriptlet and display the
values, but
struts don't fills out the form automaticly. First thing i took a look on
it, that i maybe
configured the scope of the form incorrect and when mapping back to input he
trys to generate
a new form which is only stored in the request. But there all settings seem
to be correct.
Any idea ??
oliver
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: form looses valuse when validation maps back
Posted by Keith <ke...@yahoo.com>.
did you search the archive? you should be able to find the solution there.
--- Oliver_Refl� <o....@gmx.de> wrote:
> Hello All,
> i have for me a real strange problem. When i validate my form and there are
> missing
> fields then it is mapped back to the input page. All the error messages are
> shown correctly.
> The only thing is that my form is empty and the user has to reenter all
> values, which is
> really annoying.
>
> This is my entry in the struts-config.xml
>
> <action path="/admin/createCompany"
>
> type="com.transwide.services.uma.web.action.admin.CreateCompanyAction"
> name="companyForm"
> scope="session"
> input="/uma/admin/create-company-step1.jsp"
> validate="false">
> <forward name="success"
> path="/uma/admin/create-company-step2.jsp">
> </forward>
> <forward name="failure"
> path="/uma/admin/failure.jsp">
> </forward>
> </action>
>
> The validation is done in the action class(business reason), but i tried it
> also in the Form which
> makes no difference. Here is part of my Action which handles the validation
>
> ActionErrors errors = new ActionErrors();
>
> try{
>
> CompanyForm companyForm = (CompanyForm)form;
>
> // some validations
> if (companyForm.getAccountName()==null ||
> StringUtils.isEmpty(companyForm.getAccountName())) {
> errors.add("accountname", new
> ActionError("error.accountname"));
> }
> if (companyForm.getCompanyName()==null ||
> StringUtils.isEmpty(companyForm.getCompanyName())) {
> errors.add("companyname", new
> ActionError("error.companyname"));
> }
> if (companyForm.getPrefix()==null ||
> StringUtils.isEmpty(companyForm.getPrefix())) {
> errors.add("prefixlength", new ActionError("error.prefix"));
> } else if (companyForm.getPrefix().length() != 3) {
> errors.add("prefixlength", new
> ActionError("error.prefixlength"));
> }
> if(companyForm.getCompanyTypes()==null ||
> StringUtils.isEmpty(companyForm.getCompanyTypes())) {
> errors.add("companytypes", new
> ActionError("error.companytypes"));
> }
> if(companyForm.getVatNumber()==null ||
> StringUtils.isEmpty(companyForm.getVatNumber())) {
> errors.add("vatnumber", new ActionError("error.vatnumber"));
> }
> if (!errors.empty()) {
> saveErrors(request, errors);
> return (new ActionForward(mapping.getInput()));
> }
>
> I can take the form data out of the session with a scriptlet and display the
> values, but
> struts don't fills out the form automaticly. First thing i took a look on
> it, that i maybe
> configured the scope of the form incorrect and when mapping back to input he
> trys to generate
> a new form which is only stored in the request. But there all settings seem
> to be correct.
>
> Any idea ??
>
> oliver
>
>
> --
> To unsubscribe, e-mail: <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
>
=====
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Search the archive:-
http://www.mail-archive.com/struts-user%40jakarta.apache.org/
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Keith Bacon - Looking for struts work - South-East UK.
phone UK 07960 011275
__________________________________________________
Do You Yahoo!?
Yahoo! Sports - Coverage of the 2002 Olympic Games
http://sports.yahoo.com
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>