Can I give a XBL handler a name to call it? - xul

Can I give a XBL handler a name, so I can call it from my javascript like I do with XBL methods?

It seems not, but you can create an XBL Method and call it from both your handler and other JavaScript. Something like:
<handler event="mouseover">
this.handleMouseOver();
</handler>
...
<method name="handleMouseOver">
<body>...
//and in javascript code:
yourObj.handleMouseOver();

Related

Android: data-binidng: disable click

I want to disable click when variable isAgree is false:
here code:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<import type="android.view.View" />
<variable
name="handler"
type="myproject.ui.SubscribeBrandDialogFragment" />
</data>
<TextView
android:id="#+id/subscribeTextView"
android:layout_width="185dp"
android:layout_height="40dp"
android:layout_marginTop="#dimen/default_margin"
android:background="#{handler.isAgree ? #drawable/border_enable_bg : #drawable/border_disable_bg}"
android:gravity="center"
android:onClick="#{handler.isAgree ? handler.onClickSubscribe() : null}"
android:textColor="#{handler.isAgree ? #color/color_primary : #color/disable_text_color}" />
</layout>
But I get error in android:onClick :
e: [kapt] An exception occurred: android.databinding.tool.util.LoggedErrorException: Found data binding errors.
****/ data binding error ****msg:Cannot find the setter for attribute 'android:onClick' with parameter type void on android.widget.TextView.
file:myproject\layout\subscribe_brand_dialog.xml
loc:100:31 - 100:81
****\ data binding error ****
at android.databinding.tool.processing.Scope.assertNoError(Scope.java:112)
at android.databinding.annotationprocessor.ProcessDataBinding.doProcess(ProcessDataBinding.java:101)
at android.databinding.annotationprocessor.ProcessDataBinding.process(ProcessDataBinding.java:65)
at org.jetbrains.kotlin.kapt3.ProcessorWrapper.process(annotationProcessing.kt:131)
I know that I can fix this by java code. But I want fix this ONLY in xml layout.
Use lambda expression.
android:onClick="#{() -> handler.isAgree ? handler.onClickSubscribe() : null}"
Well a couple things.
First, I would use the controls properties the way they are meant to be used. Setting null on the click handler does not appropriately handle the UI element, you are merely hacking.
You should be disabling the click property or focus property based on your boolean, rather then toggling click handlers to null.
Secondly typically when you are doing Terinaray statements in xml click events I have seen the handler::methodName used rather then handler.methodName to ensure it is handled property in the generated databinding classes for onClick.
Lastly, if you already have the agreed boolean, why not just handle the click in the code. You literally saved yourself 1 line for another line if you think about it.
myClick()
if(isAgree) . //you saved this
.
now you have to do this
ObservableBoolean<> myBool = new ObservableField()
myBool.set(true/false)
of you are adding the
#Bindable to a method.
Either way you are not really saving code by doing the boolean check in the xml and you lose your ability to unit test it or debug. Just my two cents.

Aurelia: call multiple functions on click

Is it possible to call multiple functions on click of an html element?
For example:
<input type="text" click.delegate="myFunc1();myFunc2()" />
Simply write a wrapper function to call your functions. And call the parent function on button click.

How do I make an AJAX call or submit form in ATG

How do I make an AJAX call or submit form in ATG. Here's the code I'm using:
document.getElementById("myP").style.visibility = "hidden";
Will this work in the sense of ATG?
For ajax calls, in applications like spring and standard J2EE, you do a GET or POST call using AJAX for the form's action URL.
In ATG, you dont have action URLs. Rather, you have bean references, somewhat like
<dsp:form id="myForm">
<dsp:input type="myField1" bean="ABCFormHandler.myField1" />
<dsp:input type="myField2" bean="ABCFormHandler.myField2" />
<dsp:input type="submit" bean="ABCFormHandler.myProcess" style="display:none"/>
<dsp:input type="button" id="formSubmitter" value="Submit"/>
</dsp:form>
Here, we have defined a method called handleMyProcess in the ABCFormHandler, which also contains the properties myField1 and myField2.
Notice that the form tag has the id "myForm".
Next, there are two fields viz. "myField1" and "myField2".
There is a submit button which is hidden, by setting the style to "display:none"
Lastly, we have a normal button, for which we have simply set an id called "formSubmitter".
Now, we will use this normal button to submit the form with id "myForm".
We just need to call the form's submit() method using jQuery, which can be done simply as:
$('#formSubmitter').on('click', function(){
$form = $('#myForm');
$form.submit();
});
Hope this helps!

Calling a method from XBL

From a XBL method, when I need to call another method, I do like:
<method name="myMethod_1">
<body>
<![CDATA[
// do staff
]]>
</body>
</method>
<method name="myMethod_2">
<body>
<![CDATA[
document.getElementById("thisElementID").myMethod_1();
]]>
</body>
</method>
I would like to know if is there a way to call the local method without need the element id? I've tried this.myMethod_1() but it says the method don't exist.
In the specific case of an event listener, there is another way around the problem, and that is to pass the element itself as the listener. Of course you only get one handleEvent method, so this is less useful if you're listening to lots of different events on lots of different event targets.
<implementation implements="nsIDOMEventListener">
<method name="handleEvent">
<parameter name="aEvent"/>
<body>
<![CDATA[
// do stuff
]]>
</body>
</method>
can you show us code calling myMethod_2? If you call it like: document.getElement(...).myMethod_2() that's fine, but if you have something like someElement.addEventHandler("click", myxbl.myMethod_2,...); that won't work since event target will be this.
This is important for determining what is this in that context
EDIT: (Tom's reply)
ow, think I got it.. it's exactly this the problem.. I'm calling it from a keypress listener of another document, and the "this" was not what I think..

How to get back to same page after server side processing?

Thinking that , in struts 1.2, say a function public ActionForward abc(){ return null;} will return to the same page.
But i got this exception.
java.lang.NullPointerException
org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:441)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:279)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:738)
How to get into the same page?
You can use
return mapping.getInputForward();
In struts-config.xml, write a forward tag inside your action tag like this.
<action ...>
<forward name = "samePage" path="..."/>
</action>
Now, in your code use
mapping.findForward("samePage");