You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by nquirynen <na...@pensionarchitects.be> on 2013/01/17 14:55:23 UTC

Radiogroup with Enum value and option with NULL value

Hi,

I have a RadioGroup with options based on an enum (Language).

*.tml*

<t:radiogroup t:value="selectedLanguage">
      <t:loop t:source="languages" t:value="loopLanguage">
          <t:radio t:value="language" />
${format:labeled=language.description}
      </t:loop>
</t:radiogroup>

*.class*

@Property
private Language selectedLanguage;

@Property
private Language loopLanguage;

public Language[] getLanguages() {
   return new Language[] { Language.NL, Language.FR, Language.DE };
}

Now I want to add a radio option representing a null value (no language
selected);

So I added this to my radiogroup (after the loop):

<t:radio t:value="null" /> ${message:unknown}


Then I get this exception:

/org.apache.tapestry5.ioc.util.UnknownValueException
Input 'on' does not identify a value from enumerated type
be.pensionarchitects.admindb.model.language.Language.

availableValues

    be.pensionarchitects.admindb.model.language.Language enum constants:

        DE
        EN
        FR
        NL/

I understand the problem here. But seeing my use case, is the only solution
to use a String and the Language enum String representations as values for
my radiogroup? Or can this be solved in an other way?

Nathan






--
View this message in context: http://tapestry.1045711.n5.nabble.com/Radiogroup-with-Enum-value-and-option-with-NULL-value-tp5719355.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: Radiogroup with Enum value and option with NULL value

Posted by nquirynen <na...@pensionarchitects.be>.
Hi,

Thanks Taha, I solved it in the following way:

I don't really want to add something to my Language enum. 
I replaced it with a "dummy" html radio input as you suggested. To make it a
part of the whole radiogroup I had to add the name attribute. Now I also had
to add the value attribute with an empty value, because else I got the same
error as I had initially. And with a condition I preselect the radio input
when needed.

<t:radiogroup t:id="grpLanguage" t:value="selectedLanguage">
      <t:loop t:source="languages" t:value="loopLanguage">
          <t:radio t:value="language" />
${format:labeled=language.description}
      </t:loop>
      <t:if t:test="selectedLanguage">
	  <input type="radio" name="grpLanguage" value="" />
	  <p:else>
		<input type="radio" checked="checked" name="grpLanguage" value="" />
	  </p:else>
      </t:if>
      ${message:unknown}
</t:radiogroup>



--
View this message in context: http://tapestry.1045711.n5.nabble.com/Radiogroup-with-Enum-value-and-option-with-NULL-value-tp5719355p5719379.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: Radiogroup with Enum value and option with NULL value

Posted by Taha Siddiqi <ta...@gmail.com>.
Hi

You can use another enumeration constant Language.NONE or use an html radio (as a dummy button already selected) and it will be ignored.

For showing localized messages, you can use a message catalog as mentioned in the documentation

http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/util/EnumSelectModel.html

A basic select model for a particular Enum type. The labels for each Enum are drawn from the Enum instance name and the provides message catalog:

As key ClassName.name if present. The class name excludes the package portion. Ex: "ElementType.LOCAL_VARIABLE"
As key name if present, i.e., "LOCAL_VARIABLE".
As a user-presentable version of the name, i.e., "Local Variable".


regards
Taha


On Jan 17, 2013, at 7:25 PM, nquirynen wrote:

> Hi,
> 
> I have a RadioGroup with options based on an enum (Language).
> 
> *.tml*
> 
> <t:radiogroup t:value="selectedLanguage">
>      <t:loop t:source="languages" t:value="loopLanguage">
>          <t:radio t:value="language" />
> ${format:labeled=language.description}
>      </t:loop>
> </t:radiogroup>
> 
> *.class*
> 
> @Property
> private Language selectedLanguage;
> 
> @Property
> private Language loopLanguage;
> 
> public Language[] getLanguages() {
>   return new Language[] { Language.NL, Language.FR, Language.DE };
> }
> 
> Now I want to add a radio option representing a null value (no language
> selected);
> 
> So I added this to my radiogroup (after the loop):
> 
> <t:radio t:value="null" /> ${message:unknown}
> 
> 
> Then I get this exception:
> 
> /org.apache.tapestry5.ioc.util.UnknownValueException
> Input 'on' does not identify a value from enumerated type
> be.pensionarchitects.admindb.model.language.Language.
> 
> availableValues
> 
>    be.pensionarchitects.admindb.model.language.Language enum constants:
> 
>        DE
>        EN
>        FR
>        NL/
> 
> I understand the problem here. But seeing my use case, is the only solution
> to use a String and the Language enum String representations as values for
> my radiogroup? Or can this be solved in an other way?
> 
> Nathan
> 
> 
> 
> 
> 
> 
> --
> View this message in context: http://tapestry.1045711.n5.nabble.com/Radiogroup-with-Enum-value-and-option-with-NULL-value-tp5719355.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
>