struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alejandro <apar...@gmail.com>
Subject Re: struts2 (2.2.1) adds field error and doesn't return input!!
Date Tue, 26 Mar 2013 17:32:57 GMT
<s:submit value="Save" onclick="javascript:return savePerson();return
false;"/>

The second return never will return false because the first return false
always.


2013/3/26 lucas owen <sr.ilustre@gmail.com>

> I have this wierd problem when validating an action, I add field errors in
> the validate method but Struts2 doesn´t return input and continues
> execution. I show you my configuration (only relevant points):
>
> .jsp
> ------
>
> <script type="text/javascript">
> function savePerson(){
> document.getElementById("formP").action="PersonSave.action";
> document.getElementById("formP").submit();
> return false;
> }
> </script>
>
> <s:form id="formP" validate="false" Acceptcharset="UTF-8">
> <s:textfield key="surname" required="true"/>
> <s:textfield key="name" required="true"/>
> <s:submit value="Save" onclick="javascript:return savePerson();return
> false;"/>
> </s:form>
>
> struts.xml
> ---------------
>
> <!DOCTYPE struts PUBLIC
>     "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN"
>     "http://struts.apache.org/dtds/struts-2.1.dtd">
> <struts>
>     <constant name="struts.objectFactory" value="spring" />
>     <constant name="struts.devMode" value="true" />
>     <constant name="struts.ui.theme" value="appInterna" />
>     <constant name="struts.ui.templateDir" value="template" />
>     <constant name="struts.custom.i18n.resources" value="messages" />
>
>     <package name="project" extends="tiles-default, json-default ,
> struts-default">
>         <result-types>
>             <result-type name="tiles"
> class="org.apache.struts2.views.tiles.TilesResult" default="true" />
>             <result-type name="jasper"
> class="org.apache.struts2.views.jasperreports.JasperReportsResult"/>
>         </result-types>
> <action name="PersonSave" method="save" class="PersonAction">
>              <result name="input" type="dispatcher">
>               <param
> name="location">/WEB-INF/pages/person/person.jsp</param>
>              </result>
>              <result name="success" type="redirectAction">
>                 <param name="actionName">personSuccess</param>
>                 <param name="person.id">${person.id}</param>
>                 <param name="selectedId">${selectedId}</param>
>              </result>
>         </action>
> </package>
>
> </struts>
>
> Action
> ---------
>
> public class PersonAction extends ActionSupport {
>
> Person person;
> PersonService personService;
>  public void validateSave() {
>  if(person.getSurname().equals("")){
> addFieldError("person.surname", getText("mandatory",new
> String[]{"Surname"}));
> }
> if(person.getName().equals("")){
> addFieldError("person.name", getText("mandatory",new String[]{"Name"}));
> }
> }
>  public String save() {
> try {
> personService.save(person);
> addActionMessage(getText("response.save_ok"));
> } catch (Exception e) {
> ErrorHandler.add(this, e, log);
> }
> return "success";
> }
> }
>
> if in the validate i add action errors instead of field errors everything
> works correctly...
>
> Any help would be so much appreciated
> THANKS IN ADVANCE!!!
>

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