You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by bogdan_cm <bo...@rbccm.com> on 2011/05/04 15:22:12 UTC

getter/setter for textfield component

Hi all, 
   I have a textfield component inside a loop. The value of the text
component is set like this:
  <t:textfield t:value="getValueForKey(for_value)"></t:textfield>

The entire loop is enclosed in a <form>. When i try to submit the form, I
get the following error:

An exception has occurred: Failure writing parameter 'value' of component
Index:textfield: Expression 'getValueForKey(for_value)' for class
com.example.tutorial.pages.Index is read-only


My Java class does contain a setter method:

	public String getValueForKey(String key) {
		return arUser.getValueForKey(key);
	}

	public void setValueForKey(String key) {
		System.out.println("DO NOTHING");
	}

The only funny thing i'm doing here is that the java class does not have a
property "per se", only getter and setter methods. 

Thanks very much, 
Bogdan. 




--
View this message in context: http://tapestry.1045711.n5.nabble.com/getter-setter-for-textfield-component-tp4369806p4369806.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: getter/setter for textfield component

Posted by bogdan_cm <bo...@rbccm.com>.
Interesting. I just did not realize the class property will be assigned the
map keys one by one as I loop through them (the documentation clearly states
this ).  

Thanks for the reply, 
Bogdan. 

--
View this message in context: http://tapestry.1045711.n5.nabble.com/getter-setter-for-textfield-component-tp4369806p4369852.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: getter/setter for textfield component

Posted by Taha Hafeez <ta...@gmail.com>.
You can't use 'getValueForKey(for_value)' in a template

Here is how I would do it

<t:loop source='keys' value='key'>
   <t:textfield t:value='value'/>
</t:loop>

private Map<String, String> something;

@Property
private String key;

public Set<String> getKeys(){
   //Somehow you have already loaded the map
   return something.keySet();//keys
}

public String getValue(){
   return something.get(key);
}

public void setValue(String value){
   something.put(key, value);
}

regards
Taha


On Wed, May 4, 2011 at 6:52 PM, bogdan_cm <bo...@rbccm.com> wrote:

> Hi all,
>   I have a textfield component inside a loop. The value of the text
> component is set like this:
>  <t:textfield t:value="getValueForKey(for_value)"></t:textfield>
>
> The entire loop is enclosed in a <form>. When i try to submit the form, I
> get the following error:
>
> An exception has occurred: Failure writing parameter 'value' of component
> Index:textfield: Expression 'getValueForKey(for_value)' for class
> com.example.tutorial.pages.Index is read-only
>
>
> My Java class does contain a setter method:
>
>        public String getValueForKey(String key) {
>                return arUser.getValueForKey(key);
>        }
>
>        public void setValueForKey(String key) {
>                System.out.println("DO NOTHING");
>        }
>
> The only funny thing i'm doing here is that the java class does not have a
> property "per se", only getter and setter methods.
>
> Thanks very much,
> Bogdan.
>
>
>
>
> --
> View this message in context:
> http://tapestry.1045711.n5.nabble.com/getter-setter-for-textfield-component-tp4369806p4369806.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>