[Logo] RSF Discussions Forum
  [Search] Search   [Recent Topics] Recent Topics   [Members]  Member Listing   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
Wiring up UISelects...  XML
Forum Index -> RSF Help and Problems
Author Message
stevegithens
Request-scope Wrangler

Joined: 04/04/2006 20:34:52
Messages: 84
Location: ooeepooee
Offline

I'm a little confused about the proper way to wire up a Select combo. I've gotten some clues from the Cookbook XML example and UISelect.java.

Say I have the following html:

Code:
 <form rsf:id="basic-form" method="post">
 
 	<h1>Simple Pager</h1>    
 
 
 <div>
 <div class="listNav">
 	<span rsf:id="pagertext">Viewing 1 - 10 of XXX items</span><br/>
 	<input rsf:id="beginning" name="Submit" value="|<" type="submit" />
 	<input rsf:id="backward" name="Submit" value="<" type="submit" />
 	<select rsf:id="showselect" name="select2">
 		<option value="10" selected="selected">Show 10</option>
 		<option value="20">Show 20</option>
 		<option value="50">Show 50</option>
 		<option value="100">Show 100</option>
 	</select>
 	<input rsf:id="forward" name="Submit" value=">" type="submit" />
 	<input rsf:id="ending" name="Submit" value=">|" type="submit" />
 	<br/>
 </div>
 </div>
 </form>
 


I tried at first to do something like:
Code:
 UISelect show = UISelect.make(pagerform, "showselect");
 show.selection = new UIInput();
 show.selection.valuebinding = new   ELReference("#{pageraction.numberToShow}");
 


But I got a NullPointerException and HTML Render Error.

I see in the Cookbook XML that beans are being wired up to the optionslist and other things. When I'm constructing something like that, what containers to the selection and optionslist belong to? (The select, or form?)

A java example of constructing the full backing for a select would be sweet.

Thanks!
[WWW]
antranig
Request-scope Wrangler

Joined: 03/04/2006 13:29:55
Messages: 643
Offline

OK - you can see a pure-Java example of a (slightly complex) selection control in the last page of the Hibernate Cookbook http://rsf.fluidproject.org/wiki/Wiki.jsp?page=HibernateCookBook_4 (in the recipe editing page, just over half way down).

The key point is that UISelect is a "cluster" control, a composite of two UIBoundLists (representing the "palette" of selections, and their names) and a UIBound representing the submitted value. All of these fields will need to be set or else nothing can happen - if you look at the last "constructor" in UISelect.java you can see a more basic example of a fully-filled-out submitting control.

So the first problem in your example is that you have not set optionlist. Unfortunately there is no model in RSF whereby it will pick up a statically listed set of options from the HTML - sorry! Now I see you trying to do this of course I can see that might be rather cool, but it never struck me before Perhaps for 0.7 or so when we have "rendering reform".

So, to get your example to work, you will need to add some lines like
UIBoundList values = new UIBoundList();
values.setValue(new String[] {"10", "20", "50", "100"};
show.selection.optionlist = values;

and similar lines for the optionnames.

Although, for the optionnames, if you want to be really cool you can write in the same string array into optionnames.setValue and use a resolver !
Code:
 show.selection.optionnames.resolver = new BeanResolver() {
   public String resolveBean(Object bean) {
      return "Show " + bean;
    }};
 


If you want this resolver to be configurable you could instead declare it as a Spring bean in the context, and instead make the resolver be an ELReference to it.


I'll fix the code path you triggered to put in a more informative message.

stevegithens
Request-scope Wrangler

Joined: 04/04/2006 20:34:52
Messages: 84
Location: ooeepooee
Offline

Agh! I keep missing things on the Wiki, the java version is right there. Though I suppose I wouldn't haven't gotten far thinking I could leave the option part in the html.

Thanks!
[WWW]
antranig
Request-scope Wrangler

Joined: 03/04/2006 13:29:55
Messages: 643
Offline

Oh you can leave it in the HTML, since it's useful for previewing. It will just get overwritten once the control is rendered proper. But after thinking about it, I don't suppose letting people write optionlists statically would be any problem, I'll put it in for 0.6.2-dev



PS - on second thoughts I think I won't - this would mean I needed to parse in that part of the HTML template and interpret it, which would be some way off current RSF idioms....
stevegithens
Request-scope Wrangler

Joined: 04/04/2006 20:34:52
Messages: 84
Location: ooeepooee
Offline

Awesome.

I'm now wondering how to set the selected option in the combo box. I'd imagine that it trys to match the current value of UISelect.selection against the optionslist...

But what if you have more than one item with the same value, for example:

Code:
 <select>
   <option value="herbivore">Triceratops</option>
   <option value="carnivore">T-Rex</option>
   <option value="herbivore">Stegasaurus</option>
   <option value="carnivore">Velociraptor</option>
   <option value="carnivore">Megasaurus</option>
   <option value="herbivore">Brontosaurus</option>
   <option value="omnivore">Reasonablesaurus</option>
 </select>
 


What if I want Stegasaurus to be the selected item when the page loads?
[WWW]
antranig
Request-scope Wrangler

Joined: 03/04/2006 13:29:55
Messages: 643
Offline

You have more than one item with the same value!!! This is a great moral crime!

Seriously, the "value" really is meant to be the "unique" representation of what the selection value actually is. If you want to "de-normalise" it later, you could do this in the model, or you could have RSF do it with a resolver or darreshaper. But really, I don't think what you want to do is even supported by HTML, let alone RSF....
 
Forum Index -> RSF Help and Problems
Message Quick Reply
Go to:   
Powered by JForum 2.1.6 © JForum Team