I am looking to get the current site url in my apex class. I want the whole url, not just the domain Instead of https://google.com/ can it be something like https://google.com/page?something=something
I could only find how to put the domain without the full link. Thanks for your help in advance
To get the current URL of the Visualforce page you can use
PageReference pageRef = ApexPages.currentPage();
string currentUrl = pageRef.getUrl();
// Get or set query string parameters
string param1 = pageRef.getParameters().get('param1');
This only works in Visualforce.
When using Lightning, you should pass any additional parameters to the apex controller you need. You can use this JS to get the current page URL to send to the apex controller.
let currentUrl = window.location;
PageReference documentation
Related
I am creating a project in AngularJs at frontend and Spring MVC in backend.
Now assume when a used logged in and if he wants to update his information, for this i have created an api which request for emailid and update the rest object in database of that email id
Now i have some questions,
1.) I dont want to use CookieStore or others sessionStorage or localstorage (because of my personal vulnerability experience and also i want to use session only) in Angular, how can i do it in angular with Spring MVC.
2.) How can i retrieve the email id from session to update data?
3.)If a user goes to another page how can i maintain that session in another page, how can i check that session is there and user is authentic to see the page
Read a lot about it but unable to find the exact solution with session. Answer over there is manage it by cookieStore.or localstorage, Please help
Let's try and see what is happening here using cookies is the right way to this, you may think it is not safe but is the safest way to do it. With cookies you will be sharing the same session in all tabs, so you can handle in all tabs and share it.
There is also an alternative option and is using URL rewriting, quoting #vanje in this question in stackoverflow
the session is only identified via a URL parameter containing the session ID. So every internal URL of your web application has to be enhanced with this parameter using the method HttpServletResponse.encodeURL(). If you are using a web framework like Wicket, chances are good that this is already done for you.
Lets go now with the Angular JS - Spring MVC approach:
There is no need to access the session within the Angular JS front-end, if you need to use it and you are using JSP you may use scriplet to retrieve the information openening a <%= session.getAttribute("user") %> , but as I said there is no need to do this. You may call your function, and retrieve this information in your controller in Spring.
You have a controller in angular JS that calls with http to your REST controller in Spring such like this. assuming that you save your user first in session:
$scope.getUserInfo= function () {
$http.get(appContextPath +'/rest/getuser/').success(function (data) {
$scope.user= data;
});
};
You may have a request mapping for the URL above:
#RequestMapping(value = "/rest/getuser", method = RequestMethod.GET)
#ResponseBody
public User getUserInfo (HttpSession session) {
User nUser = session.getAttribute("user");
return nUser;
}
I think the best way is to create a method in your AngularJS controller and then call it.
Java code:
#RequestMapping(value = "/menu/get", method = RequestMethod.GET, headers="Accept=*/*")
public #ResponseBody Empleado showMenu(HttpSession session) {
Empleado empleado = (Empleado) session.getAttribute("empleado");
return empleado;
}
AngularJS code:
angular.module('myModule')
.controller('myMenuController', ['$scope', '$http'
function($scope, $http){
getEmpleadoInfo = function () {
$http.get(myContextPage + '/menu/get')
.then(function(data) {
$scope.empleado = data;
})
}
getEmpleadoInfo();
}]);
This way, when you load the page, the object will be loaded on the scope.
I am downloading the file from the server using API, for that i have to send session details in header, how can i do it using angularjs?. Please help me out.
Thank you in advance for suggestions.
No - It is not possible to send headers in straight way using $window.open
Yes - Its is possible but not straight way, If you've got server-side control then you can set header value in query string and get it parsed from query string on the back-end.
I don't suggest to pass params with window.open.
BUT you can use window.open like this.
var params = {
access_token: 'An access_token',
other_header: 'other_header'
};
//Add authentication headers in URL
var url = [url_generating_pdf, $.param(params)].join('?');
//Open window
window.open(url);
Please check the details info here
Anybody know, how to get url array params outside controller (for example bootstrap.php)?
CakePHP is still PHP at the end of the day, so you can use any valid PHP method to achieve this. Like:
if (!empty($_SERVER['QUERY_STRING'])) {
// A querystring was set...
}
Or
$url = parse_url($_SERVER['REQUEST_URI']);
if (!empty($url['query'])) {
// A querystring was set...
}
After that you can do anything else that you want to do.
To confirm a purchase I must send an e-mail to the customer with her shopping cart details. I'd like to test the HTML template to use the appropiate CSS, and of course to check the data that arrives to it.
What code should I use instead of setting the Email parameters, to watch how the template will render on the Email?
I'm all new on CakePHP, so your help will be very much appreciated.
Thanks in advance.
~José
This is CakePHP 1.3, but I have a feeling it may work well with 2.0 as well. While there may be other ways to do it, I do by creating a test action in any controller, then return a render call of the email template. Check this out:
function email_test()
{
$this->layout = 'email/html/default';
$user = $this->User->findById(1);
$this->set('name', $user['User']['firstname']);
$this->set('email_heading', 'Welcome to My App');
return $this->render('/elements/email/html/welcome');
}
This action will now render out your email in the browser.
Use the debug transport for testing.
If you want to make it more comfortable write your own transport that creates a new html file in for example APP/tmp/email/.html See the debug transport class as a reference, it's dead easy to do this http://api20.cakephp.org/view_source/debug-transport#l-34
See also the book -> http://book.cakephp.org/2.0/en/core-utility-libraries/email.html#using-transports
Here is the simple method I use to show html/plain text content of email in browser that I want to send using cakephp email class i.e. App::uses('CakeEmail', 'Network/Email');.
Just do an exit at the end of email template file or (email layout file) and then try to send email. it will render the email content.
HTH.
$this->Email->to = $user_id_array[0]['User']['email'];
$this->Email->subject = $arrTemplate[0]['EmailTemplate']['subject'];
$this->Email->replyTo = 'Admin<admin#indianic.com>';
$this->Email->from = 'Admin<admin#indianic.com>';
$this->Email->sendAs = 'html';
$this->Email->template = '/elements/email/html/warning_message';
$this->set('email_message',$arrTemplate[0]['EmailTemplate']['body']);
$this->Email->send();
in this way you can set template for email
If you want to print your email template on localhost for testing then you can use this code.
$this->Email->send();
print_r($this->Email->htmlMessage);
Hi
I want to use Tweetsharp in my mvc.net application to get the list offriends and to share image with them.
But i haven't got the proper documentation and sample for the same. What is need to add in controller action and what in view page.
Please give some links for the same.
Thanks
munish
public void MyMethod() {
TwitterService service = new TwitterService(key, secret, "Token", "Secret");
ListFriendsOptions options = new ListFriendsOptions();
options.Cursor = 12345;
// should the response have user entities
options.IncludeUserEntities = false;
// The screen name of the user for whom to return results for.
options.ScreenName = "";
options.SkipStatus = false;
// The ID of the user for whom to return results for.
options.UserId = 12345;
// this will return a list of friends for the specified user.
TwitterCursorList<TwitterUser> listOfFriends = service.ListFriends(options);
}
Also note the code above uses a third party library called TweetSharp.
As for the images im not sure as to what to do but you can look at the twitter REST API v1.1 for information
https://dev.twitter.com/docs/api/1.1/get/friends/list
https://dev.twitter.com/docs/api/1.1
TweetSharp
https://github.com/danielcrenna/tweetsharp
I don't know about Tweetsharp but take a look at linq2twitter. It provides easy access to the Twitter API through the use of LINQ.