Java Mailing List Archive

http://www.gg3721.com/

Home » Struts Users Mailing List »

user Digest 11 May 2012 03:45:26 -0000 Issue 9601

user-digest-help

2012-05-11


Author LoginPost Reply

user Digest 11 May 2012 03:45:26 -0000 Issue 9601

Topics (messages 212834 through 212835)

duplicate error messages
 212834 by: Miten
 212835 by: Łukasz Lenart

Administrivia:

---------------------------------------------------------------------
To post to the list, e-mail: user@(protected)
To unsubscribe, e-mail: user-digest-unsubscribe@(protected)
For additional commands, e-mail: user-digest-help@(protected)

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


Attachment: user_212834.eml (zipped)
Hi,

I am using struts 2.3.3 from maven.

I am using below code which produces messages for user and password twice.
one is default message showing up from not sure where as below.
username is required
password is required


while in my validate method on action I have messages as:
username mandatory
password mandatory

I read few messages related to duplication and they suggest things like
singleton. Well in my case I have basic example from maven tutorial
artifact and it has below files:
*login.jsp*
<%@(protected)" %>
<%@(protected)" %>
<html>
<head>
  <title>Sign On</title>
</head>

<body>
<s:form action="Login">
  <s:textfield key="username"/>
  <s:password key="password" />
  <s:submit/>
</s:form>
</body>
</html>


*Login.java*
/*
* $Id: Login.java 739661 2009-02-01 00:06:00Z davenewton $
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package tutorial.example;

public class Login extends ExampleSupport {

 @Override
 public void validate() {
   // TODO Auto-generated method stub
   super.validate();
   if (isInvalid(getUsername())) addFieldError("username", "username
mandatory");

    if (isInvalid(getPassword())) addFieldError("password", "password
mandatory");
   
 }
 
  public String execute() throws Exception {

    if (isInvalid(getUsername())) return INPUT;

    if (isInvalid(getPassword())) return INPUT;

    return SUCCESS;
  }

  private boolean isInvalid(String value) {
    return (value == null || value.length() == 0);
  }

  private String username;

  public String getUsername() {
    return username;
  }

  public void setUsername(String username) {
    this.username = username;
  }

  private String password;

  public String getPassword() {
    return password;
  }

  public void setPassword(String password) {
    this.password = password;
  }

}

*struts.xml actually example.xml*
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
 &quot;-//Apache Software Foundation//DTD Struts Configuration 2.3//EN&quot;
 &quot;http://struts.apache.org/dtds/struts-2.3.dtd&quot;>

<struts>
<package name="example" namespace="/example" extends="struts-default">
  <action name="HelloWorld" class="tutorial.example.HelloWorld">
   <result>/example/HelloWorld.jsp</result>
  </action>

  <action name="Login_*" method="{1}" class="tutorial.example.Login">
   <result name="input">/example/Login.jsp</result>
   <result type="redirectAction">Menu</result>
  </action>

  <action name="*" class="tutorial.example.ExampleSupport">
   <result>/example/{1}.jsp</result>
  </action>
 
 
 
</package>
</struts>

and I invoke the action http://localhost:8080/tutorial/example/Login.action




Regards,

Miten.





--
Sent from the Struts - User mailing list archive at Nabble.com.


Attachment: user_212835.eml (zipped)
Check Login-validation.xml which defines the validation


Regards
--
Łukasz http://www.lenart.org.pl/
mobile +48 606 323 122, office +27 11 0838747
Warszawa JUG conference - Confitura http://confitura.pl/

©2008 gg3721.com - Jax Systems, LLC, U.S.A.