You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Stetze2008 <st...@gmx.de> on 2008/05/28 23:41:22 UTC

XML Validation Problem

Hi there,

I'm using the struts 2 xml validation. but when I send a form with for 
example one empty textfield, the form shows up again and displays the 
field error at the correct position. the problem is that all the other 
fields which have had values before sending the form are empty now too. 
how can I change that?

thanks in advance



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


Re: XML Validation Problem

Posted by Márcio Gurgel <ma...@gmail.com>.
Hi!

Are you using tabbedPanel?
If positive, I'm almost sure that's the reason of "clean fields"... I had
this problem, I found two possible ways to resolve this:
1 - Change s:submit to sx:submit (dojo) sending the attr "targets" to your
current tab.
2 - The most tragic: dont use tabs and s:submit will validade correctly.

2008/5/29 Lukasz Lenart <lu...@googlemail.com>:

> Hello!
>
> Sorry, but I can't help you, from my point of view everything is ok. Do you
> use some JavaScript?
>
>
> Regards
> --
> Lukasz
> http://www.lenart.org.pl/
>

Re: XML Validation Problem

Posted by Lukasz Lenart <lu...@googlemail.com>.
Hello!

Sorry, but I can't help you, from my point of view everything is ok. Do you
use some JavaScript?


Regards
-- 
Lukasz
http://www.lenart.org.pl/

Re: XML Validation Problem

Posted by Stetze <St...@gmx.de>.
this is for example an extract of my ProfileAction-editProfile-validation.xml:

<field name="fullname">
   <field-validator type="requiredstring">
      <message>Please insert your first and last name!</message>
   </field-validator>
   <field-validator type="regex">
    <param name="expression">[a-zA-ZäöüÄÖÜ]+ [a-zA-ZäöüÄÖÜ]+</param>
    <message>Please insert both first and last name!</message>
   </field-validator>    
</field>

And this is the relevant part of my jsp:

<s:form method="POST" action="editProfile">        
<table cellpadding="2" class="mainBody">  
    <tr>
        <td><s:textfield name="username" cssClass="loginForm" key="form.prompt.username"/></td>                       
    </tr>                   
    <tr>
        <td><s:textfield name="fullname" cssClass="loginForm" key="form.prompt.fullname"/></td>                                       
    </tr>
    <tr>
        <td><s:textfield name="email" cssClass="loginForm" key="form.prompt.email"/></td>                       
    </tr>
    <tr>
        <td>
            <s:submit cssClass="loginForm" key="button.saveChanges"/>
        </td>
    </tr>
</s:form>

the correct validation field error message is shown but the form is empty though the fields were filled before sending the form.



-------- Original-Nachricht --------
> Datum: Thu, 29 May 2008 14:48:30 +0200
> Von: "Lukasz Lenart" <lu...@googlemail.com>
> An: "Struts Users Mailing List" <us...@struts.apache.org>
> Betreff: Re: XML Validation Problem

> Hi,
> 
> That's strange, everything looks ok, and the last think is validation.xml
> 
>        showProfile(); // I tried it with and without this line but if
> there
> > is a validation error all fields in the jsps are empty
> >
> 
> You should never do like this, if you want to call such method (which is
> mapped as action), call action via redirect.
> 
> 
> Regards
> -- 
> Lukasz
> 
> http://www.linkedin.com/in/lukaszlenart
> http://jdn.pl/blog/416
> http://www.lenart.org.pl/

-- 
Psssst! Schon vom neuen GMX MultiMessenger gehört?
Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger

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


Re: XML Validation Problem

Posted by Lukasz Lenart <lu...@googlemail.com>.
Hi,

That's strange, everything looks ok, and the last think is validation.xml

       showProfile(); // I tried it with and without this line but if there
> is a validation error all fields in the jsps are empty
>

You should never do like this, if you want to call such method (which is
mapped as action), call action via redirect.


Regards
-- 
Lukasz

http://www.linkedin.com/in/lukaszlenart
http://jdn.pl/blog/416
http://www.lenart.org.pl/

Re: XML Validation Problem

Posted by Stetze <St...@gmx.de>.
Hi,

thanks for looking at the problem. here is the relevant part of my action:

public class ProfileAction extends JombolaAction {

    private static Logger l = Logger.getLogger("UserAction");

