Webix load combo get all values into array - java

I'm loading some data into a hidden Webix combo box via URL with two parameters. After loading, I want to store all values from the combo box into an array. But this doesn't work. If it is possible to load data from URL to an array without loading it first into a combo, how does this work? I use Spring ResourceMapping annotation in the controller.

You can use a webix DataCollection which work as any webix data component but without any graphical representation :
var store = new webix.DataCollection({ url:"data.php" });
Another solution is to manually do ajax request :
webix.ajax().get('data.php', function(txt, data) { console.log(data.json()); });

Related

Spring boot not saving path variable to database

I currently have a form that allows users to upload data, however, I want to save the path variable to the database for that object.
The thymeleaf form action is as follows.
<form th:action="#{/homepage/{room_id}/saveLayout(room_id=${Room.room_id})}" th:object="${layout}" method="post">
This is the controller that the form corresponds to
#PostMapping("/homepage/{room_id}/saveLayout")
public String saveLayout(#ModelAttribute("layout") Layout layout, #PathVariable(value = "room_id")long room_id) {
layout.setroomid(room_id);
layout.Service.saveLayout(layout);
return "redirect:/homepage";
}
The idea is that when a user sends the form after clicking on say room 2, the URL should be
homepage/2/saveLayout
However, the issue is that the URL does not contain the ID of the room, instead it looks like this
homepage//saveLayout
Which in turn causes spring boot to return an error saying the URL contained malicious content '//'. Even after removing the path variables and hard coding an integer 2 into the setroomid method, the room id does not change in the database. I have another controller which directs the user to the form to input the data, this adds attributes layout and room to the model. There are no red underlines in either of the HTML documents within the thymeleaf code. My setroomID method is
public void setroomid(long room_id){
roomid = roomid;
}
I should also make it clear that the actual data uploading works, however the roomID for a layout remains unchanged. If anyone is able to recommend any changes to make this work, or suggest an alternate way of binding a roomID to a layout in the database then it would be appreciated, thanks.

How to bind Java object to Javascript control

I am using the Sencha framework and am creating controls using Javascript. I want to fetch some data from the database using Java, but am uncertain on how to bind that Java object to the Sencha-created controls. What can I try?
'Sencha created controls'?
Check Sencha API for the controls - checkbox, gridpanel etc..
You may need to use a store config in most cases.
Just use Sencha GXT: "Sencha GXT is the fastest, most powerful way to create rich web-based applications using Java."
Suppose you want to create a combobox in sencha, then do it as:
var javaData = = [
[1, 'item1']
,[2, 'item2']
];
var combo = new Ext.form.ComboBox({
store: new Ext.data.SimpleStore({
id:0
,fields:
[
'myId', //numeric value is the key
'myText' //the text value is the value
]
,data: javaData
})
,valueField:'myId'
,displayField:'myText'
,mode:'local'
});
replace javaData var value with your data from server.
Ensure that the data is in json format to run this example.
For more: http://www.sencha.com/learn/combobox-faq/
What your ExtJS store does is an Ajax call to a certain page on your java application. That page will return data formatted in JSON so that your ExtJS store can parse that data.
Basically it doesn't mather what your back end technology is. You just need to make sure your page returns json in the following format:
{
data: [], //Array of json data
success: true, //true when your call was handled succesfull
total: 10 //The total items of a certain object
}
So in your case your JSP page will display the result in the JSON format as explained above, your ExtJS store will be configured to call that certain JSP page.

how to change the value of textfield + jQuery + Struts2

I have two textfield A , B : i want to do something like when i enter something in textfield A,this value will be use it in some action and result will be displayed in textfield B without clicking the submit button using ajax.
how can i do it please ? note that i am a using struts2
Most of the information has already been provided by #alexanderb and i believe that Jquery is good way to go, now lets come to the second half of your question about using AJAX in your code. there are few ways you can send results from your action class.
Return JSON from your action class and use above code.
Use stream result type in your S2 code and place the data in the textfield.
Still i believe JSON with Jquery is good way to go which not only provides you the feasibility to easily extend functionality in future but also provide a clean way.Struts2 provides a plugin which can convert the data being send from your action class to JSON and all you will be left to parse the JSON data in your UI to fill the text-box.For details how to work with JSON in s2 refer to JSON plugin for detail
S2-json-plugin
With JSON plugin your flow will be
Call your Action class on specific event in text box.
Configure your action to return JSON data using S2-JSon plugin.
Action will return JSON to the Jquery code.
Parse the JSON data and fill the text box with the value
It should be easy. Suppose you have action that takes value as string and return some string back, availble on '/app/service' url.
You can create such code for that:
$(function() {
$('#text_1').on('keyup', function() {
var value = $(this).val();
$.post('/app/service', JSON.stringify(value), function (r) {
$('text_1').text(r);
});
});
});

Creating a free form BIRT report using Scripted Datasource

I am trying to create a free form BIRT report. The report is not consisted to rows which have the same columnNames in each row.
Instead, it is a free form report, which will be of the following form.
"Name: {FirstName} {LastName} Addess : {Address}
Phone# {Phone#}
....
....
"
I am using a scripted datasource, which essentially returns the Map containing the name value pairs of {FirstName, LastName, Address, Phone, and other fields}..
But I am not sure how to set the variables and how do I get the FirstName, LastName etc.
Should I try to use dynamic text.
I don't know of any way in which BIRT can handle non row related data.
Here's my open script of the dataset.
open:
util = new Packages.test.ReportsUtil();
reportsVO = util.getReportVO("ABC");
in fetch:
if(currentrow < totalrows) {
dataSetRow["FirstName"] = reportsVO.getPropValue("identity.FirstName");
dataSetRow["LastName"] = reportsVO.getPropValue("identity.LastName");
currentrow++;
} else {
return (false);
}
But I am not sure of how do I get access to the FirstName and LastName in the main layout page.
Thank you
The goal of a scripted data source is to allow you to leverage the logic inherent in your data model and benefit from any business rules that manipulate that data. In the end it still wants the data to be formed into a rather traditional row-based set.
You mention dynamic text and I think this would be a great use for the Java-based event handlers. You can use the logic in the Java object you had bound to the scripted data source to instead tie to an event in the life cycle of the report and get your non-relational data that way.
You can even call your Java object directly from a JavaScript event handler (much easier to plug into via the IDE) using the JS "Packages" construct.
There are many examples to help you get this done at the BIRT Exchange.
I did something similar (BIRT 3.7) but I used row["colName"] instead of dataSetRow["colName"] and that seems to work. I have my data in a list, and then each list item is a grid. I set the data binding in the list to the data set. The grid is able to see the value as row["colName"].

how to make a <html:multibox> checked by default

I'm new to Struts 1 so may be its already a resolved question.
The situation is: I have a list of <html:multibox> tag, which are rendered into html-checkbox element when the page loads. I want the checkboxes to be checked by default (without using javascript/jquery).
You would set the fields in your Form if you want them selected. For multiple checkboxes with all the same name but different values, your Form should have a String[] property that holds all the selected values. Just populate that with the values you want selected by default. This could be something as simple as:
public void reset(ActionMapping mapping, HttpServletRequest request) {
if(multiboxField == null) {
multiboxField = new String[2];
multiboxField[0] = "optionOne";
multiboxField[1] = "optionTwo";
}
}
The best way to do this is with a *formname*SetupAction.java class.
Set your struts-config.xml to redirect people who click on your page to this SetupAction. Import your form class, populate your String[] with whatever values you want default-checked, and action-forward them back to your page. This also allows you to dynamically populate them, based on DB data or session variables or whatever you want.

Categories