How to solve the following Error ?

Nageswarara Rao December 12, 2012

Hi

I write the javascript in velocity file like

"#if($document.form.userNameContains.value == ($element.getName()));"

when i run this i got the following error , please tell me the solution to this error

($document.form.userNameContains.value) of '==' operation has null value. If a reference, it may not be in the context. Operation not possible. templates/allusers.vm [line 24, column 69]

2 answers

1 vote
Andy Brook [Plugin People]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 13, 2012

As Ive said previously, you are mixing server side and client side concepts, velocity != javascript.

Prefixing a # indicates that it is a velocity directive, this runs on the server and dissapears by the time it gets to the client. What you are seeing as a server side validation failure, because $document cannot be resolved on the server.

Perhaps you could explain what you are trying to achieve? Where is this velocity triggered from, an action? Perhaps you are looking for the current user that is available (if driven by an action) via $action.getLoggedInUser(), then you can use the various methods on the user for your comparison.

0 votes
Mizan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 13, 2012

Try #if($document.form.userNameContains.value.equals($element.getName()));

Also check if both the values are not null

Suggest an answer

Log in or Sign up to answer