PDA

View Full Version : clearing referencedata


Ric.hard
Jun 4th, 2006, 11:17 AM
hi guys,

heres my code for my referencedata. I have been able to display my dynamic content with no problems but how do i make sure that the session is empty and the attributes countries and states are empty everytime i enter the first page, BUT not to be emptied when I click the back button ( _target0 btn ).

please advise.
thanks
richard


protected Map referenceData(HttpServletRequest request, int page) {

Map refData = new HashMap();

switch (page) {
case 0:
List list = ( List ) this.phonePlansDao.getInternationalPhonePlans();
List list2 = ( List ) this.phonePlansDao.getUSCPhonePlans();
refData.put("internationalPhonePlans", list);
refData.put("usPhonePlans", list2);
break;
case 1:
refData.put("countries", this.getCountries());


String currCountry = this.getSelectedCountry() ;
Country selectedCountry = null;
if ( currCountry != null ){
selectedCountry = this.getCountry( this.getSelectedCountry() ) ;
if ( selectedCountry != null ){
HashSet states = (HashSet) selectedCountry.getStateProvinceRegion() ;
refData.put("states", states);
}
}

String currState = this.getSelectedState();
StateProvinceRegion selectedState = null ;
if ( currState != null ){
selectedState = this.getState( selectedCountry, this.getSelectedState() );
if ( selectedState != null ){
HashSet areaCodes = ( HashSet) selectedState.getAreaCodes();
refData.put("areaCodes", areaCodes);
}
}

String currAC = this.getSelectedAreaCode();
AreaCode currACObj = null;
if ( currAC != null ){
currACObj = this.getAreaCode( selectedState,currAC ) ;
if ( currACObj != null ){
HashSet XCodes = ( HashSet) currACObj.getExchangeCodes();
refData.put("XCodes", XCodes);
}
}
break;
}

return refData;

manifoldronin
Jun 4th, 2006, 04:19 PM
As far as I know, Spring MVC doesn't keep the ref data in the session - or maybe I'm missing your question.

Ric.hard
Jun 4th, 2006, 08:55 PM
hi manifoldronin,

you maybe right, but whereever spring keeps these values i need it cleared when the user enters the first page of the wizard but NOT cleared when the user plays with the back and next submit button.

thanks.

any ideas.

richard

As far as I know, Spring MVC doesn't keep the ref data in the session - or maybe I'm missing your question.

rstearns01
Jun 5th, 2006, 09:30 AM
One solution is to not populate it in the reference data, but treat it as a form change. If you'll look at the control flow for AbstractFormController (which both SimpleFormController and AbstractWizardFormController derive) and its superclasses, referenceData() is called when first showing the form, allowing you to populate static or initial information. As this is not the time you want to populate those particular items, you can save yourself some conditional logic not to do it there. When the user takes an action, you can submit the form and override isFormSubmission() to determine if you only need dynamic data to change. If this is the case, then by overriding onFormChange() you can set your dynamic data into the model and the form redisplays.

Another option, if you don't want a server call and there's not too much data, is to populate the dropdowns with populated objects (i.e. a Country contains a list of its States) and use a little JavaScript to repopulate the states input when the country fires an onChange() event.

We've done it both ways.

HTH

Ric.hard
Jun 5th, 2006, 10:07 AM
Thanks Randy. Tried it the javascript way. found an existing javascript code to populate coutry-state-areacode. Id rather use this than retyping all states and their areacodes. I created a hidden fields and bind them to spring.

Thanks
Richard

One solution is to not populate it in the reference data, but treat it as a form change. If you'll look at the control flow for AbstractFormController (which both SimpleFormController and AbstractWizardFormController derive) and its superclasses, referenceData() is called when first showing the form, allowing you to populate static or initial information. As this is not the time you want to populate those particular items, you can save yourself some conditional logic not to do it there. When the user takes an action, you can submit the form and override isFormSubmission() to determine if you only need dynamic data to change. If this is the case, then by overriding onFormChange() you can set your dynamic data into the model and the form redisplays.

Another option, if you don't want a server call and there's not too much data, is to populate the dropdowns with populated objects (i.e. a Country contains a list of its States) and use a little JavaScript to repopulate the states input when the country fires an onChange() event.

We've done it both ways.

HTH