Showing posts with label parameter. Show all posts
Showing posts with label parameter. Show all posts

28 July 2011

How to inject parameter to controller in spring 3?

Solution for Spring 3 (Annotations)

In many tutorials you can find how to add parameter to service and it looks is , it is and ...  it doesn't work when you trying apply "easy successful receipe" to controller, so shit hit the fun and you feel screwed up.

However... solution for your problem is still simply.
You need:
1)Set parameter in META-INF/context.xml
 <?xml version="1.0" encoding="UTF-8"?>
 <Context displayName="Another awsome program">
 <Parameter name=" param/naughty/url " value="http://pastor.ovh.org"/>
 (... bunch of other stuff ...) 
</Context> 
2) In your marvellous controller
package org.ovh.pastor.mvc.controller; 
 @Controller
public classAwsomeController  {
(  ... bunch of other stuff ...) 
private @Value("${param/naughty/url}") String doggyWebsite;  
 public void setDoggyWebsite ( String doggyWebsite ) {
this. doggyWebsite = doggyWebsite ;
 } 
(  ... bunch of other stuff ...)   
}

 Little explanation of most important line:

  private @Value("${param/naughty/url}") String doggyWebsite;

where :
  •  private  - modifier
  • @value - is a lovely annotation that contain information where is parameter 
  • String -  data type 
  •  doggyWebsite  - vairable name
     

Hope , it helps . Keep smiling and pray that someday spring will be easier , better explained by examples.

22 February 2011

call function with parameter from external javascript file

I discover something interesting recently.

Many beginners already know that but for some unknown reason quite often forgot about it.
 Apparently, many people  have a weird problem with  ... call function with parameter from external javascript file.
 Some solutions are quite confusing, so here you can find  easiest solution :

our html file looks:

<html>
<head>
<script type="text/javascript" src="js/message.js"></script>
</head>
 <body>

 <script type="text/javascript">
showMessage("This message is sent as parameter")
 </script>

 </body>
</html>

our js file looks:

function showMessage(text) {
alert(text);
}


 That's it.