I'm trying to wrap my head around this. My language is Java using PlayFramework but I think any answer using php, or ruby on rails would get me in the right direction. Basically the user can add or take away number of pallets in this form. There needs to be some javavscript calculations per tab also. Everything is fired using a input change jquery event so there is no submit buttons. My first mockup used UUID's but that seemed to get me nowhere.
What happens is each tab is reponsible for doing calculations like perimeter. My first question is how to call javascript for the specific tab. I first did it with UUID's and separate scripts for each tab. This didn't seem correct.
My second problem is submitting this data. Obviously the name parameters need to be different. So I'm scratching my head on this. Every pallet would be tagged with an id so I'm not worried about the backend as much as I'm trying to figure out how structure the front end and the controllers.
Any help would be great. Thanks.
On the javascript part, assuming all the tabs have the same structure, create a generic method that receives and id (id of the tab) as parameter, and then retrieves the proper fields form the calculation. Something like:
function doCalc(tabId){ //assumes jquery
var tab = $("#"+tabId);
var field1 = $("#"+tabId+"_field1");
var field2 = $("#"+tabId+"_field2");
//...etc to retrieve tabs
}
The method assumes that when you create a tab "tabId" and its elements, you generate the id of the elements with the formula "tabId_", which will facilitate finding them.
About the submission, using Play! you should check this section about Ajax requests. It could be as simple as doing the calculation (the method above) and at the end call a Play method via Ajax. This method would get all the parameters (id, values, etc) of a pallet (the pallet of the given tab) and save it.
For submission, I assume you are trying to figure out how to hold and pass the data in a bean. What about having a field as below:
LinkedHashMap<String, LinkedHashMap<String, Object>> field;
The inner maps would be the listing of the fields on a Pallet. The outter maps are the Pallets.
Related
Scenerio is that we are having a page in which the whole data will load in a single page, at a time limited data is there on the screen but as we scroll down the scroll bar other data will populated dynamically, the case is that we do not know the exact amount of data we are having.I want to search for an attribute in the whole data if I'll found the data I can simply break it from my code but if the searched attribute is not present then how I can know whether I have iterated threw all the search results?
I am having no clue how can i procced ?
Consider creating a sentinel value/node to represent the end of the real data. The code that is handling the dynamic loads simply returns real data over and over until it runs out, at which point it returns a special value representing the sentinel. The client knows to never display the sentinel, and also knows that once it comes in, you are done and can stop fetching any new data. Your search can go through all the received data, and if it encounters the sentinel, it is done, if not, you know there might be more dynamic data to fetch.
I am using Vaadin 8 and I want to make some sort of confusion matrix. I was wondering if I can fill the values of the table/grid manually according to the cell position, instead of data provider.
referenceTable.addColumn(reference -> String.valueOf(reference.getId())).setId(REFERENCE_ID).setCaption(REFERENCE_ID).setMinimumWidth(100).setMaximumWidth(200);
referenceTable.addColumn(reference -> String.valueOf(reference.getTitle())).setId(TITLE_COLUMN).setCaption(TITLE_COLUMN).setMinimumWidth(100).setMaximumWidth(500);
I don't have any specific model which I can use.
Something like this, I want
Typically Grid in Vaadin is typed with POJO type bean and the API is optimized for that use case. However you can potentially use Grid with any valid type parameter. You can e.g. use List or HashMap<String,String> just to name few.
In GitHub there is Vaadin 8 example of Grid using ArrayList, which makes possible to use index to access the data for the column. The full code is too extensive to be featured here. The example contains also demonstrator for style generator.
I am new in servlets, I would like to display results in the very same page that I am on when I click a search button, then the results should be on the very same page, how can I achieve that without going to another JSP or if I am supposed to do it behind the scene moving to another without the user noticing that its another page, how do I make it seem as if its the same page with results on it. Any shed of light is highly appreciated.
You have to use javascript to receive the search results from the server. This technique is called ajax. Javascript libraries like jquery (or many others) can help you a lot with this.
Your form submits the search term to the current page, i.e. you can leave the form action attribute empty.
In your servlet check whether a search term has been submitted. If this is the case, execute your search function and write the result to the response.
You don't mention where you data is coming from, but that is fairly unimportant in this question. The data could come from a local variable, from DOM storage or have been served to you using AJAX. But here is an example of setting text data in a textarea element (there are nearly unlimited ways to format what you want, this is one example only). Dynamically changing your current page in this manner means that you do not need to navigate to another.
It works by getting a reference to the element by it's name ("data" in this case) using document.getElementById
We then set the element's content value to your data, and it is displayed in the textarea.
HTML
<input type="text"></input>
<div>
<textarea id="data"></textarea>
</div>
Javascript
var data = "Here is your data that was returned from your source";
document.getElementById("data").value = data;
On jsfiddle
I'm trying to submit a form with a few textareas like this:
<textarea name="criticism[]" rows="3" cols="5"></textarea>
The textarea needs to have an array as the name because there can be an unlimited number of them on the page, added by the user with js.
The values are passed to the controller correctly.
In the controller I do params.flash() which seems to add the values to the seession, since if I do ${flash} in the template they are printed to the screen. However, I can't access them in any way. ${flash.criticism} returns null, and ${flash.criticism[x]} will return an out of bounds error.
Am I missing anything syntax wise?
Cheers :)
The flash scope is only available to the current request and the next one. To put something in the session use session.
However flash and session are not intended to store values. They are cookie limited to 4kb. To store something use the db and/or the cache
If you want to re-render your values in the next page, just pass the string array as a 'criticism' parameter to the next render method and use it in your template with ${criticism[x]}
I have a array of data which was generated due to some Actions in my previous actions
On submitting that page, Control will be redirecting to the second page,
IN the second page, I need to populate the array data into the Tables
( I want to use Javascript to populate this, No other means)
Problems which i am facing now
1) I cant read the Java array in the Java script ? (I am not sure how to pass the Java array to Javascript function)
2) Thought of implementing the Java script objects similar to the java objects, but there will be lot of over head
Can any one help me to over come this situation
I am using the BTT framework which is similar to Struts, for Javascript I am not using any frameworks
Thanks in advance
JSON would be a format to make the java-array accessible in javascript.
https://github.com/douglascrockford/JSON-java/blob/master/JSONStringer.java
too broad to answer, since specifics are missing. here are some generic steps.
Collect your stuff in JavaScript array
Have a hidden form field
while posting to server, set the value of hidden field to your array (in string format)
Read the hidden field content in server (posted form data)
Parse them (JSON is appropriate here)
Use them while preparing next page content as JS Array