Wicket external link - hyperlink

I am using an external link which points to a url which is generated after a user fills in a form
I am using a IModel as the model for the external link, sadly it looks like the model does not update the external links url, has anyone had an issue like this before.
My code
model declaration:
IModel<String> url;
model assignment within an onsubmit ajax link
url = getUrl(params);
declaration of external link:
ExternalLink el = new ExternalLink("el", url);

You are overwriting the Model, but you should just overwrite the ModelObject.
try
url.setObject(/*get input as string from anywhere);
Also, make sure you added the ExternalLink or a Parent of ExternalLink to the AjaxRequestTarget.

Related

How to pass form field values to a service method in Grails?

I'm learning Grails and I'm having a problem. I implemented scaffolding to give me the basic web forms I want and I auto-generated the controller. In the controller the create code will accept the input of a URL from a field on the form and then call a service method, let's call it executeUrl() which uses that url in some logic, which is already done.
So I have a class called myUrl that has a property urlName.
myUrl aUrl = new Url(params)
UrlService.executeUrl(aUrl)
The issue is I need to fill aUrl.urlName with something since I'm passing null above. When the user enters a url in the create form how do I grab that value and pass it to executeUrl()? Hopefully this makes sense, the tutorials have helped up to this point but I'm stuck. Any help appreciated.
So starting with your form field, assume you have something like:
<input type="text" name="url" id="url" />
In your controller you can grab the url from params like
def url = params.url
If you have a field named url in your MyUrl class you can just pass params to the constructor and groovy will bind the value for you, naming is key here
class MyUrl {
String url
}
new MyUrl( params )

Yii url manger with url parameter

What I'm trying to do is when users signup they have a custom url to their own page, like so:
www.mysite.com/username
How do I set the url manager in Yii to achieve this? I know you use this somehow.
<url:[a-zA-Z0-9_-]+>
Also with controller and action with that url:
www.mysite.com/username/controller/action
Put this AFTER ALL the other rules:
// one content type can have special urls
'<username>' => 'user/view',
Assuming your controller's function params are:
public function actionView($username) {
// code to get user by username (instead of by $id)
you can do what ever you want after reading this:
http://www.yiiframework.com/doc/guide/1.1/fr/topics.url#using-custom-url-rule-classes
i advice to read all article! it's helpfull!

Composite C1 routes.MapPageRoute - Directing to a page

I have been adding some custom routes which are not working
I can get this MVC route working but the problem is it simple routes directly to the view rather than the page which contains the master layout etc.
routes.MapRoute("Job-Listing", "job-detail/{category}/{title}/{id}", new { controller = "JobSearchModule", action = "JobDetail" });
I tried routing to a page which existed like following. This didn't work and simple went to a page not found.
routes.MapPageRoute("Job-Listing", "job-detail/{category}/{title}/{id}", "~/job-seekers/job-search/job-detail");
I guessed that this might be because this is not a physical path and there is some other routing going off under the hood. So I tested this by adding a Route to a physical page like follows. (this route worked)
routes.MapPageRoute("jobDetail2Route", "job-detail/{category}/{title}/{id}", "~/Text.aspx");
This got my thinking that composite c1 might have a physical URL which the C1 routing maps to. I'm sure I have seen at some point something to do with a /Renderers/Page.aspx. Does anyone know if I could somehow route to a physical page in this way?
Thanks
David
OK so some further information.
I realized I could get the the URL using /Renderers/Page.aspx?pageId=d622ab3b-2d33-4330-9e6e-d94f1402bc80. This URL works fine so I attempted to add a new route to this URL like as follows...
routes.MapPageRoute("Job-Listing", "job-detail/{category}/{title}/{id}", "~/Renderers/Page.aspx?pageId=d622ab3b-2d33-4330-9e6e-d94f1402bc80");
Unfortunately this still didn't work. I got an error on the Renderers/Page.aspx
Value cannot be null.
Parameter name: pageUrlData
Any ideas?
Rather than using the internal representation of a page URL like ~/Renderers/Page.aspx?pageId=d622ab3b-2d33-4330-9e6e-d94f1402bc80 you should use the public representation like /my/page/url.
To get the public representation from the page id you could use a method like this:
using Composite.Data;
...
public string GetPageUrl( Guid pageId )
{
using (var c = new DataConnection())
{
PageNode p = c.SitemapNavigator.GetPageNodeById(pageId);
return p.Url;
}
}
This will give you the public URL of the page with the provided id. If you are running a website with different content languages this method will automatically fetch you the URL matching the language of the page your MVC Function is running on.
Should you have the need to explicitly change the language of this URL use the overload DataConnection(CultureInfo culture) instead of the default constructor.
With the above method in place you should be able to do this:
routes.MapPageRoute(
"Job-Listing",
"job-detail/{category}/{title}/{id}",
GetPageUrl(Guid.Parse("d622ab3b-2d33-4330-9e6e-d94f1402bc80"));

In an asp.net-mvc site, is there a better way to get the full base URL?

I have an asp.net-mvc site and I send out a lot of email from my site. Before I used to send email from my controller and I used this code to get the base url:
protected string GetBaseUrl()
{
return string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Authority, Url.Content("~"));
}
that is because i obviously need fully formed URL. so in a normal link on a page that i have href="/GoHere", i would want that to translate to:
"http://www.mysite.com/GoHere"
not just relative URLs given that they are going in emails like
"/GoHere"
I am now refactoring my controller to move all of this code outside of it, but i find myself passing this baseURL string around (because the function above relies on Request which is in namespace:
System.Web
and I can't seem to access this request object outside the controller class. Right now I am passing a string BaseURL all over the place so when i need to generate the emails, i can append the relative URL after the base URL but that feels very hacky
Is there a better way to get the baseURL (either through the Request object or not) outside of a controller class in an asp.net-mvc website?
UrlHelper.Action has an overload that accepts "protocol". Use this to generate full urls that conform to your routing table.
var baseUrl = Url.Action("Index", "Home", null, Request.Url.Scheme);
MSDN Source
In a default project MVC with default routing, this would return something like:
http://mydomain.com
Note that if you can't use/access the HttpRequest object, consider passing in the scheme or if you know it's always "https" (for example) then you can use a magic (hard coded) string or read it from a settings/config file.
You can access the HttpRequest object outside of the controller by using:
var request = System.Web.HttpContext.Current.Request;
On a similar note, you will have the same problem accessing the UrlHelper instance of the controller. You can create an instance like so:
var url = new UrlHelper(System.Web.HttpContext.Current.Request.RequestContext);
HttpRequest.RequestContext is new to .NET 4.0. I thought I'd not that seeing as though you haven't specified a working version. MSDN source.
The problem is determining the baseURL programmatically as it is highly relative and a website is reachable at many URLs. For example:
* http://localhost/GoHere locally
* http://localhost:8080/GoHere locally on another port
* http://127.0.0.1/GoHere locally by the loop back address
* http://10.0.10.5/GoHere the internal IP of the machine
* http://72.34.56.78/GoHere the public IP of the machine
* http://www.mysite.com/GoHere preferred public URL
* http://www.bestsiteever.com/GoHere SEO URL
It would be easier to set the baseURL in a config file, a database by customer, or whatever way you need to correlate the baseURL to the email.

Getting client side validation to work with Telerik MVC Window

I am using a telerik mvc window extension that is triggered from a custom template link in a telerik mvc grid. The window is modal and it contains a form for editing data. After successfully implementing client side validation using a standard html page, I have been trying to implement it in the telerik mvc window. I have not been able to do so successfully. Is this possible? Does anybody have a working example of this?
Thanks
Ozzy
You need to load to page in an IFrame. To do this, make sure the url in LoadContentFrom method starts with http or https:
<%= Html.Telerik().Window()
.Name("Window")
.LoadContentFrom("http://www.example.com")
%>
if you're using the Url.Action() helper to get the url, include the protocol parameter to get the full url.
E.g
Url.Action("action name","controler name", "http") <--may also need to include route values or null route value dictionary.
To close to window, you'll need to make a call back to the parent view, try this:
add a bool isValid property to your model
if succesfully validated, reload the view with isValid equals true
onload:
var isValid = '<%: Model.IsValid%>';
if(isValid == 'True')
{
window.parent.$('#MyWindow').data('tWindow').close();
}
It is possible. First make sure you have your ViewModel property that needs validation decorated with the appropriate attribute. Eg: [Required(ErrorMessage = "this is required")]
Then include all the client validation scripts found in telerik's folder in your application.
<script src="../../Scripts/jquery.validate.min.js" type="text/javascript"></script>
Make sure you use the latest build of teleriks extensions. hth.

Resources