sj:select tag in struts2-jquery plugin calls the JSON method again when the page gets submitted for a different action - struts2

This question is on Struts2 jquery plugin. While loading a JSP be default I am loading one dropdown list values and the second dropdown values are loaded based on selection of first dropdown. When the second dropdown value is selected an onChange event get executed and the page is getting refreshed. When the page is refreshing the First dropdown is getting called again! Is there anyway to avoid the second time execution of default loading of firstdropdown and also need to hold the selected values for both the submitted dropdown values of the JSP?
Note: First dropdown and second dropdowns are evaluated in SampleAction.java and onChange event executes LoadAction.java
Please let me know if you require further details!
Thanks

An option from the first dropdown is selected
Second dropdown is filled accordingly and then a value is selected
Instead of page-refresh, you can submit a form passing the values of both select tags
Now you get the selected values in your action and then you can show the same page but with prefilled values. This time when the page loads, the first select box by default shows the same previously selected value.
For the second select to show the previously selected value, you'll have to write some javascript code which will select the previously selected value.

Related

Pre-populate ListBox / MultiSelectList with selected items

Is there a way to pre-populate a MultiSelectList with selected items?
Example:
I have a single View that has the following ListBoxFor that will cause the page to update what it's displaying by allowing filtering of Model.Companies.
#Html.ListBoxFor(m => m.SelectedCompanies, new MultiSelectList(Model.Companies, "IdString", "CompanyName")
What I'd like to have happen is after the update, the MultiSelectList will have the items that were selected before the page updated and refreshed. Does that mean I need to return SelectedCompanies with what was selected, or is there another way?
I am using the javascript library Chosen for usability of the ListBox on the client side, but I don't think that this affects what I'm trying to do.
Sometimes, JS libaries can interfere with your desired results. I can't speak for Chosen JS library, but inspect the markup and see how it renders. As long as it still has the listbox on the client (it must have some input element defined somewhere; my guess it hides it and updates the values as they are selected), then yes it should integrate fine.
However, when the controller posts back, you have to repopulate the Model.SelectedCompanies property with whatever values came back from the POST operation to the controller. The property should still have the selected companies if you return a View from the POST operation. If you are using a RedirectToAction instead, you'd have to store the selections in TempData.

How to retain values of dropdown with selected values in MVC?

The scenario is - There are two view in my mvc application. One is Index and other is for adding payment details. in index form I fetch details of a perticular client in that I have cascading dropdown one for selecting type and one for according to type select client in another dropdown, both are coming from DB's and on d same view I have an ActionLink for going on Payments view "for adding the payment details for the same client that is been selected on Index views second dropdown (first is for Type)".
My problem is that when I am going on Payments view and clicking back button of browser to go back on my index page it is clearing the second dropdown. and all other data is safe on the form. So can you please help me to avoid this so that all the data of my Index view should retain throughout the execution.
This also in case when I add Payment for that client and click submit it should redirect on the Index view with retaining all its previous data. that we have fetched on Index page.
with a message box Payment Added successfully.
You can save the current selected values of dropdown1 and dropdown2 into one of the followings:
URL
Session
Cookie
Then in the Index page you always check to read those values if they are existed to setup the dropdowns in the first request. Then do update those values again whenever user selects to update the dropdowns.

How to handle default dropdown values using jquery ajax in mvc3?

Based on selection of first dropdown i am binding another drop down values based on first dropdownid value.My question is i given default first dropdown value as "select" but there is no id value for that in second dropdown to get the values.if user selectes "select" in frist dropdown i need to load all values in second dropdown.please tell me how to acheive this?
If you given default first dropdown value as "select" means, at that time disable the second drop down value. If 'country' value equal to 'select' means, at that time disable the 'state drop down'.When we click that country 'select' at that time also call that disable drop down function.
For example HTML view page, country drop down displayed. From that you will get country ID.
$countryID=> From your MVC code you have pass default country ID (default ID)
$countrySelected=$this->getCountryFromName(trim($countryID']));
if ($countrySelected!= ''){
$sVal=$this->getStateList($countrySelected);
$newStateList=array('0'=>'State');
$newStateList+=$this->formatDropdownArray($sVal,'STATE_ID','NAME');
$stateSelected='State';
echo CHtml::dropDownList('STATE_IDD',$stateSelected,$newStateList,array('tabindex'=>9));
}else{
$stateSelected=$defaultState;
echo CHtml::dropDownList('STATE_IDD',$stateSelected,$stateList,array('tabindex'=>9));
}

how to populate values in listbox based on value entered in textbox in BIRT?

I want to populate values in a list box based on a value entered in textbox. It cant be aceived through cascading paramters as all parameters in Cascading parameters are List Boxes. But my requirement is to populate values inside a ListBox based on the value entered inside a textbox. Please help.
Cascading parameter is the only way to define a dependency between two parameters. As you can see, the birt web viewer displays a textbox just below each combobox, and a radio button to select if we fill each list parameter from the combobox or the textbox:
I know some users had exactly the same requirement, and have successfully modified "ComboBoxParametersFragments.jsp" to display only the textbox when it is needed. For example we can use a specific prefix in the parameter name, or a user property, so that we can decide in the JSP if we hide the combobox or not.

I want to Dynamically Create Select list when i click a button by using struts2 tag?

I want to Dynamically Create Drop down list when i click a Button and the value selected in the Drop Down List should be inserted into the Database The Drop Down List should be in Struts2 Tag.
function addDropDown(parent){
var myselect = document.createElement("select");
myselect.setAttribute("name","someName");
myselect.onchange=function(){ submitvalue(this.value) };
theOption=document.createElement("OPTION");
theText=document.createTextNode("text gere1");
theOption.appendChild(theText);
theOption.setAttribute("value","value here1");
myselect.appendChild(theOption);
theOption=document.createElement("OPTION");
theText=document.createTextNode("text gere2");
theOption.appendChild(theText);
theOption.setAttribute("value","value gere2");
myselect.appendChild(theOption);
theOption=document.createElement("OPTION");
theText=document.createTextNode("text gere3");
theOption.appendChild(theText);
theOption.setAttribute("value","value gere3");
myselect.appendChild(theOption);
parent,appendChild(myselect);
}
call this function onClick of your button with some parent element(form or div) as argument.The function submitvalue() will be called on selection of any element of the dropdown, do your database submit action there(submit using ajax or whatever you are using as you have not mentioned it). I also noticed you have mentioned that the dropdown should be in struts2 tags, icouldnt wonder why as even the static struts2 tags get changed to html tags when executed

Resources