BlackBerry objectlistfield development - blackberry

How to get the index of ObjectListField in BlackBerry so that on clicking one item in the object list ,we can retrieve the position of an item?

Use the following code for getting the index :
int index = yourObjectListField.getSelectedIndex();
And the following code to get the text:
String selectedText += yourObjectListField.get(yourObjectListField, yourObjectListField.getSelectedIndex());

Related

Request.Cookie - Cookie is not sent or not excepted

I'm developing a shopping cart function.
I need product data from the server that used to render the shopping cart page.
Every time the Add-to-cart button is hit, I stringify this array ( using JSON.stringify() ):
var CART = [{productId: 102, quantity: 3} , {productId: 211, quantity: 6}];
I want to get this data using Request.Cookie["shoppingCart"] in my ASP.NET application,
but when I debug It is always null
This is what the browser return when I call document.cookie
"shoppingCart=[{\"productId\":101617121,\"quantity\":2}]"
But when I try to change the value of the cookie to something like: shoppingCart=testresult ,
the Request.Cookie["shoppingCart"] then has value.
Thank you in advance for helping me!
I solved it.
First, I tried to remove some special chars which are: " and , .
And Request.Cookie then had values. So it seems like ASP.NET just doesn't except these characters in cookie value. ( Tell me if I'm wrong please )
My solution was instead of convert JSON string, I used this formular for each product in the shopping cart : var item = `{productId}:{quantity}`; .
For example:
var sampleCookie = "11231:16:15121:8";
Split the string with : char then use a simple code to get the data.
My code for this:
string cookie = Request.Cookies["shoppingCart"];
var cartItems = new List<CartItem>();
if (cookie != null && cookie.Length > 0)
{
string[] values;
values = cookie.Split(':');
int i = 0;
while (i < values.Length)
{
cartItems.Add(new CartItem()
{
ProductId = values[i],
Quantity = Convert.ToInt32(values[i+1])
});
i += 2;
}
}

How to get the row index of a Grid Element (Vaadin Flow)

I am using Vaadin 14 (currently rc7).
Getting the row index of a Grid with a ListDataProvider is simple. I use the code below.
final Collection<T> c = ((ListDataProvider)grid.getDataProvider()).getItems();
final List<T> list;
if (c instanceof List) {
list = (List)c;
} else {
list = new ArrayList(c);
}
return list.indexOf(item);
However, how to get this in the generic use case, not assuming a ListDataProvider?
Use Case
Make a specific row visible in the Grid based on some app logic, so "scroll to a row".

How to setDescription of the name of a element in facet?

I need help about how to add description on facet, here I will put my code so you could see what I am thinking :
List<Facet> facetsExecutor = findFacets("executorFaceting", "caseFileUserApps.activeUsers.executor", fullTextQuery, queryBuilder, includeZeroCounts);
addMoreFacets(najdeniFaceti, facetsExecutor, rb.getString("com..........executor"));
for(int i=0;i<facetsExecutor.size();i++){
String name=facetsExecutor.get(i).getValue();
setDescription(name); //The method setDescription(name) is undefined for the type HibernateIndexSearch
}
Could someone help me, because I need the look when my mouse is over the name of the element in the facet to show a field with specified text(name of the element in the facet)???

Aspose.Words delete line(row) containing a Bookmark

I have a very basic helper method that sets Bookmark's text.
public static Bookmark SetBookmark(this Document doc, string bookmarkName, string value)
{
var bm = doc.Range.Bookmarks[bookmarkName];
if(bm == null)
throw new NullReferenceException(string.Format("Bookmark {0} Not Found!", bookmarkName));
bm.Text = value ?? string.Empty;
return bm;
}
What I need is to remove a bookmark and delete line of text that contains it when a certain condition is met, e.g. when value == null. Any suggestions?
Sample document looks like:
Hello
[Bookmark]
Goodbye
Resulted document after removal:
Hello
Goodbye
Please set the value of Bookmark.Text property to empty string to remove its content and use Bookmark.Remove method to remove the bookmark from the document. Bookmark.Remove method does not remove text inside the bookmark.
I work with Aspose as Developer evangelist.
Please set the value of Bookmark.Text property to empty string to remove its content as shown in following code example. I already shared this in my previous answer.
Document doc = new Document(MyDir + "Bookmark.doc");
// Use the indexer of the Bookmarks collection to obtain the desired bookmark.
Bookmark bookmark = doc.Range.Bookmarks["MyBookmark"];
// Remove the contents of bookmark.
bookmark.Text = "";
doc.Save(MyDir + #"Out.docx");
I work with Aspose as Developer evangelist.

How to index sub-content in Sitecore with Lucene?

I'm using Sitecore 7.2 with MVC and a component approach to page building. This means that pages are largely empty and the content comes from the various renderings placed on the page. However, I would like the search results to return the main pages, not the individual content pieces.
Here is the basic code I have so far:
public IEnumerable<Item> GetItemsByKeywords(string[] keywords)
{
var index = ContentSearchManager.GetIndex("sitecore_master_index");
var allowedTemplates = new List<ID>();
IEnumerable<Item> items;
// Only Page templates should be returned
allowedTemplates.Add(new Sitecore.Data.ID("{842FAE42-802A-41F5-96DA-82FD038A9EB0}"));
using (var context = index.CreateSearchContext(SearchSecurityOptions.EnableSecurityCheck))
{
var keywordsPredicate = PredicateBuilder.True<SearchResultItem>();
var templatePredicate = PredicateBuilder.True<SearchResultItem>();
SearchResults<SearchResultItem> results;
// Only return results from allowed templates
templatePredicate = allowedTemplates.Aggregate(templatePredicate, (current, t) => current.Or(p => p.TemplateId == t));
// Add keywords to predicate
foreach (string keyword in keywords)
{
keywordsPredicate = keywordsPredicate.And(p => p.Content.Contains(keyword));
}
results = context.GetQueryable<SearchResultItem>().Where(keywordsPredicate).Filter(templatePredicate).GetResults();
items = results.Hits.Select(hit => hit.Document.GetItem());
}
return items;
}
You could create a computed field in the index which looks at the renderings on the page and resolves each rendering's data source item. Once you have each of those items you can index their fields and concatenate all of this data together.
One option is to do this with the native "content" computed field which is natively what full text search uses.
An alternative solution is to make an HttpRequest back to your published site and essentially scrape the HTML. This ensures that all renderings are included in the index.
You probably will not want to index common parts, like the Menu and Footer, so make use of HTMLAgilityPack or FizzlerEx to only return the contents of a particular parent container. You could get more clever to remove inner containers is you needed to. Just remember to strip out the html tags as well :)
using HtmlAgilityPack;
using Fizzler.Systems.HtmlAgilityPack;
//get the page
var web = new HtmlWeb();
var document = web.Load("http://localsite/url-to-page");
var page = document.DocumentNode;
var content = page.QuerySelector("div.main-content");

Resources