You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by RogerV <ro...@googlemail.com> on 2010/12/08 13:49:01 UTC

@VisitorFieldValidator message formatting question.

I'm trying to use the VistorFieldValidator via annotation. The validator is
being called ok, but using @VisitorFieldValidator() all the error messages
are prefixed with the word "null". If I use
@VisitorFieldValidator(appendPrefix=false) then I don't get any error
messages at all.

Why am I getting "null" prepended to the message string and how do I stop
it?

Regards
-- 
View this message in context: http://old.nabble.com/%40VisitorFieldValidator-message-formatting-question.-tp30405050p30405050.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: @VisitorFieldValidator message formatting question.

Posted by Maurizio Cucchiara <ma...@gmail.com>.
Forget what I told you about fieldName, try simply to change value of messge
inside visitor annotation. Setting append prefix to true tells struts to
prepend message to error fileds.

Maurizio Cucchiara

Il giorno 10/dic/2010 16.02, "RogerV" <ro...@googlemail.com> ha
scritto:
>
>
> Maurizio Cucchiara wrote:
>>
>> At first glance everything would seems correctly configured (except
>> for that unnecessary RequiredFieldValidator).
>> Did you try it in a more recent version (like 2.2.1)?
>>
>
> Hi Maurizo,
>
> I've upgraded to 2.2.1 and the behaviour has changed slightly, but still
> doesn't tie in with my expectations or yours (if I've understood your
> explanation). Firstly specifying the fieldName="My Field Name" still makes
> no difference whether I include or exclude it. Secondly, specifying
> appendPrefix="false" with or without message="My Message" still produces
no
> error messages at all in both cases.
>
> Where the difference occurs is now @VisitorFieldValidator(fieldName =
"YOUR
> FIELD NAME", appendPrefix = true, message = "") now outputs <Message
> generated by error condition> instead of <null><Message generated by error
> condition>
>
> Regards
> --
> View this message in context:
http://old.nabble.com/%40VisitorFieldValidator-message-formatting-question.-tp30405050p30426854.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>

Re: @VisitorFieldValidator message formatting question.

Posted by RogerV <ro...@googlemail.com>.

Maurizio Cucchiara wrote:
> 
> At first glance everything would seems correctly configured (except
> for that unnecessary RequiredFieldValidator).
> Did you try it in a more recent version (like 2.2.1)?
> 

Hi Maurizo,

I've upgraded to 2.2.1 and the behaviour has changed slightly, but still
doesn't tie in with my expectations or yours (if I've understood your
explanation). Firstly specifying the fieldName="My Field Name" still makes
no difference whether I include or exclude it. Secondly, specifying
appendPrefix="false" with or without message="My Message" still produces no
error messages at all in both cases.

