Basically what I'm trying to do is, I create a type object with a name and attribute names (I tried to collect those attribute names in a tableview). Then I create items by selecting those types I created before. The Item object i create has its name,type and attribute names. What I want is, when I'm creating an item, I select a type. When I select that type, I want the tableview in item creating page to show selected types attribute names.item creating page is something like that
I tried something like this. Those are my initialize method and creatType methods.
any suggestions?
ObservableList<Types> list2 = FXCollections.observableArrayList();
ObservableList<Items> list3 = FXCollections.observableArrayList();
public void initialize(URL url, ResourceBundle resourceBundle) {
typeAttributesNames.setCellValueFactory(new PropertyValueFactory<Types, String>("typeAttributesNames"));
this.itemAttrValue.setCellValueFactory(new PropertyValueFactory<Items,String>("attributeValues"));
typeAttrNameColumn.setCellValueFactory(new PropertyValueFactory<Types,String>("typeAttributesNames2"));
attrNameTableView.setItems(list2);
itemsAttrTableView.setItems(list3);
}
public void createType(){
ObservableList<Types> typesObservableList=list2;
Types types= new Types(typesTextField.getText(),typesObservableList);
types.getTypesTitledPane().setText(typesTextField.getText());
typeTitledPaneVbox.getChildren().addAll(types.getTypesTitledPane());
typeNameComboBox.getItems().addAll(typesTextField.getText());
Types.typesArrayList.add(types);
typesTextField.clear();
typeNameComboBox.setOnAction(e ->
typeAttrTableView.setItems(typesObservableList));
attrNameTableView.getItems().clear();
}
Related
I want to show a form that has a pre-filled list of objects and each of the object attributes as a field, retrieved from my database using Thymeleaf templates (that the user will then be able to edit). I understand I would use th:each to accomplish looping over each object in the returned list and creating the pre-filled form fields.
However, if there are no items retrieved from the database, I want to still show a form corresponding to that objects attributes, only with the pre-filled values empty. How would I implement this? I cannot find details in the documentation.
I am assuming you are doing something like this in your controller:
#GetMapping
public String showListOfObjectsForm(Model model) {
List<MyObject> listOfObjects = service.get...
model.addAttribute( "myList", listOfObjects );
return "form"
}
You could check the size of listOfObjects and add a "dummy" object in the list:
#GetMapping
public String showListOfObjectsForm(Model model) {
List<MyObject> listOfObjects = service.get...
if( listOfObjects.isEmpty() ) {
listOfObjects.add( new MyObject() );
}
model.addAttribute( "myList", listOfObjects );
return "form"
}
I'm designing a project about cataloging something. In this project user must be able to create his own table as he wish. Therefore I do not have any static class and instance of it.
I'm creating a diaglog pane and I can create textfields for user inputs according to column names of database table dynamically but how can i add those user's inputs into the tableView ?
As I can add any String input into the ListView can I add user String inputs into tableView columns?
ListView<String> listView = new ListView();
public ObservableList<String> listCatalogNames = FXCollections.observableArrayList();
listCatalogNames.add("Books");
More details with an example;
There is listview that contains all catalog names and according to lisview selection tableview will be created dynamically center of borderpane.
User have books(name, author, page) and movies(name, year, director, genree) catalogs.
Lets say user selected movies and tableView appeared with 4 columns and clicked add button. Diaglog pane created with 4 textfield. I built everything until that point but I cannot add user's input into the tableView because i dont have any static class for Movies or Books etc.
Is there any way to create dynamic class ?
Please give me an idea and help me about that situation.
here is the github link of our project
Just use String[] storing the Strings for every column of a row (or a similar data structure) as item type for the TableView. It should be simple enough to create a String[] from the inputs and add it to this TableView:
static TableView<String[]> createTable(String... columnNames) {
TableView<String[]> table = new TableView<>();
for (int i = 0; i < columnNames.length; i++) {
final int index = i;
TableColumn<String[], String> column = new TableColumn<>(columnNames[i]);
column.setCellValueFactory(cd -> new SimpleStringProperty(cd.getValue()[index]));
table.getColumns().add(column);
}
return table;
}
Adding a String[] userInputs to a TableView<String[]> table would be done like this:
table.getItems().add(userInputs);
A similar issue (creating a TableView based on the metadata of a ResultSet) can be found here: How to fill up a TableView with database data
Easiest solution that comes to my mind is to make use of polymorphism. You can create a super class of both Book and Movie, let's call it Item. Then you can declare your table to contain Item and cast to one of the concrete classes when you need to.
I have a selectbox in libgdx , I am trying to add a list of values to it . Is the a way i can add the list such as selectbox.addAll(list1) ?
Due to SelectBox reference the method you are looking for is
public void setItems(T... newItems)
You can use it for example like this:
SelectBox.SelectBoxStyle boxStyle = new SelectBox.SelectBoxStyle();
//creating boxStyle...
String[] values = new String[]{"value1", "value2", "value3", "value4"};
SelectBox<String> selectBox = new SelectBox<String>(boxStyle);
selectBox.setItems(values);
Of course instead of creating the style manually you can use Skin with predefined .json file for this purpose
I am building a Spring Rest application for a food store in which the admin can create new Menu everyday by adding, editing or removing menu items as per the occasion. When the admin tries to update the menu, at the server side I am fetching first the menu item list that is associated with the current menu passed and then converting it to hash map so as to find the menu items currently passed with menu. Following is the code snippet to convert the list to map:
private Map<Long, MenuItem> convertIdToMenu(List<MenuItemMappingWrapper> menuItemMappingWrapper){
List<Long> menuItemIdList = new ArrayList<Long>();
for (MenuItemMappingWrapper menuItemWrapper : menuItemMappingWrapper) {
menuItemIdList.add(menuItemWrapper.getMenuItemId());
}
List<MenuItem> menuItemList = menuDao.getMenuItemById(menuItemIdList);
Map<Long, MenuItem> menuItemMap = new HashMap<Long, MenuItem>();
for (MenuItem menuItem : menuItemList) {
menuItemMap.put(menuItem.getId(), menuItem);
}
return menuItemMap;
}
So I can find the menu item by passing its "id" as key to map rather than iterating over the large list of items. Is there a more better to improve the performance on the server side other than converting list to map ?
I am using Struts 2 framework for my application and my code is as follows,
/*Setting dynamic dropdown of service Type*/
ShowSearch drop=new ShowSearch();
service=drop.serviceType();
setService(service);
I am getting list of values from DB (Lets say values are "Apple","Cat","Jack","Zag") and it has shown in struts2 dropdown as mentioned in JSP .
<s:select id="serviceType" name="serviceType"
label="What is the service offering" required="true"
value="%{serviceType}" list="service" />
When I am trying to do below action, lets say localhost:8080/as/prd?id=first
Actual Value of the "serviceType" dropdown for 'first' is "Jack". But now, dropdown is showing in the order which is taken from DB (i.e based on list "Service").
My requirement is to show "Jack" then following "Apple","Cat","Zag",.... What should I do to show like that?
set that string variable in your action class. Then that string variable will be displayed first in the dropdown.
Show like that is called sorting in the alphabetical order. To do that you could modify the list before the rendering phase. Assume your list collection element is a simple string, then
Collections.sort(myList);
will do what you want.
Another approach is to use s:sort tag and write a comparator which sort the list, then wrap it around the s:select tag
<s:sort comparator="myComparator" source="myList">
<s:select id="serviceType" name="serviceType"
label="What is the service offering" required="true"
value="%{serviceType}" list="myList" />
</s:sort>
Write a simple comparator
public Comparator getMyComparator() {
return new Comparator() {
public int compare(Object o1, Object o2) {
String s1 = (String) o1;
String s2 = (String) o2;
return s1.compareTo(s2);
}
};
}
More detailed explanation how to sort collections and how to use Comparable and Comparator you could find here.