Polymer dom repeat index to a variable - java

So I have this dom repeat where all lessons get displayed of the class of an user which I get from a json.
<template is="dom-repeat" items="{{lessen}}">
<div><paper-button id="{{index}}" on-click="toggleDialog">{{index}} - {{item.lessen}}</paper-button></div>
</template>
Is there a way I can get the value of '{{index}}' to send to my backend via iron-ajax? I got this function:
sendAfmelding: function() {
console.log("Afmelden van les met user="+this.username);
if (this.rol == "student") {
console.log("indexnummer = "+this.$.index);
this.$.ajax2.contentType="application/json";
this.$.ajax2.body={
"username":this.username,
"lesIndex":this.$.index // <-- needs to change
};
this.$.ajax2.generateRequest();
}
}
I got everything correctly set up. Username get's send and everything, the only thing I still need is that index value. For example, if I put
"lesIndex":"1"
in my function my code will do exacly what I want but ofcourse I want the user to select the lesson himself.
I hope my question is a bit clear, thanks in advance!

I think
id$="{{index}}"
is what you want to get attribute binding instead of property binding.
See for example the 2nd-last paragraph before https://www.polymer-project.org/1.0/docs/devguide/templates.html#dom-bind

The index is exposed on the item's click event, you can access it inside toggleDialog:
toggleDialog: function (event) {
var index = event.model.index;
sendAfmelding(index); // I assumed you were calling this somewhere in here
}
And then ofcourse add the parameter to the sendAfmelding function:
sendAfmelding: function (index) {
console.log("Afmelden van les met user=" + this.username);
if (this.rol == "student") {
console.log("indexnummer = " + index);
this.$.ajax2.contentType = "application/json";
this.$.ajax2.body = {
"username": this.username,
"lesIndex": index
};
this.$.ajax2.generateRequest();
}
}

Related

Get index of LinkToAction on table - WD Java

I have a data table and I want to show detail when clicking each row on it. But the index always returns 0.
int index= wdContext.getCurrentElement().index();
wdComponentAPI.getMessageManager().reportSuccess("test "+ index);
Please help me review and give your thoughts.
You have several options here. First option:
wdContext.node<YourNode>.getLeadSelection().index();
Pay attention to get lead selection of your node but not of the root context. Also context mapping should be properly defined for this to work.
Second option is to use wdDoModifyView event:
wdDoModifyView(...)
{
if (firstTime)
{
IWDLinkToAction link = (IWDLinkToAction) view.getElement("LinkID");
link.mappingOfOnAction().addSourceMapping("nodeElement", "rowElement");
}
}
Here we map built-in parameter nodeElement to our target rowElemen parameter which would be used in LinkToAction handler.
void onActionLinkClicked(..., I<DataSourceNode>Element rowElement)
{
/* do whatever with row element */
}

Oracle ADF When Selecting Multiple Rows, RowSetIterator Does Not Populate on First Method Invocation

Uncertain how best to word the title, but here's the gist.
The goal is to retrieve all selected rows of a table and manipulate them. The problem I'm bumping into is that the RowSetIterator doesn't get populated the first time the method within my backing bean is invoked. It does get populated when invoked a second time.
How do I go about getting it to work properly on the first invocation?
Doubtless I'm not being perfectly clear, please let me know if you require any additional information. Here's a snippet of the bean method:
public String deleteSelectedQueries()
{
JSFUtils.addInformationMessage("Delete");
RowKeySet selectedQueries =
getSavedQueriesByUserTable().getSelectedRowKeys();
Iterator selectedQueriesIter = selectedQueries.iterator();
DCBindingContainer bindings =
(DCBindingContainer) BindingContext.getCurrent().getCurrentBindingsEntry();
DCIteratorBinding savedQueriesByUserIter =
bindings.findIteratorBinding("SavedQueriesByUserROVOIterator");
RowSetIterator savedQueriesByUserRowSetIterator =
savedQueriesByUserIter.getRowSetIterator();
while (selectedQueriesIter.hasNext())
{
Key key = (Key) ((List) selectedQueriesIter.next()).get(0);
Row currentRow = savedQueriesByUserRowSetIterator.getRow(key);
System.out.println(currentRow.getAttribute("QueryName"));
}
return null;
}
}
Any ideas?
Thanks!
This code looks good to me.
The problem may come from <af:table> tag, make sure you have these tags removed:
selectedRowKeys="#{bindings.SavedQueriesByUserROVO.collectionModel.selectedRow}"
selectionListener="#{bindings.SavedQueriesByUserROVO.collectionModel.makeCurrent}"

Jsoup selectors returning all values instead of searched values

