I'm using play 1.1, I have a URL mapping routes file as,
* /show/{id}/ TestController.show
and TestController is specified as
public static void show(String id){}
When I use above route in my HTML template by #{TestController.show(id)}, I would expect to render as /show/23/ in the browser address bar, but like this instead its rendered as default mapping(/TestController/show?id=23) which has least priority in routes file. Can you please help me how do we render the URL as http://localhost:9000/show/23/?
The actions arguments has to be the same type as these passed in template so if you built href in template with #{TestController.show(id)} where id is porbably type of Long or int declare your action with the same argument.
public static void show(Long id){
... action's body ...
}
Related
I am new to microservices and Lagom framework, in the service api where we make ServiceCalls I do not understand the difference of namedcall, pathcall and restcall. where and when should we use which?
for instance in these calls:
ServiceCall<NotUsed, Cargo, Done> register();
restCall(Method.POST, "/api/registration", register()
ServiceCall<NotUsed, NotUsed, Source<Cargo, ?>> getLiveRegistrations();
pathCall("/api/registration/live", getLiveRegistrations())
ServiceCall<User, NotUsed> createUser();
namedCall("/api/users", this::createUser)
The Lagom Documentation covers it pretty well:
Named
The simplest type of identifier is a name, and by default, that name is set to be the same name as the name of the method on the interface that implements it. A custom name can also be supplied, by passing it to the namedCall method:
default Descriptor descriptor() {
return named("hello").withCalls(
namedCall("hello", this::sayHello)
);
}
In this case, we’ve named it hello, instead of the default of sayHello. When implemented using REST, this will mean this call will have a path of /hello.
Path
The second type of identifier is a path based identifier. This uses a URI path and query string to route calls, and from it dynamic path parameters can optionally be extracted out. They can be configured using the pathCall method.
Dynamic path parameters are extracted from the path by declaring dynamic parts in the path. These are prefixed with a colon, for example, a path of /order/:id has a dynamic part called id. Lagom will extract this parameter from the path, and pass it to the service call method.
ServiceCall<NotUsed, Order> getOrder(long id);
default Descriptor descriptor() {
return named("orders").withCalls(
pathCall("/order/:id", this::getOrder)
);
}
Multiple parameters can of course be extracted out, these will be passed to your service call method in the order they are extracted from the URL:
Rest Call
The final type of identifier is a REST identifier. REST identifiers are designed to be used when creating semantic REST APIs. They use both a path, as with the path based identifier, and a request method, to identify them. They can be configured using the restCall method:
ServiceCall<Item, NotUsed> addItem(long orderId);
ServiceCall<NotUsed, Item> getItem(long orderId, String itemId);
ServiceCall<NotUsed, NotUsed> deleteItem(long orderId, String itemId);
default Descriptor descriptor() {
return named("orders").withCalls(
restCall(Method.POST, "/order/:orderId/item", this::addItem),
restCall(Method.GET, "/order/:orderId/item/:itemId", this::getItem),
restCall(Method.DELETE, "/order/:orderId/item/:itemId", this::deleteItem)
);
}
I want to use specific Joomla template (with no navigation, no top and bottom) for users that connect to website through my mobile app with iframe in it. I assume that this users will start connection from specific address with tmpl param (or something similar) but is there a way to lock this template for these users?
Maybe there is some plugin to set template in session data and override default template choice?
There is a Joomla extension called Template Assigner - http://extensions.joomla.org/extension/template-assigner . It does exactly what you want.
Plugin allows me to set template only for specyfic user group, not to switch template accordingly to url but thanks to Your idea I created very simple plugin to do this, code below:
defined('_JEXEC') or die;
class plgSystemMobiler extends JPlugin
{
public function onAfterInitialise()
{
$app = JFactory::getApplication();
$jinput = $app->input;
if (isset($_REQUEST['mobile'])) $par=(int)$_REQUEST['mobile'];
if (isset($par)) $jinput->cookie->set('mobile', $par, time() + 100000, $app->get('cookie_path', '/'), $app->get('cookie_domain'), $app->isSSLConnection());
$cookie=$jinput->cookie->get('mobile');
if (intval($cookie)>0) JFactory::getApplication()->input->set('templateStyle', intval($cookie));
}
}
I want to understand how url helper works.
For example, in my template I have:
my super url
and in controller:
func (c Pages) IndexPages() revel.Result {
...
}
I need url like
http://localhost:9000/pages?page=1
I don't want to write:
func (c Pages) IndexPages(page int) revel.Result {
because I want to check if the controller contains the param page.
How to add my template var to c.Params.Query with the url helper?
Revel url helper code in template.go
// Return a url capable of invoking a given controller method:
// "Application.ShowApp 123" => "/app/123"
func ReverseUrl(args ...interface{}) (template.URL, error) {
We need to update the manual with information about this template function, but you can see in the link and code above how it's intended to be used. You pass it a controller and action with parameters and it creates a template.URL object with the matching route.
It seems you're not interested in how the url helper works (though that's what you asked). You want to know how to pass the page variable to the template? In your controller you need to pass page via c.RenderArgs["page"] = page. Then you can reference it in your template: my super url Revel Template Doc.
As you noted, you can manually get the value for page with page := c.Params.Query.Get("page") if you don't want to use the parameter binding feature.
how can I get certain parameter from url directly from struts2?
http://apps.facebook.com/testApp/myaction.action#param1=a1afacf5¶m2=AAADpzov7PBMBA
Previously, getting param1 and 2 from javascripts in JSP using window.location.href.slice. Now I want to get those params directly from action class. I tried to get those using request.getParameter("param1"), but getting null.
All you need to create property in your action class and provide there getter and setters,once this is done framework will push them in to the ValueStack with action processing.
OGNL expression will help you to access the properties being there in the Value-Stack.You have to do something like
Action Class
public class MyAction extends ActionSupport{
private String param1;
private Sting param2;
// provide getter and setters for the above properties
public String execute() throws Exception{
// your action logic and provide param1,param2 values which you want in you JSP
return SUCCESS;
}
}
once you action get called both the parameters will be pushed to value stack with the values you have provided in the action class,all you need to access them in your JSP with OGNL like
JSP page
<s:property name="param1" value="param1"/>
<s:textfiled name="param2" value="%{param2}"/>
I don't understand the purpose of using templates in Kohana. I see almost no difference in the process of building a view with a template controller vs a regular controller, except that the template controller is tied to a given template and so is less flexible. What are the advantages?
Building view with regular controller:
Class Controller_Hello extends Controller
{
public function action_index()
{
$view = View::factory('page');
$view->page_title = 'My Hello App';
$view->content = 'hello, world!';
$view->sidebar = View::factory('parts/sidebar');
$this->response->body($view);
}
}
Building view with template controller:
Class Controller_Hello extends Controller_Template
{
public $template = 'page';
public function action_index()
{
$this->template->page_title = 'My Hello App';
$this->template->content = 'hello, world!';
$this->template->sidebar = View::factory('parts/sidebar');
}
}
Controller_Template is just an example of how you can implement your own templating-system.
It is not ready-to-use solution (at least for my projects usually). Check this one controller (it is also not ready-to-use solution but possibly it will help you understand point of extending different controllers for different purposes): http://pastie.org/2563595
I am sure there are other, maybe better solutions for templating systems. But why am I using templates in Kohana?
Think about multiple pages, all based upon one layout/design scheme. So I build a template controller using a certain view, defining layout/design, defining content, header and footer "areas". In the template controller I am loading the CSS files and script files, setting the title and meta values of the website, because every single site is using these CSS/script files with the same meta values and title.
So in every Controller extending the template controller I don't need to load the CSS/script files anew, set the meta values and title etc... But I could change all these values, maybe add a CSS file only for a single site.
Maybe all the mentioned sites have the same footer and/or header: I assign the header/footer view to the template within the template controller, so I don't need to do that in all the controller extending the template controller. Or all actions in one controller have the same header/footer, so I assignt he header and footer few in the before() function of the controller...
For me templates in kohana are a good utility for building small web applications.