Where the difference occurs is now @VisitorFieldValidator(fieldName = "YOUR
FIELD NAME", appendPrefix = true, message = "") now outputs <Message
generated by error condition> instead of <null><Message generated by error
condition> 

Regards
-- 
View this message in context: http://old.nabble.com/%40VisitorFieldValidator-message-formatting-question.-tp30405050p30426854.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: @VisitorFieldValidator message formatting question.

Posted by Maurizio Cucchiara <ma...@gmail.com>.
At first glance everything would seems correctly configured (except
for that unnecessary RequiredFieldValidator).
Did you try it in a more recent version (like 2.2.1)?


2010/12/9 RogerV <ro...@googlemail.com>:
>
>
> Maurizio Cucchiara wrote:
>>
>> Sorry,
>> I meant annotated *classes*
>>
>
> Sure, BaseAction - all other actions extend this;
>
> @ParentPackage(value = "admin")
> @Result(name="start",location="add-new-user-flow.jsp")
> public class AddNewUserFlow extends ActionSupport implements SessionAware,
> Preparable,
>                                                                                                                ValidationAware {
>
>        private static final long serialVersionUID = 1L;
>        private Map<String, Object> session;
>        private NewUserDTO newUserDto;
>
>        @Override
>        public void prepare() throws Exception {
>                newUserDto = (NewUserDTO) session.get("NEWUSERDTO");
>        }
>
>        @Action(value="start-create-user")
>        public String startConversation() {
>                newUserDto = new NewUserDTO();
>                session.put("NEWUSERDTO", newUserDto);
>                return "start";
>        }
>
>
>        @Override
>        public void setSession(Map<String, Object> session) {
>                this.session = session;
>        }
>
>
>        @VisitorFieldValidator(appendPrefix=true, message="my message")
>        public NewUserDTO getNewUserDTO() {
>                return newUserDto;
>        }
>
>
>        public void setNewUserDto(NewUserDTO addNewUserDto) {
>                this.newUserDto = addNewUserDto;
>        }
>
>        public Map<String, Object> getSession() {
>                return session;
>        }
>
> }
>
>
> The NewUserDTO
>
> public class NewUserDTO {
>
>        private String userName;
>        private String email;
>        private int serialNumber;
>        private List<License> licenses;
>        private Authority authority;
>        private Password password;
>
>    @Autowired
>    private UserJpaController userdao;
>
>    public NewUserDTO() {
>        this.licenses = new ArrayList<License>();
>    }
>
>        public String getUserName() {
>                return userName;
>        }
>        @RequiredFieldValidator(message="User Name is required")
>        @RequiredStringValidator(message="User Name is required")
>        public void setUserName(String userName) {
>                this.userName = userName;
>        }
>
> ... more getters & setters.
> --
> View this message in context: http://old.nabble.com/%40VisitorFieldValidator-message-formatting-question.-tp30405050p30417733.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>



-- 
Maurizio Cucchiara

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


Re: @VisitorFieldValidator message formatting question.

Posted by RogerV <ro...@googlemail.com>.

Maurizio Cucchiara wrote:
> 
> Sorry,
> I meant annotated *classes*
> 

Sure, BaseAction - all other actions extend this;

@ParentPackage(value = "admin")
@Result(name="start",location="add-new-user-flow.jsp")
public class AddNewUserFlow extends ActionSupport implements SessionAware,
Preparable,
														ValidationAware {

	private static final long serialVersionUID = 1L;
	private Map<String, Object> session;
	private NewUserDTO newUserDto;

	@Override
	public void prepare() throws Exception {
		newUserDto = (NewUserDTO) session.get("NEWUSERDTO");
	}
	
	@Action(value="start-create-user") 
	public String startConversation() {
		newUserDto = new NewUserDTO();
		session.put("NEWUSERDTO", newUserDto);
		return "start"; 
	}
	

	@Override
	public void setSession(Map<String, Object> session) {
		this.session = session;
	}

	
	@VisitorFieldValidator(appendPrefix=true, message="my message")
	public NewUserDTO getNewUserDTO() {
		return newUserDto;
	}

	
	public void setNewUserDto(NewUserDTO addNewUserDto) {
		this.newUserDto = addNewUserDto;
	}

	public Map<String, Object> getSession() {
		return session;
	}

}


The NewUserDTO

public class NewUserDTO {

	private String userName;
	private String email;
	private int serialNumber;
	private List<License> licenses;
	private Authority authority;
        private Password password;
    
    @Autowired
    private UserJpaController userdao;
    
    public NewUserDTO() {
    	this.licenses = new ArrayList<License>();
    }
    
	public String getUserName() {
		return userName;
	}
	@RequiredFieldValidator(message="User Name is required")
	@RequiredStringValidator(message="User Name is required")
	public void setUserName(String userName) {
		this.userName = userName;
	}

... more getters & setters.
-- 
View this message in context: http://old.nabble.com/%40VisitorFieldValidator-message-formatting-question.-tp30405050p30417733.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: @VisitorFieldValidator message formatting question.

Posted by Maurizio Cucchiara <ma...@gmail.com>.
Sorry,
I meant annotated *classes*

2010/12/9 Maurizio Cucchiara <ma...@gmail.com>:
> My guess is that there is something wrong in your configuration.
> Could you post your annotated class?
>
> 2010/12/9 RogerV <ro...@googlemail.com>:
>>
>>
>>
>> Maurizio Cucchiara wrote:
>>>
>>> Ok,
>>> try this
>>>
>>> @VisitorFieldValidator(fieldName = "YOUR FIELD NAME", appendPrefix =
>>> true, message = "YOUR MESSAGE")
>>>
>>> Struts should use Field Name like a prefix for every invalid element
>>> inside the annotated object.
>>>
>>
>> This doesn't work as I would expect;
>>
>> @VisitorFieldValidator(fieldName = "YOUR FIELD NAME", appendPrefix = true,
>> message = "YOUR MESSAGE") outputs <Your Message><Message generated by the
>> error condition>
>>
>> @VisitorFieldValidator(fieldName = "YOUR FIELD NAME", appendPrefix = true,
>> message = " ")
>> outputs <null><Message generated by the error condition>
>>
>> @VisitorFieldValidator(fieldName = "YOUR FIELD NAME", appendPrefix = false,
>> message = " ")  or
>>
>> @VisitorFieldValidator(fieldName = "YOUR FIELD NAME", appendPrefix = false,
>> message = "YOUR MESSAGE ")
>>
>> outputs no error message at all.
>>
>> It doesn't make any difference whether I include the fieldName="YOUR FIELD
>> NAME" or not, the string "YOUR FIELD NAME" never appears in the ouput.
>>
>> I'm using 2.0.18 if that's of any relevance. I would have expected that
>> specifying either appendPrefix=false or appendPrefix=true, message=" " to
>> display only the generated error message. What is the fieldName attribute
>> for?
>>
>> Regards
>>
>>
>>
>> --
>> View this message in context: http://old.nabble.com/%40VisitorFieldValidator-message-formatting-question.-tp30405050p30417193.html
>> Sent from the Struts - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>
>
>
> --
> Maurizio Cucchiara
>



-- 
Maurizio Cucchiara

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


Re: @VisitorFieldValidator message formatting question.

Posted by Maurizio Cucchiara <ma...@gmail.com>.
My guess is that there is something wrong in your configuration.
Could you post your annotated class?

2010/12/9 RogerV <ro...@googlemail.com>:
>
>
>
> Maurizio Cucchiara wrote:
>>
>> Ok,
>> try this
>>
>> @VisitorFieldValidator(fieldName = "YOUR FIELD NAME", appendPrefix =
>> true, message = "YOUR MESSAGE")
>>
>> Struts should use Field Name like a prefix for every invalid element
>> inside the annotated object.
>>
>
> This doesn't work as I would expect;
>
> @VisitorFieldValidator(fieldName = "YOUR FIELD NAME", appendPrefix = true,
> message = "YOUR MESSAGE") outputs <Your Message><Message generated by the
> error condition>
>
> @VisitorFieldValidator(fieldName = "YOUR FIELD NAME", appendPrefix = true,
> message = " ")
> outputs <null><Message generated by the error condition>
>
> @VisitorFieldValidator(fieldName = "YOUR FIELD NAME", appendPrefix = false,
> message = " ")  or
>
> @VisitorFieldValidator(fieldName = "YOUR FIELD NAME", appendPrefix = false,
> message = "YOUR MESSAGE ")
>
> outputs no error message at all.
>
> It doesn't make any difference whether I include the fieldName="YOUR FIELD
> NAME" or not, the string "YOUR FIELD NAME" never appears in the ouput.
>
> I'm using 2.0.18 if that's of any relevance. I would have expected that
> specifying either appendPrefix=false or appendPrefix=true, message=" " to
> display only the generated error message. What is the fieldName attribute
> for?
>
> Regards
>
>
>
> --
> View this message in context: http://old.nabble.com/%40VisitorFieldValidator-message-formatting-question.-tp30405050p30417193.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>



-- 
Maurizio Cucchiara

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


Re: @VisitorFieldValidator message formatting question.

Posted by RogerV <ro...@googlemail.com>.


Maurizio Cucchiara wrote:
> 
> Ok,
> try this
> 
> @VisitorFieldValidator(fieldName = "YOUR FIELD NAME", appendPrefix =
> true, message = "YOUR MESSAGE")
> 
> Struts should use Field Name like a prefix for every invalid element
> inside the annotated object.
> 

This doesn't work as I would expect;

@VisitorFieldValidator(fieldName = "YOUR FIELD NAME", appendPrefix = true,
message = "YOUR MESSAGE") outputs <Your Message><Message generated by the
error condition>

@VisitorFieldValidator(fieldName = "YOUR FIELD NAME", appendPrefix = true,
message = " ")
outputs <null><Message generated by the error condition>

@VisitorFieldValidator(fieldName = "YOUR FIELD NAME", appendPrefix = false,
message = " ")  or 
 
@VisitorFieldValidator(fieldName = "YOUR FIELD NAME", appendPrefix = false,
message = "YOUR MESSAGE ") 

outputs no error message at all.

It doesn't make any difference whether I include the fieldName="YOUR FIELD
NAME" or not, the string "YOUR FIELD NAME" never appears in the ouput.

I'm using 2.0.18 if that's of any relevance. I would have expected that
specifying either appendPrefix=false or appendPrefix=true, message=" " to
display only the generated error message. What is the fieldName attribute
for?

Regards



-- 
View this message in context: http://old.nabble.com/%40VisitorFieldValidator-message-formatting-question.-tp30405050p30417193.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: @VisitorFieldValidator message formatting question.

Posted by Maurizio Cucchiara <ma...@gmail.com>.
Ok,
try this

@VisitorFieldValidator(fieldName = "YOUR FIELD NAME", appendPrefix =
true, message = "YOUR MESSAGE")

Struts should use Field Name like a prefix for every invalid element
inside the annotated object.

2010/12/8 RogerV <ro...@googlemail.com>:
>
>
>
> Maurizio Cucchiara wrote:
>>
>> According with documentation appendPrefix "Determines whether the field
>> name
>> of this field validator should be prepended to the field name of the
>> visited
>> field to determine the full field name when an error occurs"
>> this link should be useful
>> http://struts.apache.org/2.0.14/docs/using-visitor-field-validator.html
>>
>> Maurizio Cucchiara
>>
>>
>
> I've read the documentation several times. I didn't understand that
> paragraph then, and I still don't
> understand what it means now :(
>
> Any pointers to an example?
>
> Regards
>
> --
> View this message in context: http://old.nabble.com/%40VisitorFieldValidator-message-formatting-question.-tp30405050p30405827.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>



-- 
Maurizio Cucchiara

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


Re: @VisitorFieldValidator message formatting question.

Posted by RogerV <ro...@googlemail.com>.


Maurizio Cucchiara wrote:
> 
> According with documentation appendPrefix "Determines whether the field
> name
> of this field validator should be prepended to the field name of the
> visited
> field to determine the full field name when an error occurs"
> this link should be useful
> http://struts.apache.org/2.0.14/docs/using-visitor-field-validator.html
> 
> Maurizio Cucchiara
> 
> 

I've read the documentation several times. I didn't understand that
paragraph then, and I still don't
understand what it means now :(

Any pointers to an example?

Regards

-- 
View this message in context: http://old.nabble.com/%40VisitorFieldValidator-message-formatting-question.-tp30405050p30405827.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: @VisitorFieldValidator message formatting question.

Posted by Maurizio Cucchiara <ma...@gmail.com>.
According with documentation appendPrefix "Determines whether the field name
of this field validator should be prepended to the field name of the visited
field to determine the full field name when an error occurs"
this link should be useful
http://struts.apache.org/2.0.14/docs/using-visitor-field-validator.html

Maurizio Cucchiara

Il giorno 08/dic/2010 13.49, "RogerV" <ro...@googlemail.com> ha
scritto:
>
> I'm trying to use the VistorFieldValidator via annotation. The validator
is
> being called ok, but using @VisitorFieldValidator() all the error messages
> are prefixed with the word "null". If I use
> @VisitorFieldValidator(appendPrefix=false) then I don't get any error
> messages at all.
>
> Why am I getting "null" prepended to the message string and how do I stop
> it?
>
> Regards
> --
> View this message in context:
http://old.nabble.com/%40VisitorFieldValidator-message-formatting-question.-tp30405050p30405050.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>