I have an asp.net app that does ModelMapping from a submitted form. Today, I serialize the form and everything works great. I'm planning on nesting the current data structure (that the form maps to) within a class but the problem is that the class's name can vary.
Today I use Jquery's Serialize command on the form but now I need to prepend the new class name (and a '.') to the various inputs in the form.
Is there a simple way to tell Serialize to prepend a variable name? Alternatively, does anyone know an easily prepend a class on a set of variables that are serialized?
Related
I'm trying to build a custom UI control in alfresco to display the associations of an object type that I have.
Basically I have two object types; Code, which is a key value pair, and CodeScheme which contains multiple child associations to codes, it's essentially a mirror of a map structure I have in a different system.
The problem I have is that the codes are automatically generated, so they get the UID names, whereas really I'd like to present them as 'key=value', 'key=value', etc (ideally I'd like to present it as a table).
I've already created a custom control and added it to share-config-custom, and confirmed that the configuration is working correctly. What I'm not really clear on now is:
a) How to attach a javascript to the control so that I can process the association data.
b) How to get hold of the codes in javascript, and read their properties.
I'm just looking for a push in the right direction.
Thanks :)
One idea would be to use a form filter. Your form filter could iterate over the child references, fetch each child node, grab the data you want to display and then add one or more new properties with that data.
Then, your form control is hooked to the fields your form filter dynamically added to the form data. It can then read and display the data as needed.
Without a form filter I think you'd have to use JavaScript to parse the child association refs and use AJAX calls to fetch each child's node data, then format that as needed. The form filter idea would be less traffic from the browser.
I am working on an application using JSF and Hibernate. The fields on the JSF form are backed by the Hibernate entities.
Ex:
value=#{bean.entity.value}
There is a Clear button which should empty all the fields on the form. There are 3 ways to do this:
Call a javascript function which loops through all the fields on the form and sets default value based on the type of field - text/checkbox/dropdown.
Call a bean method which creates a new entity (zeroes all fields) and assign the existing entities id to it. I hoped Hibernate would then update the row with that id, but instead it is creating a new row since it is a detached entity. Is there a way to fix this?
The most straight forward way is to call a bean method and manually set default values for all the fields in the entity. The problem with this is that there are too many fields and each time any change is made on the front end, I need to update the bean method accordingly.
Which is the most appropriate way to do this?
If no business is required to calculate the default value I would use JS function to reset fields. You will save one request to the server.
You could also generate JS function by JSF and get the default value from server side.
This won't solve the issue on page reload though.
I would like to know if I can send html elements attributes (like id, class or title) with a classic post form and save them in a db.
I know this is possible with AJAX, saving the values in variables with javascript and then sending them to a PHP file with $.post or $.ajax
But is it possible with a normal post submit form?
Thanks to all
This is not possible. Only the value- and the name-attribute are sent to the server when you use a classic submit. There is no way to get more attributes then these two.
So, you are forced to use javascript.
The following might be an alternative to your proposed $.post-function: you can adjust a form and then submit it using javascript. So, apart from the two JQuery-functions you mention, there is also a form.submit() method. You will have to manipulate the value- and name-attribute of the form-elements and then use .submit() to send those to the server.
This is not possible, only names and values are posted.
Im trying to create a form where a user can add as many details as they want. So for example the form has an input field for name. The client has the option to add that name or to keep adding names.
I want to make the data binding value an array of names. If not it just return the last input with the value of name.
I tried doing something like this:
{{input value=name[]}}
but that automatically threw an error. How can I accomplish this in emberJs?
Unfortunately, Ember doesn't accept indices in bindings expressions. All I can propose is to use this workaround.
This is for a web application using struts.
I have an array of objects in my Form that gets listed in a table. A user can add/edit/delete from the table. How would I send the changed table back to the Action class?
Will I need to create a string or array of strings, and parse that into an object? Is there a way that java/struts handles objects that are to be modified in the jsp? Or does this need to be cared for in javascript?
Struts binds the request parameters onto the ActionForm object based on name of the input.
actionFormObj.setBla(String x) { ... } matches <input name="bla"... in the form.
When you have related inputs, you can use maps or arrays for ActionForm properties and Struts is smart enough to treat them as well. See here.
Additionally, if your table contains read-only data that you switch to input when editing, you might have to deal with a lot of hidden fields in your form. If you still consider JavaScript as an option, you could create a POST request based on a JavaScript object (that you create with whatever data you wish from the table) and then use jQuery to send it. See here.
Indexed properties in struts, apparently takes care of this.