    private UserService userService;
    private ScopeUserService scopeUserService;
    private String username;
    private String email;
    private String password;
    private String newPassword;
    private String confirmPassword;
    private String fullname;
    private String scope;
    private Collection<GameScopeValue> scopes;
    private String button;

    private static final long serialVersionUID = 1L;

    public String showProfile() throws Exception {
        UserContext uCtx;
        String result = ERROR;

        uCtx = getUserContext();

        if (uCtx != null) {
            username = uCtx.getUser().getUsername();
            fullname = uCtx.getUser().getFullname();
            email = uCtx.getUser().getEmail();
            result = SUCCESS;
        }
        return result;
    }

    public String editProfile() throws Exception {
        String result = ERROR;

        UserContext uCtx = getUserContext();
       
        if (uCtx != null) {
            uCtx.getUser().setUsername(username);
            uCtx.getUser().setFullname(fullname);
            uCtx.getUser().setEmail(email);
        }

        try {
            userService.updateUser(uCtx.getUser());
            setUserContext(uCtx);
            addActionMessage(getText("message.profile.updated"));
            result = SUCCESS;
        } catch (UserNotExistsException e) {
            l.debug("Exception while updating profile/password of user: "
                    + username + ", user does not exist!");
            addActionError(getText("message.profile.error"));
        }       
        showProfile(); // I tried it with and without this line but if there is a validation error all fields in the jsps are empty
        return result;
    }

is there an error?



-------- Original-Nachricht --------
> Datum: Thu, 29 May 2008 14:20:18 +0200
> Von: "Lukasz Lenart" <lu...@googlemail.com>
> An: "Struts Users Mailing List" <us...@struts.apache.org>
> Betreff: Re: XML Validation Problem

> Hi,
> 
> Your configuration looks ok, maybe there is something in your action,
> maybe
> you reset a profile bean, or recreate it or something in editProfile
> method,
> could you share it?
> 
> 
> Regards
> -- 
> Lukasz
> 
> http://www.linkedin.com/in/lukaszlenart
> http://jdn.pl/blog/416
> http://www.lenart.org.pl/

-- 
Psssst! Schon vom neuen GMX MultiMessenger gehört?
Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger

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


Re: XML Validation Problem

Posted by Lukasz Lenart <lu...@googlemail.com>.
Hi,

Your configuration looks ok, maybe there is something in your action, maybe
you reset a profile bean, or recreate it or something in editProfile method,
could you share it?


Regards
-- 
Lukasz

http://www.linkedin.com/in/lukaszlenart
http://jdn.pl/blog/416
http://www.lenart.org.pl/

Re: XML Validation Problem

Posted by Stetze <St...@gmx.de>.
Hi,

I have defined two action in my struts.xml:

<action name="showProfile" class="profileAction"  method="showProfile">
    <result type="tiles">page.user.profile</result>
</action>

<action name="editProfile" class="profileAction" method="editProfile">
      <result type="tiles">page.user.profile</result>
     <result name="input" type="tiles">page.user.profile</result>
</action>

the showProfile action shows all the user information (user name, nick name, email, ...) in a form on the profile page.
the editProfile action is used to save the changed values of the form and is being validated via xml validation. but as I wrote if the validation returns a field error the error message is shown but all the form contents are gone on the profile page.

what would be the solution to solve this problem?

thanks in advance


-------- Original-Message--------
> Date: Thu, 29 May 2008 08:48:58 +0200
> From: "Lukasz Lenart" <lu...@googlemail.com>
> To: "Struts Users Mailing List" <us...@struts.apache.org>
> Subject: Re: XML Validation Problem

> Hi,
> 
> Did you define input result for that action? How it looks?
> 
> 
> Regards
> -- 
> Lukasz
> 
> http://www.linkedin.com/in/lukaszlenart
> http://jdn.pl/blog/416
> http://www.lenart.org.pl/

-- 
Ist Ihr Browser Vista-kompatibel? Jetzt die neuesten 
Browser-Versionen downloaden: http://www.gmx.net/de/go/browser

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


Re: XML Validation Problem

Posted by Lukasz Lenart <lu...@googlemail.com>.
Hi,

Did you define input result for that action? How it looks?


Regards
-- 
Lukasz

http://www.linkedin.com/in/lukaszlenart
http://jdn.pl/blog/416
http://www.lenart.org.pl/