Zend_Form_Element_Select onchange - ajax

I am unable to set value of text, radio and other form elements based on a select element onchange.
All form elements are part of the same form.
The values to be set are to be fetched from database table without refreshing/redirecting the whole page (may be using Ajax).
Solution should be MVC based. I am a ZF novice.

Made it work with the help of following link:
http://zendgeek.blogspot.in/2009/07/ajax-with-json-and-prototype-in-zend.html
I used JQuery $.ajax() in place of prototype.js Ajax.Request() as the latter was conflicting somewhere with a datepicker element and I thought why to include one more js file when already JQuery is there.

Related

Cascading dropdown lists within a form

I want to enable a pair of cascading dropdown lists within a form in an ASP.NET MVC3 / Razor2 application. Ideally the solution will meet the following goals:
Child list populated simply by changing the selection of the parent list
Both dropdown lists contained within the form as they need to post information on submit
Uses Ajax to avoid whole page round-trip
Uses Ajax Html helper for easy integration
Works even if javascript is not enabled
So, from a user point of view, when an item in the parent dropdown is selected, the contents of the child dropdown is refreshed to display items related to it.
Can anyone please suggest the best way to do this?
EDIT.
No takers ... suggests to me that there may be conflicting requirements in the above list of goals. The closest I got to the above was this article, which met all the goals except that it doesn't work nested within an Html form.
So, I will restate the problem in a different way: how can I make an AJAX call from a dropdown list within an Html form so that I can populated another dropdown list with related items?
Took some time to find a reasonable solution to this, although so far I still don't have a no-jquery fallback. This article shows you how to use AjaxHelper extensions to create your own Ajax-enabled controls. Works a treat, and very reusable.

Use of a4j:jsFunction Within a Paginated OpenFaces 3 Datatable

I've a paginated OpenFaces 3 datatable (using o:dataTablePaginator within a facet below the table) that has a column which contains an a4j:jsFunction tag (using RichFaces 4.1) to create (a differently named) JavaScript function within each row of the table. The JSF 2.1 page which contains the table is being deployed within an application onto Glassfish 3.1.
When I click the next page icon for the table, the datatable fails to update via AJAX with the OpenFaces AJAX "Loading..." message (with the "spinning" diamond) remaining displayed in the top right corner of the page. In Firebug, I can see the result of the OpenFaces AJAX Post being an error with the affected line 344 of ajaxUtil.js:
TypeError: xml.getElementsByTagName("partial-response")[0] is undefined
var childNodes = xml.getElementsByTagName("partial-response")[0].childNodes;
and the following error in IE Developer Tools:
SCRIPT5007: Unable to get value of the property 'childNodes'
: object is null or undefined
I've been able to eliminate all other tags within the datatable being the cause of the problem except for this one:
<a4j:jsFunction id="cellUpdateFunction#{rowIndex}"
name="updateCellStr#{rowIndex}"
data="#{backingBean.getStrForRow(rowIndex)}" execute="#this"
oncomplete="setCellText(#{rowIndex}, event.data);"/>
This creates a JavaScript function in a column cell (for each row of the table) that when called updates the text in the cell with the string stored for the cell within the backing bean.
Does anyone know whether this is a known issue and there is a workaround I've been unable to find? Otherwise, how would I go about writing similar functionality with OpenFaces AJAX as I expect that using only OpenFaces components would not break the AJAX call updating the OpenFaces datatable?
Thanks in advance for any help.
Can you try to use the nightly builds and check? You can find nightly builds here: http://openfaces.org/downloads/

Is there any way to keep current page when sorting jqgrid columns?

My jqgrid contains several pages. When I sort any column the page resets to first.
(That's right also for filterToolbar i.e. after calling $("#my-grid")[0].triggerToolbar();)
Is there any way to keep my current page after sorting/filtering ?
EDIT:
Actually my problem is a little more complicated.
I save jqgrid preferences(rowNum, page, filters etc..) to the cookie.
When I load the page first time I load the prefs.
I use the technique from Mark B's answer (see jqGrid Filter Toolbar initial default value) to populate my filter default values.
The problem: in that case page always sets to the first.(because of triggerToolbar calling) i.e. it doesn't save state.
I don't quite understand your requirement. If the user has seen some rows on the second page for example and then the user has clicked on the column header to sort the column the the grid will be sorted. The data which the user have seen before can be on any page. So I don't understand why you want hold the current page which will show absolutely another data as it showed before.
If you do need to hold the page you can do this in the following way. Inside of the loadComplete you can save the value of page parameter. Inside of onSortCol event handler the value will be already changed to 1, but you can correct it to the value which you saved before. I didn't tested this, but I think it should work.
UPDATED: Now I think I understand your original problem. I think you should choose another way described here or here. What you needs is just to save in the cookie the postData value and to set search:true parameter of jqGrid if the filters is not empty (or other filter parameter depend on the options which you use). In the way you should be able to restore not only the filter, but additionally the page value. The final solution can a little depend from jqGrid parameters and the parameters of filterToolbar which you use. So it you will have implementation problem you should include more code which you use.
I'm using mvc with jqgrid and this solition work for me:
$("#GridTable").jqGrid({
...
onSortCol:
function () {
var postpage = jQuery("#GridTable").getGridParam('postData');
jQuery("#GridTable").setGridParam({ page: postpage.page });
},
...
});

How to handle nested forms in ASP.NET MVC

I'm trying to build a fairly complex form which as a couple of cascading selects - i.e. the user selects a value in one combo and the other combo is populated according to their first selection.
I've followed a tutorial on how to handle the cascading but the problem I have is that I now have nested forms (the code in the tutorial uses forms inside partial views to POST to a controller action to load the 2nd combo). I have my main form on which I want to collect the input values but also the nexted forms for the cascading select boxes. The problem I have is that the cascading selection doesn't post to the correct controller action, but instead posts to my main (outer) form's action.
I understand this is the correct behaviour for a browser (as nested forms apparently aren't supported) but what's the correct way to implement this?
The correct way is to only have one form. Then use AJAX to populate the cascading drop down list. The are 100s of examples online how to do this with JSON
use this to have multiple submit buttons on one form which each have different controller actions to post to:
http://iwayneo.blogspot.co.uk/2013/10/aspnet-mvc-action-selector-with-list.html
as for cascading stuff - i would focus on populating these without Ajax 1st - then you can worry about adding this sort of flare - if it doesn't work without JS anyway you're in a bad place.
I would have the 1st dropdown populated when you initially load the form and have a "next" button to populate the next dropdown in the cascade. this submit can use the method above to post to an action which then populates the second data set based on the selection of the 1st dropdown.
make sense?
Then how you ajax that after the point is up to you but you'll have a very solid foundation to build up stuff like that as you will have it working in the minimal tech scenario.
w://

making primeFaces ajax call in dataTable

I am using JSF 2 with PrimeFaces 2.2. I tried making an ajax call through a select box onchange event in a dataTable. I was able to see the System.outs printing but, I could not see the components given in the update attribute getting updated. I have given the dataTableId in the update attribute.
I guess the problem now is the selectbox is getting populated again and an ajax call is made. Should we give only the parent tags in the update attirbute, for the ajax call to work. Please help me out in this.
When the ID in the update attribute does not start with :, it becomes relative to the ID of the current component inside the same NamingContainer component. But since the h:dataTable is an NamingContainer component, you need to reference it by an absolute ID. Rightclick the JSF page in the webbrowser and choose View Source to see the generated HTML DOM tree. Locate the HTML <table> element which is generated by the <h:dataTable>, determine the value of its id attribute and use exactly that id in the update attribute, prefixed with :.

Resources