Hi,
I've been trying to follow the recipe for creating the dynamic select
elements (http://tinyurl.com/y4ssym) but there's something I'm not
understanding... the selectListHelper method wants the bean with the
item to be the select target ("item" in the example) as part of its
argument list ... which would need to be already populated ... which
would mean that the form would already be posted so that
getSubmissionBean() would have to have been called already so as to
have a non-null bean to pass to selectListHelper().
e.g.:
public class AddVenue extends Element {
private Venue mVenue = null;
private Datasource mDatasource = Datasources.getRepInstance
().getDatasource(Config.getRepInstance().getString("DATASOURCE"));
private ContentQueryManager<Venue> mVenueQM = new
ContentQueryManager<Venue>(mDatasource, Venue.class);
// get the External Data Providers from the DB
private ContentQueryManager<ExternalDataProvider> mProviderQM =
new ContentQueryManager<ExternalDataProvider>(mDatasource,
ExternalDataProvider.class);
private List<ExternalDataProvider> DataProviderList =
mProviderQM.restore(); // get all the items in the DB
// get the country codes from the DB
private ContentQueryManager<Country> mCountryQM = new
ContentQueryManager<Country>(mDatasource, Country.class);
private List<Country> CountryList = mCountryQM.restore(); //
get all the items in the DB - right now we just have English so
that's OK.
// TODO in v1.1: add equiv. of WHERE lang =
USER_LANGUAGE_PREFERENCE so we're fully internationalizable
public void processElement() {
Template t = getHtmlTemplate("admin.AddVenue");
ValidationBuilderXhtml validator = new ValidationBuilderXhtml
();
// Populate a map of ExternalDataProvider IDs to names. we
already pulled a list of ExternalDataProviders
// from the database and stashed them in DataProviderList
Map<Integer, String> providerMap = new HashMap<Integer,
String>();
for (ExternalDataProvider mDataProvider : DataProviderList) {
providerMap.put(mDataProvider.getId(),
mDataProvider.getName());
}
// populate a map with the countries list, this time using strings
since we want to show the full country name in the list, but only get
back the ISO digraph
// e.g., "United States of America" => "US"
Map<String, String> CountryMap = new HashMap<String, String>();
for (Country mCountryProvider : CountryList) {
CountryMap.put(mCountryProvider.getCountry_code(),
mCountryProvider.getCountry_name());
}
// ????? I am presuming the arg #2 ("item") is the bean we're
filling out with this form.. no?
SelectListHelper.prepareSelectList(t, mVenue, "providerId",
providerMap, null, "Please select a Data Provider."); // TODO replace
English. text with a externalized l10n string
// ditto
SelectListHelper.prepareSelectList(t, mVenue, "country",
CountryMap, null, "Country...."); // TODO replace English. text with
a externalized l10n string
while (true) {
t.setBlock("step1", "step1");
print(t); //print template
pause(); // ... and wait the user to hit submit
if (hasSubmission("addvenue")) {
mVenue = getSubmissionBean("addvenue", Venue.class);
// check for and post validation errors where needed; rinse, repeat
until user gets it right... (or gives up :)
:
:
Of course I get a NPE (since mVenue is null when selectListHelper
runs) if I run it like this... and if I move the selectListHelper
down into the loop, I get all sorts of errors about non-clonable
objects.
Is this a catch-22, or am I missing something here? (Or, am I
implementing this multi-part form in a sloppy/pessimal kind of way..?)
regards,
David
------------------------------------------------------------------------
-------------------
David HM Spector
spector (at) zeitgeist.com
http://www.zeitgeist.com/
voice: +1 631.261.5013 fax:
+1 212.656.1443
~ ~ ~
"New and stirring things are belittled because if they are not
belittled, the
humiliating question arises, 'Why then are you not taking part in
them?'"
--H. G. Wells
_______________________________________________
Rife-users mailing list
[email protected]
http://lists.uwyn.com/mailman/listinfo/rife-users