Are links always bookmarkable? - wicket

I created an ordinary link, nothing fancy:
Link<Integer>link=new Link<Integer>("link") {
#Override
public void onClick() {
setResponsePage(MyTarget.class);
}
};
In HTML I see:
<a wicket:id="link" href="./?0-3.ILinkListener-link">link</a>
When I click the link, I see in the URL field:
http://localhost:8080/wicket/bookmarkable/my.test.own.wicket_quickstart.MyTarget
So are my links always bookmarkable?

Wicket links are mostly internal links and you cannot be sure about the generated URL. If you want to get an bookmarkable link, use Bookmarkable link instead. http://ci.apache.org/projects/wicket/apidocs/6.x/org/apache/wicket/markup/html/link/BookmarkablePageLink.html
Link<Integer>link = new Bookmarkable<Integer>("link", MyTarget.class);
If you want to have a nice URL, use page mounting / request mappin, see https://cwiki.apache.org/confluence/display/WICKET/Request+mapping

No.
Links will redirect you somewhere. If you use a Bookmarkable Page and setResponsePage you will get a nice redirected url.
You can also use a link to change some model value
Link<Integer>link=new Link<Integer>("link") {
#Override
public void onClick() {
myModel.setObject("Great success!");
}
};
In this case you will be taken back to your page.

Related

Share TEXT to Google+?

I'd like to allow my website (which allows users to post to the website itself, and, if the user enables it, Facebook) to be able to share a user's post to Google+. After reading through all I could find on stackoverflow/etc., it seems that the official G+ API doesn't allow you to post anything to a user's stream. That means that I'd have to use a share button/link/etc. The problem is, every share button/link I've found is for sharing _url_s...but I want to share text (and maybe an added URL if necessary)! If there's already a question answering this, sorry for reposting, but it must've gotten hidden beneath the ~ 5,000 questions that got returned for my search :D
Thanks,
Matthew
The Share API is intended for sharing pages, although you could share a page and have the Snippet data on that page contain the text that you want to share.
You may also want to look into the History API, which is currently in developer preview, to see if it will meet your needs or to provide feedback to Google about what changes you might need.
You may post a message like this..
whether G+ app is installed in your phone or not
try it, this works for me
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
shareMediaButton = (Button) findViewById(R.id.share_button);
shareMediaButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
if(isGooglePlusInstalled())
{
PlusShare.Builder share = new PlusShare.Builder(MainActivity.this);
share.setText("write your message here.....!");
//share.addStream(selectedImage);
share.setType("text/plain");
startActivityForResult(share.getIntent(), 0);
}else{
Intent shareIntent = new PlusShare.Builder(MainActivity.this)
.setType("text/plain")
.setText("write your message here.....!")
.getIntent();
startActivityForResult(shareIntent, 0);
}
}
public boolean isGooglePlusInstalled()
{
try
{
getPackageManager().getApplicationInfo("com.google.android.apps.plus", 0 );
return true;
}
catch(PackageManager.NameNotFoundException e)
{
return false;
}
}
});
}

facebook redirect app from canvas page to fan page

im building facebook app as a iframe app in fan page. My problem at the moment is next: i added facebook request dialog (http://developers.facebook.com/docs/reference/dialogs/requests), and everything goes well except for one thing: when a user gets notification, the links goes to canvas page, not to fan page (where i would like to go...)
Since i cant convince facebook to add some funcionality (that would be great), im looking for a way to automaticly redirect from app canvas page to fan page, where this app is added as iframe tab.
I hope somebody understands what i want to do... :)
thanks, Peter
I also wanted to make sure that users view my Facebook app via a Facebook Page Tab (rather than via the Facebook App page or by directly viewing the actual site itself). I have managed to achieve it with this Javascript in a <script> tag in the head of my document (tested Mac/PC FF,Chrome,Opera,IE6-8,Safari).
<script type="text/javascript">
function NotInFacebookFrame() {
return top === self;
}
function ReferrerIsFacebookApp() {
if(document.referrer) {
return document.referrer.indexOf("apps.facebook.com") != -1;
}
return false;
}
if (NotInFacebookFrame() || ReferrerIsFacebookApp()) {
top.location.replace("http://permalink-to-my-facebook-page-tab");
}
</script>
If I understand you correctly, you can do this:
top.location.href='http://www.facebook.com/YOUR_PAGE_NAME?sk=app_YOUR_APP_ID'
or you can use a header to redirect to that url. This will redirect to the application's tab on your fan page.
My application is quite dynamic and I never know which page it's added to. So when I used URL 'http://www.facebook.com/YOUR_PAGE_NAME?sk=app_YOUR_APP_ID' it only redirected me to page, but not to application tab. What I do is:
1) I get page id from signed_request (the encrypted in base64url parameter that your app gets once someone comes to the page, so you have to decrypt it and pick id value from JSON page object)
2) Then I get page data from https://graph.facebook.com/PAGE_ID_YOUR_GET. You get JSON object with some page data in response in JSON format.
3) Only after point 2 I get 'link' value of page from response. It's like http://www.facebook.com/pages/Some-Page-Name
4) And finally I add '?sk=app_YOUR_APP_ID' to page link.
Maybe that's too complicated, but that's the only way it worked for me the way I expected (redirecting exactly to page application tab).
<script type="text/javascript">
function NotInFacebookFrame() {
return top === self;
}
function ReferrerIsFacebookApp() {
if(document.referrer) {
return document.referrer.indexOf("apps.facebook.com") == -1;
}
return false;
}
if (NotInFacebookFrame() || ReferrerIsFacebookApp()) {
top.location.replace("http://permalink-to-my-facebook-page-tab");
}
</script>

