I am trying to post checkbox data with Jsoup and am having a little trouble. I thought that when multiple checkboxes are selected, they are sent as an array to the server but maybe that is not the case?
This is what I thought was correct:
HashMap<String, String> postData = new HashMap<String, String>();
postData.put("checkbox", "[box1,box2,box3]");
Jsoup.connect("somesite").data(postData).post();
This does not seem to work properly. However, if I send only a single checkbox then I get my expected results leading me to believe my understanding of how checkbox form data sends is incorrect.
This works:
postData.put("checkbox", "box2");
Maybe HashMap is the wrong type to use. According to the Jsoup documentation I could just call .data(key, value) multiple times but I was hoping for something a little cleaner than that.
If you have multiple checkboxes, then presumably each checkbox has its own name attribute. You should then call .data(name, value) for each such name.
AFAIK there's no way to "collapse" these calls to data into a single call.
Maybe You can try something like the following ?
HashMap<String,String> paramHM=new HashMap<String,String>();
ArrayList<String> checkboxVal=new ArrayList<Strnig>();
/ .. put request.getParametersValues() in this arraylist
org.jsoup.Connection jsoupConn=Jsoup.connect(web_api).data(paramHM);
// Multiple Call that
for(String item:checkboxVal){
jsoupConn=jsoupConn.data("checkbox",item);
}
Related
My issue is I have a simple List of Strings say
List<String> names = List.of("Frank","Joe","Eva");
All I want is display it on the UI. With some simple code like
ListComponent lc = new ListComponent.setItems(names);
I have tried it with Table which seems to work but code behind it is a bit boilerplate for this simple task(7-8 line of code).
I have tried also the Grid component and it works well when I want to bind a POJO to it , but with String.class type its a nightmare.
Grid<String> listGrid= new Grid<>(String.class) ;
listGrid.setItems(names);
it doesnt work because I have to provide getters for the column, which String.class doesnt have for the value. So I did this:
Grid<String> listGrid= new Grid<>(String.class) ;
listGrid.setItems(names);
listGrid.addColumn(String::toString).setCaption("name");
It works! However unspecified columns also appear in the grid, so now I have 3 columns Byte,Empty,name. And I dont know why. Where are these comes from?
What are the requirements for displaying them? Just to get them on the screen? Is Label enough?
for(String name: names) {
mylayout.addComponent(new Label(name))
}
If you need selection, then maybe ListSelect or ComboBox are the go-to’s.
If you want to avoid the additional columns, one way is to do as was pointed out in a comment, i.e. do removeAllColumns() before you go on creating your own columns.
Another approach would be to do new Grid<>() instead of new Grid<>(String.class). The main difference is that the second constructor uses reflection on the provided class and automatically configures columns for anything that looks like regular Java bean properties.
I would highly prefer to use grid.removeColumnByKey rather than removeAllColumns()
You can also use grid.setColumns to specify order of columns.
I will add link to vaadin documentantion for grid with java examples which is realy helpfull. enter link description here
I did something similar to adding the Strings in TextAreas. Because I needed some formatting, I added the text using StringBuilder.
List<String> details = getDetails();
StringBuilder builder = new StringBuilder();
for (String detail : details) {
TextArea ta = new TextArea();
ta.setSizeFull();
ta.setMaxHeight("100px");
ta.setValue(builder.append(detail).toString());
((Span) content).add(ta);
((Span) content).add(new Hr());
}
The result is like this:
Try out this
final Grid<String> grid = new Grid<>();
grid.setItems(new ArrayList<String>());
grid.addColumn(item -> item).setHeader("Value");
I am trying to create a pass code and username login for an app that I am designing. At the moment I am required to have four users, and four separate pass codes that are relevant to each user.
this code needs to be run in an android emulator.
Would anyone have a simple array structure that would be easy to follow?
As Hristo said, you should use a HashMap
Map<String, String> myMap = new HashMap<String, String>();
myMap.put("DmcG", "somePassword");
...
String password = myMap.get("DmcG");
Why don't you try using Hashmap? Its structure is < Key, Value >. You can implement it by using the key for username and its value for password. Hope that helps!
I am working on Selenium with java client. I am getting the Html as the string using the method driver.getPageSource() .
Can you please suggest to me, do we have any open source which is used to convert the Html to Java Object?
Based on that above question, I am expecting functionality like below:
getTextBoxIds() - It will list of the all the text box Ids as the HashMap() ids as the key, and value is the TextBox value.
getSelectBoxIds()
getDivIds()
Note: As of now I am checking the expected data using the contain(), indexOf(), lastIndexOf() methods.
Regards,
Vasanth D
Don't do that! Selenium does it for you (and much more).
Once you're on the page you wanted to get to, you can get all the data you need:
/** Maps IDs of all textboxes to their value attribute. */
public Map<String,String> getTextBoxIds() {
Map<String,String> textboxIds = new HashMap<>();
// find all textboxes
List<WebElement> textboxes = driver.findElements(By.cssSelector("input[type='text']"));
// map id of each textbox to its value
for (WebElement textbox : textboxes) {
textboxIds.put(textbox.getAttribute("id"), textbox.getAttribute("value"));
}
return textboxIds;
}
and so on and so forth. Look at Selenium's documentation to find out more.
Also, JavaDocs.
I am newbie on GWT. I am writing the code of a page which asks a JSON object that contains two collections and I use one of these collection to fill a Flextable.
This is my JSON Object:
public class Users extends JavaScriptObject {
protected Users() {
}
public final native JsArray<Link> getLinks() /*-{
return this.links;
}-*/;
public final native JsArray<User> getCollection() /*-{
return this.collection;
}-*/;
}
In particular I am using the second collection (called collection) to fill a Flextable. But my problem is that when I delete one row from the table, even if I send a request with an http delete method to the server (and the server delete that item successfully), when I try to refresh the table GWT does not generate the GET request to the server, (even if it is written in the code) and Users Object is the same as before with the deleted item also.
I have tried to delete this item from collection using this method:
public static native void remove(JsArray<?> arr, int index, int count) /*-{
arr.splice(index, count);
}-*/;
....
remove(users.getCollection(), index, users.getCollection().length());
And I also tried this other technique:
users.getCollection().set(index, null);
But in both cases, I do not get the expected result, when I refresh the table I find the deleted items again.
I think that I am not managing the DOM properly, Do you have any suggestions? Any Idea? I am sure it is simple problem to solve for an expert.
EDIT:
The user can refresh the data in the table clicking a button, the handler of this event will perform a request to a server, but this request is sent on the first click only.
Basically there are two alternatives, the first is to set the header Cache Control to no-cache in the server side, while if you cannot modify the code in the server side, for example in the case of legacy applications, you can attach a random number in your request in a parameter. A request will have a uri with an additional parameter which is a random generated number, http:\\mydomain.com\something?random=12345. Two different requests will have different numbers and at the second request the response of the first request, which has been cached it will be ignored. It is not a smart practice, but it works.
For getting data like this better use HTTP POST request, because GET requests are being cached (by GWT, proxy servers...).
Also make sure your server code for deleting items is doing right job, and manually check server response in firebug or in chrome console to see if your response contains deleted records.
Please post code you use to fill flex table, are you clearing it before populating with data again ?
EDIT:
see link.
If you can use celltable http://gwt.googleusercontent.com/samples/Showcase/Showcase.html#!CwCellTable (because it holds List of elements it display underneath) or use some collection (ArrayList) to hold data that your FlexTable is displaying. Then you can easily modify that collection and redraw your flex table from it.
So, basically i'm working with a ListView, looking like this for the moment :
(source: xooimage.com)
(As a new user I can't post images..)
I add each element of the list like that :
map = new HashMap<String, String>();
map.put("ing_name", "Mozzarella");
listItem.add(map);
map = new HashMap<String, String>();
map.put("ing_name", "Emmental");
listItem.add(map);
I would like to put a different picture for every element, to end up with something like that (I photoshoped it) :
(source: xooimage.com)
I tried some things, but couldn't find out one working.
Does someone know how to do it ?
Thanks. :-)
Try using the Simple adapter class. The below link might be helpful.
Simple adapter example
I hope it helps..