jsp page to groovy Controller working in webcentersite - oracle12c

How to integrate the jsp page to groovy Controller in webcentersite(oracle) & page navigation

In WCS12c,when you create the template(JSP page) you have to associate respective controller into it.Because when you render the template it will first check whether it has controller or not if controller present then template would call controllor first and do operation ,fetch data and store in map object.
for ex:do opertaion and set into map object models.put("set map object",getmapvalue)
After controller executed it will come to template and execute such as if we are get those map object which setting in controller you would see the respective JSON format.With help of that json you can retrieve the data as per our need.
For calling the controller object you can simply use this way:
${get map object}

Related

Is it possible to have XML Fragments IDs prefixed with its view's ID?

When a XML view is declared, all of its controls IDs are prefixed by the ID of the view itself.
In order to get any control inside the controller it's necessary to use:
this.byId()
... where this points to the controller by default.
I already know that there is
sap.ui.getCore().byId()
as well which can be used to retrieve a control defined in a JS View or created without a view prefix.
I declared a XML fragment with a dialog and a Text control which will contain a text defined by my controller. I noticed that the ID I defined inside the fragment is not prefixed with the view's ID.
My question is: Is it possible to have XML Fragments IDs prefixed with its view's ID (then I could use this.byId instead of sap.ui.getCore) ?
I checked and this appears to be happening only when you are adding the fragment from a controller. If the fragment is defined in the static time in the xml view the ID's of the content derive their name from the view.
The way to get over this is to ensure your fragment ID is derived from your view.
The code would be something like this in your controller.
oPage.addContent(new sap.ui.xmlfragment(this.createId("idFragment"), "fragmentcreation.SampleFragment"));
IdFragment = ID for your fragment
fragmentcreation.SampleFragment = Name of your fragment(fragmentcreation is the folder)

Call Modules Controller from Application Bootstrap

I've asked a question like this previously but I believe this is different (that one was just a general question).
I implemented Zend_Navigation.
For menu I used DB Table to store menu items and did recursion on Array-s to get the tree of menu items.
All of this action takes place in my module called Menu. Inside I have:
Menu --
Controllers --
IndexController.php
Models--
DbTable--
Menu.php
Bootstrap.php
inside index controller I have a function menuGenerator($menu_id)
So following tutorials on Zend_Navigation, the menu is initialized in the application bootstrap.
my function inside application's bootstrap looks like this:
public function _initMenus() {
$menuArray = new Menu_IndexController();
$outArray = $menuArray->menuGenerator(1);
$mainmenu = new Zend_Navigation($outArray);
$this->view->navigation($mainmenu);
}
and it gives me an error:
Fatal error: Class 'Menu_IndexController' not found in D:\Server\xampp\htdocs\project\application\Bootstrap.php on line 8
So, Any ideas how should I make it to work correctly?
P.S. is it possible to start 2 new menus at a time? for ex: I need 1. main menu 2. footer menu (any link to an article would be nice)
By default, Zend Framework's autoloader doesn't autoload controllers in the same way it loads other components (models, view helpers, forms, etc), so PHP throws the error saying it can't find the class. The quickest way to get around this is to explicitly include the controller in Bootstrap.php. The following should work:
public function _initMenus() {
require_once('./Controllers/IndexController.php');
$menuArray = new Menu_IndexController();
$outArray = $menuArray->menuGenerator(1);
$mainmenu = new Zend_Navigation($outArray);
$this->view->navigation($mainmenu);
}
It's pretty unusual to call a controller method during Bootstrap since there are many bootstrapping tasks upon which controller actions depend. In your case, the controller method menuGenerator() is not actually an action, so presumably it will not be a problem.
Nonetheless, it's still unusual enough that I would move the menuGenerator() method out into its own class. Then invoke that operation both at Bootstrap and in your controller.

add conditional logic to controller in zend framework

i want to add a conditional statement to my layout that tests:
the controller param in the url
the existence of a zend_auth()
what's the best way to achieve that? i have tried testing the $this->_getParam('controller') in the layout but got an error. i could just set that variable in all the controllers but that seems kind of dumb. how to best set a variable that i could use later from the layout with some conditional logic? or should i instead add my conditional logic that is inside a view helper and then loaded into the layout?
Edit The controller shouldn't be a URL parameter, unless you are doing some very strange routing. If you were getting a GET (or POST) variable, you would use ->getParam() on the request object, Zend_Controller_Front::getInstance()->getRequest(), as used below. But the controller is a separate property of that request object.
This is the auth part:
$loggedIn = Zend_Auth::getInstance()->hasIdentity();
This is the controller part:
$controller = Zend_Controller_Front::getInstance()->getRequest()->controller;

Grails - Render a template by email

I have a controller's method which renders a template.
This works fine to render the template within my .gsp view.
I am also using the mail-plugin, and I would like to used the same controller's function to render the template by email, hence populating some email with it.
I know how to do that from a .gsp view via Ajax request but do not know any way to do that from within a controller or a service.
The idea would be to use my controller's action more like a function, take the rendered teplate and populate my email with it.
Also, my controller's action needs to have some 'params' properties to work properly.
Any suggestion most welcome.
Regards,
You can use the render tag( http://grails.org/doc/latest/ref/Tags/render.html ) can be used to return a string.
I would move whatever logic you have in your controller that is reusable into a service, and then use this to return a model, then you can simply call this via:
def model = myService.method( ... )
def emailContent = g.render( template: 'mytemplate', model: model)

Passing ViewData to PartialView returned from using Html.Action

I want to embed a partial view in an ASP.NET MVC page by returning it from an action method.
In my base view, I would have:
<%= Html.Action("MyPartialViewAction") %>
My controller would have an action method like:
[ChildActionOnly]
public ActionResult MyPartialViewAction()
{
return PartialView("MyPartialView");
}
I expected the returned partial view (MyPartialView) to have access to the ViewData that was set in the base page's controller action but that doesn't appear to be the case. If I insert the partial view by using the following in my base view it works:
<% Html.RenderPartial("MyPartialView") %>
I don't want to do that though because I want my "MyPartialViewAction" to execute logic to determine WHICH partial view to return.
I believe that it actually creates a new controller, meaning that any view that it creates will have the ViewData from that controller, not the controller that created the view that is invoking the Action method. You might want to try:
Refactor your selection logic to a separate method and use it in your original action to choose the partial view name. Populate that in your model and use it via RenderPartial.
Use TempData (or Session, directly) to hold the previous action's ViewData and hydrate the new controller's ViewData from it.
If the data required is limited, pass it in the RouteValueDictionary -- your action would need to receive these as parameters.