I'm learning how to use jsoup and I've created a method called search which uses jsoup's selectors containsand containsOwn to search for a given item and return it's price. (For now the item name is hardcoded for testing purposes but the method will later take in a parameter to accept any item name).
The problem I'm having is that the selector isn't working and all the prices on the page are being returned instead of the one item being searched for, in this case "blinds". So in this example if you follow the link, only one item on that page says blinds and the price is listed as "$30 - $110 original $18 - $66 sale" but every item on that page gets returned instead.
I am aware that with jsoup I can explicitly call the name of the div and just extract the information from it that way. But I wanted to turn this into a bigger project and also extract prices from the same item from other chains such as Walmart, Sears, Macy's etc. Not just that particular website I used in my code. So I can't explicitly call the div name if I wanted to do that because that would only solve the problem for one site, but not the others and I wanted to take on an approach that encompasses the majority of those sites all at once.
How do I extract the price associated with its rightful item? Is there any way of doing it so that the item and price extracting will apply to most websites?
I would appreciate any help.
private static String search(){
Document doc;
String priceText = null;
try{
doc = Jsoup.connect("http://www.jcpenney.com/for-the-home/sale/cat.jump?id=cat100590341&deptId=dept20000011").get();
Elements divs = doc.select("div");
HashMap items = new HashMap();
for(Element element : doc.select("div:contains(blinds)")){
//For those items that say "buy 1 get 1 free"
String buyOneText = divs.select(":containsOwn(buy 1)").text();
Element all = divs.select(":containsOwn($)").first();
priceText = element.select(":containsOwn($)").text();
items.put(element, priceText);
}
System.out.println(priceText);
}catch(Exception e){
e.printStackTrace();
}
return priceText;
}
If you have tried at least to debug your app, then for sure, you will spot where is your mistake.
Put breakpoint for example on this line:
String buyOneText = divs.select(":containsOwn(buy 1)").text();
and then you will see, that really this element in loop contains blinds text. (and as all, that were selected)
I don't know why to make super universal tools, that will be working everywhere - IMO is not possible, and for every page you have to make your own crawler. In this case probably your code should be looking like this (I have to added timeout + this code is not working fully on my side, as I have default currency PLN):
private static String search() {
Document doc;
String priceText = null;
try {
doc = Jsoup.connect("http://www.jcpenney.com/for-the-home/sale/cat.jump?id=cat100590341&deptId=dept20000011").timeout(10000).get();
Elements divs = doc.select("div[class=price_description]");
HashMap items = new HashMap();
for (Element element : divs.select("div:contains(blinds)")) {
//For those items that say "buy 1 get 1 free"
String buyOneText = divs.select(":containsOwn(buy 1)").text();
Element all = divs.select(":containsOwn($)").first();
priceText = element.select(":containsOwn($)").text();
items.put(element, priceText);
}
System.out.println(priceText);
} catch (Exception e) {
e.printStackTrace();
}
return priceText;
}

Can't make getElementById() method working correctly in a java serializer program