GWT, navigate to page using POST request

I want to navigate away from my GWT app using a POST request. If it was a GET I could just use Window.Location and if I didn't need it to be dynamic I could hardcode a Form and submit it. The FormPanel seems to be the answer for creating and submitting forms, but it does it asynchronously, and I want the user's browser to follow the form submit, navigating away from my app, rather than just displaying the results.
Anybody know how to do this in Google Web Toolkit?
Ok, got it!
Passing null to the String constructor of the FormPanel effectively says "replace the current page":
new FormPanel((String)null);
This forum thread was useful:
http://www.coderanch.com/t/120264/GWT/GWT-HTTP-post-requests
Havn't done this myself but I think you should be able to create a FormPanel and then cast its element to FormElement and call submit on the FormElement.
FormPanel formPanel = new ...
FormElement form = FormElement.as(formPanel.getElement());
form.submit();
I thought your FormElement idea would work, but unfortunately it still sends it async. Both the following successfully send a request and get a response, but alas, the page doesn't change.
_tmp.addClickHandler(new ClickHandler()
{
#Override
public void onClick(ClickEvent event_)
{
doPost();
}
public native void doPost() /*-{
var form = document.createElement("form");
form.setAttribute("method", "GET");
form.setAttribute("action", "http://www.google.com");
document.body.appendChild(form);
form.submit();
}-*/;
});
and
public void onClick(ClickEvent event_)
{
final FormPanel form = new FormPanel();
form.setAction("http://www.google.com");
form.setMethod(FormPanel.METHOD_GET);
RootPanel.get("main").add(form);
FormElement formElement = FormElement.as(form.getElement());
formElement.submit();
}
I realize that I've used GET methods in my examples above. This is purely because Google only accepts GET. I had the same result trying POST on my own servlets.
There must be a way of doing this.

How to eliminate ReturnUrl from the browser address

Now on unauthorized attempt to access an action my ASP.NET MVC app redirects user to the login page and generates URL shown below:
http://www.mysite.com/Account/Log?ReturnUrl=%2Ftest%2Fsampleaction
So, is there a way to eliminate this string from the URL, but to save it somewhere to be able to redirect user back after login?
I wonder why you would want to do that. Maybe you are sick of misused, excessive URL parameter orgies, and you like the clean RESTful URL style and the elegant way it can be implemented using the new ASP.NET Routing feature.
However, in this case, this is exactly what URL parameters are intended for. It's not bad practice or bad style at all. And there is absolutely no reason to apply SEO witchery to your login page. So why should you make this process less reliable for the user by requiring the session state directly (or indirectly via TempData), or any other workaround?
I would consider to implement my own AuthorizationFilter and do the redirect.
public class AuthorizationFilter : IFilter
{
public bool Perform(ExecuteWhen exec, IEngineContext context,
IController controller, IControllerContext controllerContext)
{
if (context.CurrentUser.IsInRole("Administrator"))
{
return true;
}
context.Response.Redirect("home", "index");
return false;
}
}
Before redirecting to login action store url
TempData["redirect-url"] = "/requested/page/url";
on login action read that value and pass it to login view and put to a hidden field.
I would implement a AuthorizationAttribute
public class MyAuthorizeAttribute : AuthorizeAttribute
{
public override void OnAuthorization(AuthorizationContext filterContext)
{
base.OnAuthorization(filterContext);
if (filterContext.Result is HttpUnauthorizedResult)
{
filterContext.HttpContext.Session["ReturnUrl"] = filterContext.HttpContext.Request.UrlReferrer.AbsoluteUri
filterContext.Result = // Your login page controller;
}
}
}
This is not tested but might help you find the answer
Good luck to you, please provide your solution when found.

Deeplinking using GWT History Token within a Facebook iFrame Canvas

I would like to deep link directly to a GWT app page within a Facebook iFrame Canvas.
The first part is simple using GWT's History token with URLs like:
http://www.example.com/MyApp/#page1
which would open page1 within my app.
Facebook Apps use an application url like:
http://apps.facebook.com/myAppName
which frames my Canvas Callback URL
http://www.example.com/MyApp/
Is there a way to specify a canvas callback url (or bookmark url) which will take the user to a specific page rather than the index page?
Why? you may ask. Besides all the benefits of deep links...
I want the "Go To Application" url to take users to an index page w/ marketing material (the canvas callback url)
I want the "Bookmark URL" to take (likely returning) users to a login page and bypass downloading the marketing content (and that huge SWF file).
This may seem to be a hack but here it goes.
Facebook allows the application to tack on parameters to the url ?x=123
So I'm checking the window location to see if it contains my special 'page' parameter and loading that page. Below is my solution given that I'm using GWT + gwt-presenter's PlaceManager class.
The application deep url ends up being http://apps.facebook.com/myAppName?page=page1
EventBus eventBus = injector.getEventBus();
// Load PlaceManager so it can start listening
PlaceManager placeManager = injector.getPlaceManager();
String currentPlace = History.getToken();
String place = Window.Location.getParameter( "page" );
if (place != null && !place.isEmpty()) {
// send user to the place on the URL line
eventBus.fireEvent( new PlaceRequestEvent( new PlaceRequest( new Place (place) ) ));
} else if ("".equals(currentPlace)) {
// Nothing in URL, load default GWTpage
eventBus.fireEvent( new PlaceRequestEvent(new PlaceRequest( IndexPresenter.PLACE)));
} else {
// fire a body to the Place Manager to activate the requsted Place
placeManager.fireCurrentPlace();
}