You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Shing Hing Man <ma...@yahoo.com> on 2006/10/24 21:53:28 UTC
Re: Dynamic Radiogroup
In the component FieldLabel, the parameter field
expects an object of type IFormcomponent.
(Please see
http://tapestry.apache.org/tapestry4/tapestry/ComponentReference/FieldLabel.html)
It looks as though the Java class for the Radio
component is not of type IFormcomponent.
Shing
--- Todd Orr <to...@gmail.com> wrote:
> Okay, new problem. When attempting to create labels
> for the radio
> inputs I am getting exceptions:
>
> <li jwcid="@For" source="ognl:suggestedAmounts"
> element="li"
> value="ognl:currentSuggestedAmount">
> <label jwcid="@FieldLabel" field="sug"><span
> jwcid="@Insert"
> value="ognl:currentSuggestedAmount.label" /></label>
> <input type="radio" jwcid="sug@Radio"
> value="ognl:currentSuggestedAmount.amount" />
> </li>
>
> Produces:
> Error converting value for template parameter field:
> No type converter
> for type org.apache.tapestry.form.IFormComponent is
> available
>
> Any thoughts? It says also "No type converter for
> type
> org.apache.tapestry.form.IFormComponent is
> available." but should I
> need to create a TypeConverter for a built in
> Tapestry component?
>
> Thanks
>
> On 10/23/06, Todd Orr <to...@gmail.com> wrote:
> > nevermind, im an ass
> >
> > On 10/23/06, Todd Orr <to...@gmail.com> wrote:
> > > I'm having trouble getting the radiogroup
> component to handle a nested
> > > For component. The following is nested within a
> Form component:
> > >
> > > <div jwcid="@RadioGroup"
> selected="ognl:suggestedAmount">
> > > <ul>
> > > <li jwcid="@For"
> source="ognl:suggestedAmounts" element="li"
> > > value="ognl:currentSuggestedAmount">
> > > <label><span
> jwcid="@Insert"
> > > value="ognl:currentSuggestedAmount.label"
> /></label>
> > > <input type="radio"
> jwcid="@Radio"
> > > value="ognl:currentSuggestedAmount.amount" />
> > > </li>
> > > </ul>
> > > </div>
> > >
> > > The form allows the user to choose one of a
> number of pre-determined -
> > > suggested - amounts.These amounts are typically
> database driven, but
> > > hard coded for testing. The related java is
> shown below:
> > >
> > >
> > > public abstract SuggestedAmount
> getSuggestedAmount();
> > >
> > > public abstract void
> setSuggestedAmount(SuggestedAmount amount);
> > >
> > > public abstract SuggestedAmount
> getCurrentSuggestedAmount();
> > >
> > > public abstract void
> setCurrentSuggestedAmount(SuggestedAmount amount);
> > >
> > > private static List<SuggestedAmount> amounts =
> null;
> > >
> > > public List<SuggestedAmount>
> getSuggestedAmounts() {
> > > if (amounts == null) {
> > > amounts = new
> ArrayList<SuggestedAmount>();
> > > SuggestedAmount a = new
> SuggestedAmount();
> > > a.setId("11111");
> > > a.setAmount(new
> BigDecimal(1000));
> > > a.setLabel("1K");
> > > amounts.add(a);
> > > a = new SuggestedAmount();
> > > a.setId("22222");
> > > a.setAmount(new
> BigDecimal(500));
> > > a.setLabel("0.5K");
> > > amounts.add(a);
> > > a = new SuggestedAmount();
> > > a.setId("33333");
> > > a.setAmount(new
> BigDecimal(250));
> > > a.setLabel("0.25K");
> > > amounts.add(a);
> > > a = new SuggestedAmount();
> > > a.setId("44444");
> > > a.setAmount(new
> BigDecimal(100));
> > > a.setLabel("0.1K");
> > > amounts.add(a);
> > > a = new SuggestedAmount();
> > > a.setId("55555");
> > > a.setAmount(new BigDecimal(50));
> > > a.setLabel("0.05K");
> > > amounts.add(a);
> > > }
> > > return amounts;
> > > }
> > >
> > > /**
> > > * Listener for form submittal.
> > > *
> > > */
> > > public void doSubmit) {
> > > BigDecimal amount = null;
> > > SuggestedAmount suggestedAmount =
> getSuggestedAmount();
> > > System.out.println(suggestedAmount);
> > > if (suggestedAmount != null) {
> > > amount =
> suggestedAmount.getAmount();
> > > }
> > > System.out.println("AMOUNT" + amount);
> > > }
> > >
> > > No matter what I choose, I get null print to the
> console. Has anyone
> > > had any experience using the Radiogroup in this
> way before?
> > >
> > > Thanks,
> > > T
> > >
> >
>
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail:
> users-help@tapestry.apache.org
>
>
Home page :
http://uk.geocities.com/matmsh/index.html
___________________________________________________________
All new Yahoo! Mail "The new Interface is stunning in its simplicity and ease of use." - PC Magazine
http://uk.docs.yahoo.com/nowyoucan.html
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Dynamic Radiogroup
Posted by Todd Orr <to...@gmail.com>.
I've tried the jwc approach with no luck.
JWC:
<component id="amountGroup" type="RadioGroup">
<binding name="selected" value="ognl:suggestedAmount" />
</component>
<component id="amountList" type="For">
<binding name="source" value="ognl:suggestedAmounts"/>
<binding name="value" value="ognl:currentSuggestedAmount"/>
<binding name="element" value="literal:li"/>
</component>
<component id="suggestedAmountField" type="Radio">
<binding name="value" value="ognl:currentSuggestedAmount" />
</component>
<component id="suggestedAmountLabel" type="FieldLabel">
<binding name="field" value="component:suggestedAmountField" />
<binding name="displayName" value="ognl:currentSuggestedAmount.label" />
<binding name="prerender" value="false" />
</component>
HTML:
<form method="post" jwcid="@Form" success="listener:doSubmit">
<div jwcid="amountGroup">
<h3><span jwcid="@Insert" value="message:title">TITLE</span></h3>
<ul>
<li jwcid="amountList">
<input id="suggestedAmount" type="radio" jwcid="suggestedAmountField" />
<label for="suggestedAmount" jwcid="suggestedAmountLabel">TEST</label>
</li>
</ul>
</div>
</form>
I did subclass Tap's built in Radio and implemented IFormComponent.
This stopped the errors from occurring, but didn't create the proper
id-for link between the FieldLabel and the Radio components.
On 10/24/06, Patrick Moore <tr...@gmail.com> wrote:
> your FieldLabel's field parameter is wrong, it should look like this:
>
> <label jwcid="@FieldLabel" field="component:sug">
>
> but if I remember correctly this will not work anyhow because sug is
> defined in the html after the FieldLabel. You will need to specify sug
> in your java or .jwc.
>
> -Pat
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
RE: Dynamic Radiogroup
Posted by Ben Sommerville <bs...@bulletproof.com.au>.
Ok, attachments don't work. Code follows inline.
++++++++++++++++++
package tapestry.components;
import org.apache.tapestry.form.RadioGroup;
import org.apache.tapestry.form.AbstractFormComponent;
import org.apache.tapestry.IMarkupWriter;
import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.Tapestry;
import org.apache.tapestry.annotations.Parameter;
import org.apache.tapestry.annotations.ComponentClass;
import org.apache.hivemind.ApplicationRuntimeException;
/**
* TODO: Doc this.
*
* @author Ben Sommerville
*/
@ComponentClass(allowBody = false, reservedParameters = "checked,type,name")
public abstract class FormRadio extends AbstractFormComponent {
@Parameter(name="id", defaultValue="id")
public abstract String getIdParameter();
@Parameter
public abstract String getDisplayName();
@Parameter
public abstract boolean isDisabled();
@Parameter
public abstract Object getValue();
/**
* Renders the form element, or responds when the form containing the
element
* is submitted (by checking {@link
org.apache.tapestry.form.Form#isRewinding()}.
*
*
**/
protected void renderFormComponent(IMarkupWriter writer, IRequestCycle
cycle)
{
RadioGroup group = RadioGroup.get(cycle);
if (group == null)
throw new ApplicationRuntimeException(
Tapestry.getMessage("Radio.must-be-contained-by-group"),
this,
null,
null);
// The group determines rewinding from the form.
//
// boolean rewinding = group.isRewinding();
int option = group.getNextOptionId();
//
// if (rewinding)
// {
// // If not disabled and this is the selected button within the
radio group,
// // then update set the selection from the group to the value
for this
// // radio button. This will update the selected parameter of
the RadioGroup.
//
// if (!isDisabled() && !group.isDisabled() &&
group.isSelected(option))
// group.updateSelection(getValue());
// return;
// }
//
writer.beginEmpty("input");
writer.attribute("type", "radio");
writer.attribute("name", group.getName());
renderIdAttribute(writer, cycle);
// As the group if the value for this Radio matches the selection
// for the group as a whole; if so this is the default radio and is
checked.
if (group.isSelection(getValue()))
writer.attribute("checked", "checked");
if (isDisabled() || group.isDisabled())
writer.attribute("disabled", "disabled");
// The value for the Radio matches the option number (provided by
the RadioGroup).
// When the form is submitted, the RadioGroup will know which option
was,
// in fact, selected by the user.
writer.attribute("value", option);
renderInformalParameters(writer, cycle);
}
protected void rewindFormComponent(IMarkupWriter writer, IRequestCycle
cycle) {
RadioGroup group = RadioGroup.get(cycle);
if (group == null)
throw new ApplicationRuntimeException(
Tapestry.getMessage("Radio.must-be-contained-by-group"),
this,
null,
null);
// The group determines rewinding from the form.
int option = group.getNextOptionId();
// If not disabled and this is the selected button within the radio
group,
// then update set the selection from the group to the value for
this
// radio button. This will update the selected parameter of the
RadioGroup.
if (!isDisabled() && !group.isDisabled() &&
group.isSelected(option))
group.updateSelection(getValue());
}
}
-----Original Message-----
From: Ben Sommerville [mailto:bsommerv@bulletproof.com.au]
Sent: Thursday, 26 October 2006 9:33 PM
To: 'Tapestry users'
Subject: RE: Dynamic Radiogroup
I ran into this problem too. FieldLabel does not work with Radio because it
is not an IFormComponent.
The order of FieldLabel & the component it refers to doesn't matter. Except
that if you put the FieldLabel after the component you have to set
prerender=false.
I worked around this by creating a radio component that is a form component.
The
attached file has the class. Now the disclaimer- this is code from 6 or 7
months ago on a project that didn't finish & was developerd early in my
tapestry learning cycle - treat with appropriate caution :)
cheers,
Ben
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
RE: Dynamic Radiogroup
Posted by Ben Sommerville <bs...@bulletproof.com.au>.
I ran into this problem too. FieldLabel does not work with Radio because
it is not an IFormComponent.
The order of FieldLabel & the component it refers to doesn't matter. Except
that if you put the FieldLabel after the component you have to set
prerender=false.
I worked around this by creating a radio component that is a form component.
The
attached file has the class. Now the disclaimer- this is code from 6 or 7
months
ago on a project that didn't finish & was developerd early in my tapestry
learning
cycle - treat with appropriate caution :)
cheers,
Ben
-----Original Message-----
From: Todd Orr [mailto:torr0101@gmail.com]
Sent: Thursday, 26 October 2006 1:44 AM
To: Tapestry users
Subject: Re: Dynamic Radiogroup
Reversing the radio and the label still causes this exception.
On 10/25/06, James Carman <ja...@carmanconsulting.com> wrote:
> I don't think it matters where you define it within the HTML. Quite
> often, the field label will come before the field it labels. I've
> never had to resort to a .page/.jwc file in this case.
>
> On 10/24/06, Patrick Moore <tr...@gmail.com> wrote:
> >
> > your FieldLabel's field parameter is wrong, it should look like this:
> >
> > <label jwcid="@FieldLabel" field="component:sug">
> >
> > but if I remember correctly this will not work anyhow because sug is
> > defined in the html after the FieldLabel. You will need to specify
> > sug in your java or .jwc.
> >
> > -Pat
> >
> > --------------------------------------------------------------------
> > - To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> > For additional commands, e-mail: users-help@tapestry.apache.org
> >
> >
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Dynamic Radiogroup
Posted by Todd Orr <to...@gmail.com>.
Reversing the radio and the label still causes this exception.
On 10/25/06, James Carman <ja...@carmanconsulting.com> wrote:
> I don't think it matters where you define it within the HTML. Quite often,
> the field label will come before the field it labels. I've never had to
> resort to a .page/.jwc file in this case.
>
> On 10/24/06, Patrick Moore <tr...@gmail.com> wrote:
> >
> > your FieldLabel's field parameter is wrong, it should look like this:
> >
> > <label jwcid="@FieldLabel" field="component:sug">
> >
> > but if I remember correctly this will not work anyhow because sug is
> > defined in the html after the FieldLabel. You will need to specify sug
> > in your java or .jwc.
> >
> > -Pat
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> > For additional commands, e-mail: users-help@tapestry.apache.org
> >
> >
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Dynamic Radiogroup
Posted by Patrick Moore <tr...@gmail.com>.
Your experence maybe different. but I found that if I had a component
that was not mentioned in java code nor in the .jwc file I would get
problems when using FieldLabel...
On 10/25/06, James Carman <ja...@carmanconsulting.com> wrote:
> I don't think it matters where you define it within the HTML. Quite often,
> the field label will come before the field it labels. I've never had to
> resort to a .page/.jwc file in this case.
>
> On 10/24/06, Patrick Moore <tr...@gmail.com> wrote:
> >
> > your FieldLabel's field parameter is wrong, it should look like this:
> >
> > <label jwcid="@FieldLabel" field="component:sug">
> >
> > but if I remember correctly this will not work anyhow because sug is
> > defined in the html after the FieldLabel. You will need to specify sug
> > in your java or .jwc.
> >
> > -Pat
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> > For additional commands, e-mail: users-help@tapestry.apache.org
> >
> >
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Dynamic Radiogroup
Posted by James Carman <ja...@carmanconsulting.com>.
I don't think it matters where you define it within the HTML. Quite often,
the field label will come before the field it labels. I've never had to
resort to a .page/.jwc file in this case.
On 10/24/06, Patrick Moore <tr...@gmail.com> wrote:
>
> your FieldLabel's field parameter is wrong, it should look like this:
>
> <label jwcid="@FieldLabel" field="component:sug">
>
> but if I remember correctly this will not work anyhow because sug is
> defined in the html after the FieldLabel. You will need to specify sug
> in your java or .jwc.
>
> -Pat
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
Re: Dynamic Radiogroup
Posted by Patrick Moore <tr...@gmail.com>.
your FieldLabel's field parameter is wrong, it should look like this:
<label jwcid="@FieldLabel" field="component:sug">
but if I remember correctly this will not work anyhow because sug is
defined in the html after the FieldLabel. You will need to specify sug
in your java or .jwc.
-Pat
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Dynamic Radiogroup
Posted by Todd Orr <to...@gmail.com>.
That's certainly going to make this difficult. Why is the easy stuff
so hard? I suppose I'll have to hack through and implement a
replacement for Radio. Any other suggestions?
On 10/24/06, Shing Hing Man <ma...@yahoo.com> wrote:
> In the component FieldLabel, the parameter field
> expects an object of type IFormcomponent.
> (Please see
> http://tapestry.apache.org/tapestry4/tapestry/ComponentReference/FieldLabel.html)
>
> It looks as though the Java class for the Radio
> component is not of type IFormcomponent.
>
> Shing
>
>
> --- Todd Orr <to...@gmail.com> wrote:
>
> > Okay, new problem. When attempting to create labels
> > for the radio
> > inputs I am getting exceptions:
> >
> > <li jwcid="@For" source="ognl:suggestedAmounts"
> > element="li"
> > value="ognl:currentSuggestedAmount">
> > <label jwcid="@FieldLabel" field="sug"><span
> > jwcid="@Insert"
> > value="ognl:currentSuggestedAmount.label" /></label>
> > <input type="radio" jwcid="sug@Radio"
> > value="ognl:currentSuggestedAmount.amount" />
> > </li>
> >
> > Produces:
> > Error converting value for template parameter field:
> > No type converter
> > for type org.apache.tapestry.form.IFormComponent is
> > available
> >
> > Any thoughts? It says also "No type converter for
> > type
> > org.apache.tapestry.form.IFormComponent is
> > available." but should I
> > need to create a TypeConverter for a built in
> > Tapestry component?
> >
> > Thanks
> >
> > On 10/23/06, Todd Orr <to...@gmail.com> wrote:
> > > nevermind, im an ass
> > >
> > > On 10/23/06, Todd Orr <to...@gmail.com> wrote:
> > > > I'm having trouble getting the radiogroup
> > component to handle a nested
> > > > For component. The following is nested within a
> > Form component:
> > > >
> > > > <div jwcid="@RadioGroup"
> > selected="ognl:suggestedAmount">
> > > > <ul>
> > > > <li jwcid="@For"
> > source="ognl:suggestedAmounts" element="li"
> > > > value="ognl:currentSuggestedAmount">
> > > > <label><span
> > jwcid="@Insert"
> > > > value="ognl:currentSuggestedAmount.label"
> > /></label>
> > > > <input type="radio"
> > jwcid="@Radio"
> > > > value="ognl:currentSuggestedAmount.amount" />
> > > > </li>
> > > > </ul>
> > > > </div>
> > > >
> > > > The form allows the user to choose one of a
> > number of pre-determined -
> > > > suggested - amounts.These amounts are typically
> > database driven, but
> > > > hard coded for testing. The related java is
> > shown below:
> > > >
> > > >
> > > > public abstract SuggestedAmount
> > getSuggestedAmount();
> > > >
> > > > public abstract void
> > setSuggestedAmount(SuggestedAmount amount);
> > > >
> > > > public abstract SuggestedAmount
> > getCurrentSuggestedAmount();
> > > >
> > > > public abstract void
> > setCurrentSuggestedAmount(SuggestedAmount amount);
> > > >
> > > > private static List<SuggestedAmount> amounts =
> > null;
> > > >
> > > > public List<SuggestedAmount>
> > getSuggestedAmounts() {
> > > > if (amounts == null) {
> > > > amounts = new
> > ArrayList<SuggestedAmount>();
> > > > SuggestedAmount a = new
> > SuggestedAmount();
> > > > a.setId("11111");
> > > > a.setAmount(new
> > BigDecimal(1000));
> > > > a.setLabel("1K");
> > > > amounts.add(a);
> > > > a = new SuggestedAmount();
> > > > a.setId("22222");
> > > > a.setAmount(new
> > BigDecimal(500));
> > > > a.setLabel("0.5K");
> > > > amounts.add(a);
> > > > a = new SuggestedAmount();
> > > > a.setId("33333");
> > > > a.setAmount(new
> > BigDecimal(250));
> > > > a.setLabel("0.25K");
> > > > amounts.add(a);
> > > > a = new SuggestedAmount();
> > > > a.setId("44444");
> > > > a.setAmount(new
> > BigDecimal(100));
> > > > a.setLabel("0.1K");
> > > > amounts.add(a);
> > > > a = new SuggestedAmount();
> > > > a.setId("55555");
> > > > a.setAmount(new BigDecimal(50));
> > > > a.setLabel("0.05K");
> > > > amounts.add(a);
> > > > }
> > > > return amounts;
> > > > }
> > > >
> > > > /**
> > > > * Listener for form submittal.
> > > > *
> > > > */
> > > > public void doSubmit) {
> > > > BigDecimal amount = null;
> > > > SuggestedAmount suggestedAmount =
> > getSuggestedAmount();
> > > > System.out.println(suggestedAmount);
> > > > if (suggestedAmount != null) {
> > > > amount =
> > suggestedAmount.getAmount();
> > > > }
> > > > System.out.println("AMOUNT" + amount);
> > > > }
> > > >
> > > > No matter what I choose, I get null print to the
> > console. Has anyone
> > > > had any experience using the Radiogroup in this
> > way before?
> > > >
> > > > Thanks,
> > > > T
> > > >
> > >
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> > users-unsubscribe@tapestry.apache.org
> > For additional commands, e-mail:
> > users-help@tapestry.apache.org
> >
> >
>
>
> Home page :
> http://uk.geocities.com/matmsh/index.html
>
>
>
>
>
> ___________________________________________________________
> All new Yahoo! Mail "The new Interface is stunning in its simplicity and ease of use." - PC Magazine
> http://uk.docs.yahoo.com/nowyoucan.html
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org