I'm writing an XML serializer with JAXP. I'm receiving pseudo random data from a JAR and I'm building the DOM tree. I have to check if I already inserted the same Element into the tree; in order to perform this control I'm trying to use the method:
Element e = myDocument.getElementById(ao.getId());
if (e == null) {
// element is not a duplicate
access.appendChild(authorizationObject);
}else{
// element already in the tree
}
So, in every Element I create before adding them to the tree I set:
ao = a.getAuthorizationObject();
authorizationObject = myDocument.createElement("authorizationobject");
authorizationObject.setAttribute("id", ao.getId());
authorizationObject.setIdAttribute("id", true);
It can happen that in the object ao sometimes I get the same element twice (or more).
The problem is that the program always enter inside the if instruction.
You can find all the program's code here and the DTD here for your reference.
What am I doing wrong?
Thanks in advance for all your reply.
You have forgotten to append the authorizationObject to the access Element. Your code should be as follows
authorizationObject = myDocument.createElement("authorizationobject");
authorizationObject.setAttribute("id", ao.getId());
authorizationObject.setIdAttribute("id", true);
System.out.println("AO.ID = " + ao.getId());
access.appendChild(authorizationObject);
// then only this Element will be appended to the document
if (myDocument.getElementById(ao.getId()) == null ) {
I see that you have finally appended the authorization object to the document. but, it should be done prior to document.getElementById() method call
Hope this helps!

Nightmare Class - floats/strings

This is my class reponsible for new item entries, and from the start it has been a complete nightmare, I can't seem to resolve the issues I am facing which are:
setStock(float) in Item cannot be applied to ()
Item entry:
private void writeItemRecord()
{
// Check to see if we can connect to database table
if ( DataBaseHandler.makeConnectionToitemDB() == -1)
{
JOptionPane.showMessageDialog (frame, "Unable to connect to database table (Item)");
}
else // Ok, so first read data from the text fields
{
// Read data from form and store data
String Itemname = ItemnameTxtField.getText();
String Itemcode = ItemcodeTxtField.getText();
String Description = DescriptionTxtField.getText();
String Unitprice = UnitpriceTxtField.getText();
String Style = StyleTxtField.getText();
String Finish = FinishTxtField.getText();
String Stock = StockTxtField.getText();
// Convert priceStr to a float
Float fvar = Float.valueOf(Unitprice);
float price = fvar.floatValue();
Float svar = Float.valueOf(Stock);
float stock = svar.floatValue();
// Create a Item oject
Item Item = new Item();
// Set the attributes for the Item object
Item.setItemname (Itemname);
Item.setItemcode (Itemcode);
Item.setDescription (Description);
Item.setUnitprice (price);
Item.setStock(stock);
Item.setStyle(Style);
Item.setFinish(Finish);
// Write Item record. Method writeToItemTable() returns
// 0 of OK writing record, -1 if there is a problem. I store
// the returned value in a variable called error.
int error = DataBaseHandler.writeToItemTable(Item.getItemname(),
Item.getItemcode(),
Item.getDescription(),
Item.getUnitprice(),
Item.setStock(),
Item.setStyle(Style),
Item.setFinish(Finish),
Item.setSuppliercode(Suppliercode),
Item.setSuppliername(Suppliername),
Item.setAddress(Address)
);
// Check if there is a problem writing the record, in
// which case error will contain -1
if (error == -1)
{
JOptionPane.showMessageDialog (frame, "Problem writing record to Item Table");
}
// Clear the form - actual method is coded below
clearForm();
// Close database connection. Report an error message
// if there is a problem.
if ( DataBaseHandler.closeConnection() == -1 )
{
JOptionPane.showMessageDialog (frame, "Problem closing data base conection");
}
}
} // End
Any help is much appreciated!
And item extracts:
public void setStock(float StockIn)
{
Stock = StockIn;
}
public float getStock()
{
return Stock;
}
For starters, adhere to Java naming conventions. Nothing except class/interface names is allowed to use CamelCase. Use lowerCamelCase. As for your "problem", you wrote
Item.setStock(),
so obviously it's giving you the error. It is also giving you the exact line number of the error, something that would obviously have helped us to diagnose your problem.
Solution: use Item.getStock() (i suppose, it's hard to tell). Calling Item.setStock at that position (as an argument to a method call) is meaningless anyway, given that setStock is a void method.
Java compiler errors come with a line number - pay attention to it. This is your problem:
Item.setStock()
setStock() requires a parameter, you are trying to call it without one. Perhaps you meant getStock()? And I suspect that all the calls to set methods in the parameter list to writeToItemTable are also wrong, as those set methods will have void as return value, so you can't use them that way.
The setStock method looks like this:
public void setStock(float StockIn)
To call it, you need to pass a float as an argument. Somewhere in your code, you call the method, like this:
Item.setStock(),
The method needs to be called with the float argument, but instead it's called with none, hence you see a compilation error.
In this code:
int error = DataBaseHandler.writeToItemTable(Item.getItemname(),
Item.getItemcode(),
Item.getDescription(),
Item.getUnitprice(),
// Right here --> Item.setStock(),
Item.setStyle(Style),
Item.setFinish(Finish),
Item.setSuppliercode(Suppliercode),
Item.setSuppliername(Suppliername),
Item.setAddress(Address)
);
Notice that you're calling Item.setStock(), Item.setStyle(Style), etc. instead of Item.getStock(), Item.getStyle(), etc. This is probably the source of your problem - you're trying to call the setStock() method with no arguments, hence the error.
Hope this helps!
This line
// Create a Item oject
Item Item = new Item();
Is problematic. Not only is it bad style in Java to use uppercase names for variables, this particular instance results in a compile error. Also, you're calling setStock without a parameter. You need to fix that as well.
Here is your error:
int error = DataBaseHandler.writeToItemTable(Item.getItemname(),
Item.getItemcode(),
Item.getDescription(),
Item.getUnitprice(),
Item.setStock(), // <<< here! should be getStock()
Item.setStyle(Style),
Item.setFinish(Finish),
Item.setSuppliercode(Suppliercode),
Item.setSuppliername(Suppliername),
Item.setAddress(Address));
But again... consider naming/coding conventions.

Categories