You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Andreas Bulling <sp...@phoenix.hadiko.de> on 2006/02/26 17:28:46 UTC

propertySelection question

Hi everybody,

just a short question I wasn't able to find an answer to neither in the
archives nor in the online documentation:

I have a PropertySelection component on my page showing a list of user types
the visitor can select from when registering himself on the page. Instead of
using the string value of the selection (the textual user type) I want to use
the Integer representation (the value of the select html element). How can
I accomplish that? I'm using a custom SelectionModel if this is relevant ;)

Thanks a lot in advance!
Sincerly,
  Andreas

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: propertySelection question

Posted by Andreas Bulling <sp...@phoenix.hadiko.de>.
| You have created your own model? Show us that!

Sorry - I created an own model for other selections but _not_ for the user selection
(it contains only static values so far - that's why I forgot to change this).
I used a standard StringPropertySelectionModel and I jsut saw that getValue()
seems to return a String there... *ups*
I changed that to my own model and now it works ;)

Thanks anyway for your help and sorry again!

Andreas


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: propertySelection question

Posted by Alan Chandler <al...@chandlerfamily.org.uk>.
On Sunday 26 February 2006 17:40, Andreas Bulling wrote:
>
> If I change
>
> 	public abstract String getUserType();
>
> to
>
> 	public abstract Integer getUserType();

You are showing us the wrong part

You have created your own model? Show us that!

What do the getOption() and translateValue() methods do in this model?

It looks as though the "Object" type that it returns is a String, and you want 
it to return an Integer.

Thats what the code I posted in my last message did.  You loaded an array of 
strings, and the user selected from the list of strings.  The server side 
property got set with the integer index of the string chosen.

-- 
Alan Chandler
http://www.chandlerfamily.org.uk
Open Source. It's the difference between trust and antitrust.

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: propertySelection question

Posted by Andreas Bulling <sp...@phoenix.hadiko.de>.
Hi Alan,

thanks for your answer!

| Look at the example under the @PropertySelection component in the user guide.

Well, that was the first thing I did but I thought that there has to be
something else as I have my own SelectionModel (with all these getxxx and
translatexxx methods) but it still doesn't work.

<component id="inputType" type="PropertySelection">
	<binding name="value" value="userType"/>
	<binding name="model" value="modelSource.userModel"/>
</component>

Perhaps I wasn't able to describe the actual problem:
The <select> is displayed correctly but when the user submits the form
instead of the integer value associated to each select entry the string
representation is send to the page class.

If I change

	public abstract String getUserType();

to

	public abstract Integer getUserType();

I see an ognl error. :(
Perhaps: Do I have to write my own translator?

Sincerly,
  Andreas

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: propertySelection question

Posted by Alan Chandler <al...@chandlerfamily.org.uk>.
On Sunday 26 February 2006 16:28, Andreas Bulling wrote:
> Hi everybody,
>
> just a short question I wasn't able to find an answer to neither in the
> archives nor in the online documentation:

Look at the example under the @PropertySelection component in the user guide.

>
> I have a PropertySelection component on my page showing a list of user
> types the visitor can select from when registering himself on the page.
> Instead of using the string value of the selection (the textual user type)
> I want to use the Integer representation (the value of the select html
> element). How can I accomplish that? I'm using a custom SelectionModel if
> this is relevant ;)

I made myself a component that does what I think you want below.
(If you want to see more details of the usage, I have all the application on 
my web site.  You can either browse the code - start by going to 

http://www.chandlerfamily.org.uk/git/?p=akcmoney.git;a=summary

choose the latest commit from the shortlog - select that "commit" link and 
then in the resultant page select the "tree" link.  That will show you the 
code which you can then browse either the Javasource of the WebContent

Alternatively - the download page on my site has a tarball of the latest 
version

package uk.org.chandlerfamily.akcmoney.components;
/*Copyright (c) 2006 Alan Chandler, licenced under the GPL (see LICENCE.txt 
file in META-INF directory)*/

import org.apache.tapestry.form.IPropertySelectionModel;

public class ValueSelectionModel implements IPropertySelectionModel {

	private String[] options;
	
	public ValueSelectionModel (String[] options) {
		this.options = options;
	}

	public int getOptionCount() {
		return options.length;
	}

	public Object getOption(int index) {
		return (Integer) index;
	}

	public String getLabel(int index) {
		return options[index];
	}

	public String getValue(int index) {
		return Integer.toString(index);
	}

	public Object translateValue(String index) {
		return (Integer) Integer.parseInt(index);
	}

}

-- 
Alan Chandler
http://www.chandlerfamily.org.uk
Open Source. It's the difference between trust and antitrust.

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org