Can someone give me an exp. on how to use "On Input Method Text Changed FXML" ?? because I didn't find any useful exp. on the internet.
I am using a program called : SceneBuilder
You should create a function in a controller class:
public void onAction(){
//Make action when the text change
}
Write the name of the function (here, onAction) in SceneBuilder.
Related
I'm sorry if I can't explain my question but it's hard for me.
I'm trying to send an T class to my method, but I don't have direct access to my object, so, I thought use the name for create an instance with reflections, but I don't know how to send the class T to my method.
This is th definition of my method
void RedirectToActivity<T>(bool closePrevious);
And I have this code for call it
var activity = Activator.CreateInstance("myassembly", "MainActivity");
RedirectToActivity<????>(true);
With the first line I create an Instance of my class MainActivity.
In second line I need to send MainActivity class, and receive it like a T object in RedirectToActivity, but I don't know how to achieve this.
I need some like that...
RedirectToActivity<MainActivity>(true);
But I don't have direct access to MainActivity class.
I've tried this
RedirectToActivity<activity.GetType()>(true);
RedirectToActivity<typeof(activity)>(true);
But not works.
Can you just add a generic parameter argument to your RedirectToActivity method?
void RedirectToActivity<T>(T activity, bool closePrevious)
{
// Do Stuff here
}
And then pass your activity instance in:
var activity = Activator.CreateInstance<MainActivity>();
RedirectToActivity(activity, true);
Can I create a Controller that simply returns an image?
I would like to route this logic through a controller, whenever a variable [LOGO] such requested,
The controller will look up logo.png and replace the image to the variable [LOGO].
I don't want to use a View. I want to do it all with just the Controller.
Is this possible?
I tried some way by following code,
EmailHelper.SendEmail(
Constants.EmailSender.CandidateSupport,
candidate.Email,
Constants.EmailSubject.CandidateUpdateProfile,
Constants.EmailBody.CandidateUpdateProfile
.Replace("[LOGO]", Url.Content("~/Content/Images/logo_small2.png"))
I am not entirely sure what you need, but in answer to "Can I create a Controller that simply returns an image?" you can do this as follows:
public FileResult Image(string filePath)
{
//get your stream
return File(stream, "image/png");
}
Obviously you'd need to think about security given that you are returning items from the file system.
I'm using 2.4.7 and I want to include some validation for two fields which take in prices (e.g. €1 or 2 for €3). Originally I thought that perhaps I would need to resort to validating user input but as the answer suggests it was a database issue.
The encoding within SilverStripe was defaulting to ASCII which converted the symbols such as the euro symbol. In the end I need to add
$this->response->addHeader("Content-Type", "application/json; charset='utf-8'");
to the init method in the controller. This corrected the encoding issue and prevented a hacky workaround taking place. Many thanks for the insight on this one.
Thanks
I'm assuming you want to do this in the CMS. If that's the case, the easiest way is probably to create a new class which extends the TextField class and adds a public function validate() method which performs your validation (see the CreditCardField class for an example).
class FancyCurrencyField extends TextField {
public function validate($validator) {
// Do your validation
if ($invalid) {
$validator->validationError(
$this->name,
"Please don't use currency symbols.",
"validation",
false
);
return false;
}
return true;
}
}
Once you've created your class, you can modify the form fields in your getCMSFields() function on the DataObject and use the new class in place of TextField.
Having said that, it feels like output encoding and not input validation is the root cause of your problem. I'd check to make sure that everything is setup to use UTF-8.
I encountered a problem with the PHP function substr. I just used mb_substr instead and it solved my issue.
Please view http://www.silverstripe.org/general-questions/show/11797#post369831
As mentioned in an earlier question of mine, I'm new to ATK4 and I'm currently learning, so there might come a few more question. Now to my issue.
I've created a region "Sidebar" in my template shared.html and adding the view to it like this:
class Frontend extends ApiFrontend {
function init(){
parent::init();
/*
Other stuff here
*/
$this->addLayout('Sidebar');
}
function layout_Sidebar() {
$this->add('View_Menu', null, 'Sidebar');
}
}
Then I'm creating the view like this:
class View_Menu extends AbstractView {
function init(){
parent::init();
$this->add('HtmlElement')
->setElement('a')
->setAttr('href', 'testurl')
->set('Link');
}
}
This gives me the following error:
Spot is not found in owner's template
Additional information:
spot: Content
Supplying the add function with $this->template->top_tag as third argument solves this problem:
$this->add('HtmlElement', null, $this->template->top_tag)
->setElement('a')
->setAttr('href', 'testurl')
->set('Link');
...but do I really have to add that to every add() call in the view? It doesn't seem right and I'm quite sure it's not!
When you are creating AbstractView, you need to specify a default template. By default your AbstractView will use the region of from your shared.html. In other words AbstractObject assumes the template of the region it replaces.
when you create defaultTemplate() or pass 4th argument to the add() you can specify a different file to be used for template of your sidebar menu.
In either way - the template should contain a where output of any sub-elements will be displayed.
You may inherit from "View" class which already relies on the custom template containing just a . Your idea of using HtmlElement is just like this, because HtmlElement extends View.
I have been thrown in at the deep end with an existing VB.NET project at work. I have never used VB.NET before so I am struggling a little. Does anyone know how to solve the following.
I need to pass an instance to client side and then pass it to a shared method in order to access instance methods from when the shared method.
The starting point is a fileupload control within the HTML of my Contacts.aspx file:
<asp:FileUpload ID="DocUpload1" runat="server" onchange="CallMe();" />
The onchange event calls a javascript method, see below, this uses AJAX PageMethods to called a Shared method in my code behind
This is the script code which is in my Contact.aspx file
<script language="javascript">
function CallMe() {
// call server side method
PageMethods.GetContact(0, CallSuccess, CallFailed, null);
}
// set the destination textbox value with the ContactName
function CallSuccess(res, destCtrl) {
}
// alert message on some failure
function CallFailed(res, destCtrl) {
alert(res.get_message());
}
</script>
This is an example class of the type of thing I want to do, I think I need to use the "instance As Contacts" as an input parameter to the WebMethod function but I don't know how to pass the instance into it:
This is the class within my Contacts.aspx.vb file.
Partial Class Contacts
<System.Web.Services.WebMethod()> _
Public Shared Function GetContact(ByVal instance As Contacts) As String
Return instance.GetContactName() 'This is an instance class which I need to call.
End Function
'This is my instance class which I want to call from the Shared Class.
Public Shared Function GetContactName() As String
Return "Fred Bloggs"
End Function
End Class
If anyone knows the solution please could they update the code as I probably won't be able to understand if you just give a description. I just hope I am along the right tracks.
If I understand you correctly, you want to access a class (your instance) created in the ASP.Net page life-cycle from your PageMethod - eg created during initial page load or file upload etc.
This is not directly possible as PageMethods do not go through the full page life-cycle (they are essentially webservices). So you need to pass some sort of identifier to the client that, when passed back to the server in the PageMethod, can be used to re-create or retrieve your instance.
eg During the initial page load:
session("ContactID") = instance
Your PageMethod might look something like:
Public Shared Function GetContact(ByVal key As String) As String
Return HttpContext.Current.Session(key).GetContactName()
End Function
where the parameter key is the same key you used to store your instance in the session state.
In your javascript:
function CallMe() {
// call server side method
PageMethods.GetContact('ContactID', CallSuccess, CallFailed, null);
}