Hello again, I have a new problem related to this loop of radio buttons :
I want to make a list of forms, with each form containing a list of radio buttons. I can easily do that in a "static" way, with an index.tml file containing the following lines : ... <t:surveys.surveySuggestionsForm surveyId="1" /> <t:surveys.surveySuggestionsForm surveyId="2" /> <t:surveys.surveySuggestionsForm surveyId="3" /> ... And the SurveySuggestionsForm.tml : <t:form t:id="survey_form"> <t:radiogroup t:id="suggestionRG" value="selectedSuggestion" encoder="suggestionEncoder"> <t:loop source="suggestions" value="suggestionLoopValue" encoder="suggestionEncoder"> <t:radio t:id="radio" value="suggestionLoopValue"/> <t:label for="radio">${suggestionLoopValue.label}</t:label> </t:loop> </t:radiogroup> <t:submit id="surveyVote" t:id="vote" t:mixins="confirm" image="context:images/vote_button.gif" /> </t:form> Here is the code of SurveySuggestionsForm.java public class SurveySuggestionsForm { private static final Logger sLogger = Logger.getLogger (SurveyResults.class); @Parameter(required=true) private int surveyId; @Inject private ApplicationStateManager applicationStateManager; @Inject private ISurveyManager mSurveyManager; @Property(write=false) @Persist private User userInSession; @Property @Persist("SESSION") private com.titans.surveys.model.Survey survey; @Persist @Property private Suggestion selectedSuggestion; @SuppressWarnings("unused") @Property private Suggestion suggestionLoopValue; @Property @Persist private List<Suggestion> suggestions; @SuppressWarnings("unused") @Property private ValueEncoder<Suggestion> suggestionEncoder = new ValueEncoder<Suggestion> () { public String toClient (Suggestion pSuggestion) { return (String.valueOf (suggestions.indexOf (pSuggestion))); } public Suggestion toValue (String pId) { return (suggestions.get (Integer.parseInt (pId))); } }; public void beginRender() { this.survey = mSurveyManager.findById(surveyId); if (this.survey == null) { sLogger.error("Survey in parameter is null"); } else { userInSession = applicationStateManager.get(SessionContent.class).getUser(); this.suggestions = new ArrayList<Suggestion>(survey.getSuggestions()); } } public String onSuccess () { boolean resultOfVote = mSurveyManager.vote(survey, userInSession, selectedSuggestion); return null; } public boolean isSurveyNotNull() { return (survey != null); } public boolean isUserLoggedIn() { return (userInSession != null); } } The problem is when the surveyId in parameter of the surveySuggestionsForm component is filled in a dynamic way : <t:loop source="surveys" value="surveyLoopValue" encoder="surveyEncoder"> <t:surveys.surveySuggestionsForm surveyId="${surveyLoopValue.id}" /> </t:loop> In this case, when a form is submited, the related surveySuggestionsForm didn't seem to receive the correct value for the list named "suggestions", and an exception is throwed : org.apache.tapestry5.runtime.ComponentEventException: Index: 3, Size: 3 [at classpath:com/titans/surveys/components/surveys/SurveySuggestionsForm.tml, line 4] at org.apache.tapestry5.internal.structure.ComponentPageElementImpl.triggerContextEvent(ComponentPageElementImpl.java:1098) at org.apache.tapestry5.internal.services.ComponentEventRequestHandlerImpl.handle(ComponentEventRequestHandlerImpl.java:75) at org.apache.tapestry5.internal.services.ImmediateActionRenderResponseFilter.handle(ImmediateActionRenderResponseFilter.java:42) at $ComponentEventRequestHandler_126227efea9.handle($ComponentEventRequestHandler_126227efea9.java) at org.apache.tapestry5.internal.services.AjaxFilter.handle(AjaxFilter.java:42) at $ComponentEventRequestHandler_126227efea9.handle($ComponentEventRequestHandler_126227efea9.java) at org.apache.tapestry5.services.TapestryModule$36.handle(TapestryModule.java:2164) at $ComponentEventRequestHandler_126227efea9.handle($ComponentEventRequestHandler_126227efea9.java) at $ComponentEventRequestHandler_126227efe20.handle($ComponentEventRequestHandler_126227efe20.java) at org.apache.tapestry5.internal.services.ComponentRequestHandlerTerminator.handleComponentEvent(ComponentRequestHandlerTerminator.java:43) at com.titans.surveys.services.access.AccessComponentRequestFilter.handleComponentEvent(AccessComponentRequestFilter.java:32) at $ComponentRequestHandler_126227efe21.handleComponentEvent($ComponentRequestHandler_126227efe21.java) at $ComponentRequestHandler_126227efe13.handleComponentEvent($ComponentRequestHandler_126227efe13.java) at org.apache.tapestry5.internal.services.ComponentEventDispatcher.dispatch(ComponentEventDispatcher.java:46) at $Dispatcher_126227efe15.dispatch($Dispatcher_126227efe15.java) at $Dispatcher_126227efe0c.dispatch($Dispatcher_126227efe0c.java) at org.apache.tapestry5.services.TapestryModule$RequestHandlerTerminator.service(TapestryModule.java:245) at org.apache.tapestry5.internal.services.RequestErrorFilter.service(RequestErrorFilter.java:26) at $RequestHandler_126227efe0d.service($RequestHandler_126227efe0d.java) at org.apache.tapestry5.services.TapestryModule$4.service(TapestryModule.java:778) at $RequestHandler_126227efe0d.service($RequestHandler_126227efe0d.java) at org.apache.tapestry5.services.TapestryModule$3.service(TapestryModule.java:767) at $RequestHandler_126227efe0d.service($RequestHandler_126227efe0d.java) at org.apache.tapestry5.internal.services.StaticFilesFilter.service(StaticFilesFilter.java:85) at $RequestHandler_126227efe0d.service($RequestHandler_126227efe0d.java) at com.titans.surveys.services.AppModule$1.service(AppModule.java:100) at $RequestFilter_126227efe08.service($RequestFilter_126227efe08.java) at $RequestHandler_126227efe0d.service($RequestHandler_126227efe0d.java) at org.apache.tapestry5.internal.services.CheckForUpdatesFilter$2.invoke(CheckForUpdatesFilter.java:90) at org.apache.tapestry5.internal.services.CheckForUpdatesFilter$2.invoke(CheckForUpdatesFilter.java:81) at org.apache.tapestry5.ioc.internal.util.ConcurrentBarrier.withRead(ConcurrentBarrier.java:85) at org.apache.tapestry5.internal.services.CheckForUpdatesFilter.service(CheckForUpdatesFilter.java:103) at $RequestHandler_126227efe0d.service($RequestHandler_126227efe0d.java) at $RequestHandler_126227efe02.service($RequestHandler_126227efe02.java) at org.apache.tapestry5.services.TapestryModule$HttpServletRequestHandlerTerminator.service(TapestryModule.java:197) at org.apache.tapestry5.internal.gzip.GZipFilter.service(GZipFilter.java:53) at $HttpServletRequestHandler_126227efe04.service($HttpServletRequestHandler_126227efe04.java) at org.apache.tapestry5.internal.services.IgnoredPathsFilter.service(IgnoredPathsFilter.java:62) at $HttpServletRequestFilter_126227efe01.service($HttpServletRequestFilter_126227efe01.java) at $HttpServletRequestHandler_126227efe04.service($HttpServletRequestHandler_126227efe04.java) at org.apache.tapestry5.services.TapestryModule$2.service(TapestryModule.java:726) at $HttpServletRequestHandler_126227efe04.service($HttpServletRequestHandler_126227efe04.java) at $HttpServletRequestHandler_126227efdff.service($HttpServletRequestHandler_126227efdff.java) at org.apache.tapestry5.TapestryFilter.doFilter(TapestryFilter.java:127) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:112) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447) at java.lang.Thread.run(Unknown Source) Caused by: org.apache.tapestry5.ioc.internal.util.TapestryException: Index: 3, Size: 3 [at classpath:com/titans/surveys/components/surveys/SurveySuggestionsForm.tml, line 5] at org.apache.tapestry5.corelib.components.Form.executeStoredActions(Form.java:495) at org.apache.tapestry5.corelib.components.Form._$advised$onAction(Form.java:378) at org.apache.tapestry5.corelib.components.Form$onAction$invocation_1262280196c.invokeAdvisedMethod(Form$onAction$invocation_1262280196c.java) at org.apache.tapestry5.internal.services.AbstractComponentMethodInvocation.proceed(AbstractComponentMethodInvocation.java:71) at org.apache.tapestry5.ioc.internal.services.LoggingAdvice.advise(LoggingAdvice.java:37) at org.apache.tapestry5.internal.transform.LogWorker$1.advise(LogWorker.java:54) at org.apache.tapestry5.internal.services.AbstractComponentMethodInvocation.proceed(AbstractComponentMethodInvocation.java:80) at org.apache.tapestry5.corelib.components.Form.onAction(Form.java) at org.apache.tapestry5.corelib.components.Form.dispatchComponentEvent(Form.java) at org.apache.tapestry5.internal.structure.ComponentPageElementImpl.dispatchEvent(ComponentPageElementImpl.java:910) at org.apache.tapestry5.internal.structure.ComponentPageElementImpl.triggerContextEvent(ComponentPageElementImpl.java:1081) ... 59 more Caused by: java.lang.IndexOutOfBoundsException: Index: 3, Size: 3 at java.util.ArrayList.RangeCheck(Unknown Source) at java.util.ArrayList.get(Unknown Source) at com.titans.surveys.components.surveys.SurveySuggestionsForm$1.toValue(SurveySuggestionsForm.java:65) at com.titans.surveys.components.surveys.SurveySuggestionsForm$1.toValue(SurveySuggestionsForm.java:1) at org.apache.tapestry5.corelib.components.RadioGroup.processSubmission(RadioGroup.java:167) at org.apache.tapestry5.corelib.components.RadioGroup.access$100(RadioGroup.java:29) at org.apache.tapestry5.corelib.components.RadioGroup$1.execute(RadioGroup.java:137) at org.apache.tapestry5.corelib.components.RadioGroup$1.execute(RadioGroup.java:141) at org.apache.tapestry5.corelib.components.Form.executeStoredActions(Form.java:480) ... 69 more Could someone know what I'm doing wrong ? Maybe a problem with t:id or something like this ? regards, Antoine. antb59 wrote: > > Thanks for you fast answer Christophe ! > > Here is the new code for my radioGroup : > > <t:radiogroup t:id="suggestionRG" value="selectedSuggestion" > encoder="suggestionEncoder"> > <t:loop source="suggestions" value="suggestionLoopValue" > encoder="suggestionEncoder"> > <t:radio t:id="radio" value="suggestionLoopValue"/> > <t:label for="radio">${suggestionLoopValue.label}</t:label> > </t:loop> > </t:radiogroup> > > > It works! > Many thanks. > > > > cordenier christophe wrote: >> >> Oups, it's the radiogroup that need it :) >> >> 2009/12/28 cordenier christophe <christophe.corden...@gmail.com> >> >>> Hi >>> >>> I think you have to specify the encoder on the form element too. >>> >>> 2009/12/28 antb59 <ant...@gmail.com> >>> >>> >>>> Hello, >>>> >>>> I'm trying to make a tapestry component that looks like a poll. >>>> This component will contain a question, a list of suggestions, and a >>>> button >>>> to vote. >>>> I didn't want to use Ajax at first, and the click on the vote button >>>> will >>>> reload the whole page for example. >>>> >>>> The question and the list of suggestions were load from my database, >>>> and I >>>> have no problem to display them correctly on my form. >>>> If no radio button is selected, I can click on the vote button, it >>>> works. >>>> The problem occurs when I'm trying to submit the form and when a radio >>>> button is selected. >>>> >>>> Here is the code of my .tml file : >>>> >>>> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" >>>> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> >>>> <t:container xmlns:t=" >>>> http://tapestry.apache.org/schema/tapestry_5_1_0.xsd" >>>> xmlns:p="tapestry:parameter"> >>>> <t:form t:id="survey_form"> >>>> <h4>${formSurvey.category.label}</h4> >>>> <h5>${formSurvey.startDate}</h5> >>>> <p id="surveyLabel">${formSurvey.label}</p> >>>> >>>> <t:radiogroup t:id="suggestionRG" >>>> value="selectedSuggestion"> >>>> <t:loop source="suggestions" >>>> value="suggestionLoopValue" >>>> encoder="suggestionEncoder"> >>>> <t:radio t:id="radio" >>>> value="suggestionLoopValue"/> >>>> <t:label >>>> for="radio">${suggestionLoopValue.label}</t:label> >>>> </t:loop> >>>> </t:radiogroup> >>>> >>>> <t:submit id="surveyVote" t:id="vote" >>>> image="context:images/vote_button.gif" /> >>>> </t:form> >>>> </t:container> >>>> >>>> >>>> >>>> And here is the code of my java file : >>>> >>>> @SuppressWarnings("unused") >>>> public class Survey { >>>> >>>> @Parameter(required=true) >>>> private int surveyId; >>>> >>>> @Property >>>> @Persist("SESSION") >>>> private com.titans.surveys.model.Survey formSurvey; >>>> >>>> @Inject >>>> private ISurveyManager mSurveyManager; >>>> >>>> @Persist >>>> @Property >>>> private Suggestion selectedSuggestion; >>>> >>>> @Property >>>> private Suggestion suggestionLoopValue; >>>> >>>> @Property >>>> @Persist >>>> private List<Suggestion> suggestions; >>>> >>>> @Property >>>> private ValueEncoder<Suggestion> suggestionEncoder = new >>>> ValueEncoder<Suggestion> () { >>>> public String toClient (Suggestion pSuggestion) { >>>> return (String.valueOf (suggestions.indexOf >>>> (pSuggestion))); >>>> } >>>> public Suggestion toValue (String pId) { >>>> return (suggestions.get (Integer.parseInt >>>> (pId))); >>>> } >>>> }; >>>> >>>> >>>> public void beginRender() { >>>> this.formSurvey = mSurveyManager.findById(surveyId); >>>> if (this.formSurvey == null) { >>>> sLogger.error("Unable to retrieve survey with id >>>> = >>>> " + surveyId); >>>> } >>>> else { >>>> if ((this.suggestions == null) >>>> ||this.suggestions.isEmpty()) >>>> this.suggestions = new >>>> ArrayList<Suggestion>(formSurvey.getSuggestions()); >>>> } >>>> } >>>> >>>> } >>>> >>>> >>>> Here is the ComponentEventException throwed : >>>> >>>> Could not find a coercion from type java.lang.String to type >>>> com.titans.surveys.model.Suggestion. Available coercions: Double --> >>>> Float, >>>> Float --> Double, Long --> Boolean, Long --> Byte, Long --> Double, >>>> Long >>>> --> >>>> Integer, Long --> Short, Number --> Long, Object --> Object[], Object >>>> --> >>>> String, Object --> java.util.List, Object[] --> java.util.List, String >>>> --> >>>> Boolean, String --> Double, String --> Long, String --> java.io.File, >>>> String >>>> --> java.math.BigDecimal, String --> java.math.BigInteger, String --> >>>> java.text.DateFormat, String --> java.util.regex.Pattern, String --> >>>> org.apache.tapestry5.Renderable, String --> >>>> org.apache.tapestry5.SelectModel, String --> >>>> org.apache.tapestry5.corelib.LoopFormState, String --> >>>> org.apache.tapestry5.corelib.data.BlankOption, String --> >>>> org.apache.tapestry5.corelib.data.GridPagerPosition, String --> >>>> org.apache.tapestry5.corelib.data.InsertPosition, String --> >>>> org.apache.tapestry5.ioc.Resource, String --> >>>> org.apache.tapestry5.ioc.util.TimeInterval, boolean[] --> >>>> java.util.List, >>>> byte[] --> java.util.List, char[] --> java.util.List, double[] --> >>>> java.util.List, float[] --> java.util.List, int[] --> java.util.List, >>>> java.math.BigDecimal --> Double, java.util.Collection --> Boolean, >>>> java.util.Collection --> Object[], java.util.Collection --> >>>> org.apache.tapestry5.grid.GridDataSource, java.util.List --> >>>> org.apache.tapestry5.SelectModel, java.util.Map --> >>>> org.apache.tapestry5.SelectModel, long[] --> java.util.List, null --> >>>> Boolean, null --> org.apache.tapestry5.grid.GridDataSource, >>>> org.apache.tapestry5.ComponentResources --> >>>> org.apache.tapestry5.PropertyOverrides, >>>> org.apache.tapestry5.PrimaryKeyEncoder --> >>>> org.apache.tapestry5.ValueEncoder, org.apache.tapestry5.Renderable --> >>>> org.apache.tapestry5.Block, org.apache.tapestry5.Renderable --> >>>> org.apache.tapestry5.runtime.RenderCommand, >>>> org.apache.tapestry5.ioc.util.TimeInterval --> Long, >>>> org.apache.tapestry5.runtime.ComponentResourcesAware --> >>>> org.apache.tapestry5.ComponentResources, short[] --> java.util.List >>>> >>>> >>>> >>>> Could someone know what I'm doing wrong ? >>>> >>>> regards, >>>> Antoine. >>>> -- >>>> View this message in context: >>>> http://old.nabble.com/Loop%2C-RadioGroup-and-Coercion-tp26944581p26944581.html >>>> Sent from the Tapestry - User mailing list archive at Nabble.com. >>>> >>>> >>>> --------------------------------------------------------------------- >>>> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org >>>> For additional commands, e-mail: users-h...@tapestry.apache.org >>>> >>>> >>> >> >> > > -- View this message in context: http://old.nabble.com/Loop%2C-RadioGroup-and-Coercion-tp26944581p27126911.html Sent from the Tapestry - User mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org