I constructed this live template:
public boolean is$var$Present() {
return $varname$.isPresent();
}
I expect the variable name I type to be converted to camelCase and inserted to "return ...." string, but this does not happen. the "return ..." part stays unchanged.
In Live Templates Page, you can click "Edit variables" to make connection between two or more variables.
In your case, you can set $varname$ as camelCase(var).
Screenshot:
Result:
I found a solution:
public boolean is$capitalizedVar$Present() {
return $var$.isPresent();
}
Related
I recently got a report that a few Google Analytics event category names were being recorded with an i character with out a dot on top.
Pageviews and events occurring twice, once without dots over the i.
I had to look to believe it. Sure enough, I had an event called favorite and there was a handful called favorıte. Copy and paste that weird character into a terminal or a monospace font just to see how weird it is. favorıte
My first suspicion is my code where I generate the strings for the category names using toString on an enum.
public enum AnalyticsEvent {
SCREEN_VIEW,
FAVORITE,
UN_FAVORITE,
CLICK_EVENT,
... reduced for brevity;
public String val() {
return this.toString().toLowerCase();
}
}
Example of how that enum is used:
#Override
public void logSearchTag(String type, String value) {
...
logGAEvent(AnalyticsEvent.SEARCH_TAG.val(), type, value);
}
private void logGAEvent(String category, String action, String label) {
... // mGATracker = instance of com.google.android.gms.analytics.Tracker;
mGATracker.send(addCustomDimensions(new HitBuilders.EventBuilder()
.setCategory(category)
.setAction(action)
.setLabel(label))
.build());
...
}
I am going to solve this by actually assigning a string to the enums and instead return that in the val() function.
Though, I am curious if anyone knows why on a small handful of devices Enum.toString returns the enum name with that weird character replacing the i. I mean small. 8 out 50,000 is the average. Or is it possible that assumption is wrong and the error is on analytics service end somewhere? Really highly doubt that.
The String#toLowerCase method uses the default locale of the system. This use locale specific characters such as ı instead of i. In order to fix this problem call toLowerCase with a locale:
String test = "testString";
test.toLowerCase(java.util.Locale.ENGLISH) // Or your preferred locale
I assembled this piece of code from parts all over the XPages community, you might recognise a few:
var submitId= param.get( '$$xspsubmitid');
var component:com.ibm.xsp.component.xp.XspEventHandler= PageData.getComponentByClientId(submitId, view);
dprint("id= " + component.getClass().toString())
var params= component.getParameters();
for(var x:com.ibm.xsp.complex.Parameter in params) {
dprint(x);
dprint(x.getName());
dprint(x.getValue());
}
PageData is a managed bean, and getComponentByClientId does exactly what it says; its code, for completeness' sake:
public UIComponent getComponentByClientId(String id, UIComponent root) {
UIComponent component= new XspQuery().byClientId(id, root);
return component;
}
And as for XspQuery:
package org.openntf.xsp.extlib.query;
I want to find the name of the current field that triggered the partial update, and the form it is in. Both elements, fields and forms, are internal to my application. Their names are put in two Event Parameters, like this:
<xp:this.parameters>
<xp:parameter name="formName" value="#{javascript:compositeData.formName}"></xp:parameter>
<xp:parameter name="fieldName" value="#{javascript:compositeData.fieldName}"></xp:parameter>
</xp:this.parameters>
The issue is: when I put this code in one of the page events afterRestoreView, beforeRenderResponse or afterRenderResponse, the name of the parameter is correctly printed, but the call to getValue() never returns anything! More accurately: execution of the code stops, I don't know the exact error yet (which isn't exactly accurate, I admit).
How can I fetch these parameters?
TIA!
Looking at code in Mastering XPages, the way to access the value of an eventHandler parameter within the eventHandler's SSJS code is just to reference the name property as a variable. e.g. print(formName + ": " + fieldName)
For example I have the following block of code:
public String getDbSchema() {
return DB_SCHEMA;
}
Is there a shortcut to quickly turn this code into
public String getDbSchema() {
return properties.getProperty(DB_SCHEMA);
}
Currently I have to do properties.getproperty then take out right bracket and re-insert it into the end of the statement
When you select getProperty from the code completion, instead of pressing Enter, press the shortcut of Edit | Complete Current Statement (e.g. Ctrl+Shift+Enter), and DB_SCHEMA will be wrapped into call parentheses.
Sure, you can use a structural find and replace that is a little bit smart.
First, let's presume that this code has the form return XYZ; where XYZ is a constant identifier (CAPS or _)
Then you can go into search and replace in files (ctrl+shift+R), tick Case Sensitive and Regular Expression and enter:
Text to find: return ([A-Z_]*);
Replace with: return properties.getProperty($1);
I have a page that contains diff properties with checkboxes.and I have another page that contains the summary of the above page. That means If I check the in the first page its has to reflect the relavent field details in the summary page.But as the variable type in pojo is boolean its showing as true of false.I unable to get the fields name.Im using HTML front end and java. Please help me on how to do it.
In pojo the variable is boolean. Im fetching that variable in the next summary page. I need that to be name of the variable not true of false. hope im clear
You can add the string you want to properties, evaluate your boolean, get the message you want from properties according to the boolean value:
public String getLabel(){ if(isMarried) return messages.get(marriedPropertyMessage);}
I'm trying to send an email using a javascript code in a Java project. Database connection works fine, I already tested it. I got the error:
javax.script.ScriptException: sun.org.mozilla.javascript.internal.EvaluatorException: missing ) after formal parameters (#1) in at line number 1
The only information of relevance is not readily reported: the final JavaScript string executed. Make sure to look at relevant data when debugging. After inspecting the final string it will be apparent why it is incorrect and trivial to "fix".
Hint: it will look something like function sendMail(userblah, foo#bar.qux) { .., which is indeed invalid JavaScript.
The problem and solution should be self-evident from that - use fixed parameters (variable names) in the function declaration and supply arguments (values) via the invokeFunction call.
Solution:
// The following parameter names are JAVASCRIPT variable names.
String script = "function sendMail(username, email, body) { ..";
// And pass correct arguments (values), in order. The variables used
// here are JAVA variables, and align by-position with the JS parameters.
inv.invokeFunction("sendMail", username, email, "EMAIL SENT!!!!");
In addition, the getElementById (invalid ID) is wrong, the body parameter is never used, and encodeURIComponent should be used (instead of escape).
Not sure if this is a typo or not:
result = request.executeQuery("SELECT user.login, user.email "
+ "FROM user " + );
It looks like you are missing the end of your statement.
Hmmmm, your function definition:
function sendMail("username","email") {...}
doesn't look like valid JavaScript to me, apart of that, you never call the function.
Pseudocode, how to do it:
function sendMail(username, email) {
var link = "jadajada" + email; // .... etc
}
sendMail("+username+","+email+");