You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by antb59 <an...@gmail.com> on 2009/12/28 17:04:42 UTC

Loop, RadioGroup and Coercion

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-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Loop, RadioGroup and Coercion

Posted by antb59 <an...@gmail.com>.
Hi again,

In fact, I have a correct behavior for the display of the forms when I used
formState="NONE" in the loop inside form.

But the problem is on the parameter "action" of the form that contains the
loop on suggestions.

Here is the HTML code generated when I fix the surveyId value on the first
Loop :

<form id="survey_form_5" name="survey_form_5" method="post"
action="index.surveysuggestionsform_0.survey_form"
onsubmit="javascript:Tapestry.waitForPage(event);">


Here is the HTML code generated when I iterate on surveys :

<form id="survey_form_4" name="survey_form_4" method="post"
action="index.surveysuggestionsform.survey_form"
onsubmit="javascript:Tapestry.waitForPage(event);">
</form>


The problem seems to be on "index.surveysuggestionsform.survey_form"

Which modification I have to do in order to have dynamic "action" parameters
for the loop of forms ?

I want the "action" parameter to be 
"index.surveysuggestionsform_0.survey_form"
"index.surveysuggestionsform_1.survey_form"
"index.surveysuggestionsform_2.survey_form"

when I use the component in the following loop :

<t:loop source="surveys" value="surveyLoopValue" encoder="surveyEncoder">
  	<t:surveys.surveySuggestionsForm surveyId="surveyLoopValue.id" />
</t:loop>


Regards,
Antoine.
-- 
View this message in context: http://old.nabble.com/Loop%2C-RadioGroup-and-Coercion-tp26944581p27147181.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: Loop, RadioGroup and Coercion

Posted by antb59 <an...@gmail.com>.
After reading the documentation for LoopFormState, I found that ITERATION is
the value I want in my case.

"When the Form is submitted, the Loop will re-acquire its source and iterate
over it"

But when I used this value in my loop component, an new error is throwed :

# java.util.AbstractList$Itr.next(AbstractList.java:350)
#
org.apache.tapestry5.corelib.components.Loop.advanceVolatile(Loop.java:363)
# org.apache.tapestry5.corelib.components.Loop.access$200(Loop.java:44)
# org.apache.tapestry5.corelib.components.Loop$3.execute(Loop.java:95)
# org.apache.tapestry5.corelib.components.Loop$3.execute(Loop.java:99)
#
org.apache.tapestry5.corelib.components.Form.executeStoredActions(Form.java:480)
#
org.apache.tapestry5.corelib.components.Form._$advised$onAction(Form.java:378)
#
org.apache.tapestry5.corelib.components.Form$onAction$invocation_126248d3e0b.invokeAdvisedMethod(Form$onAction$invocation_126248d3e0b.java)
#
org.apache.tapestry5.internal.services.AbstractComponentMethodInvocation.proceed(AbstractComponentMethodInvocation.java:71)
#
org.apache.tapestry5.ioc.internal.services.LoggingAdvice.advise(LoggingAdvice.java:37)
#
org.apache.tapestry5.internal.transform.LogWorker$1.advise(LogWorker.java:54)
#
org.apache.tapestry5.internal.services.AbstractComponentMethodInvocation.proceed(AbstractComponentMethodInvocation.java:80)
# org.apache.tapestry5.corelib.components.Form.onAction(Form.java)
#
org.apache.tapestry5.corelib.components.Form.dispatchComponentEvent(Form.java)
#
org.apache.tapestry5.internal.structure.ComponentPageElementImpl.dispatchEvent(ComponentPageElementImpl.java:910)
#
org.apache.tapestry5.internal.structure.ComponentPageElementImpl.triggerContextEvent(ComponentPageElementImpl.java:1081)
#
org.apache.tapestry5.internal.services.ComponentEventRequestHandlerImpl.handle(ComponentEventRequestHandlerImpl.java:75)
#
org.apache.tapestry5.internal.services.ImmediateActionRenderResponseFilter.handle(ImmediateActionRenderResponseFilter.java:42)
#
$ComponentEventRequestHandler_126248d2fe8.handle($ComponentEventRequestHandler_126248d2fe8.java)
#
org.apache.tapestry5.internal.services.AjaxFilter.handle(AjaxFilter.java:42)
#
$ComponentEventRequestHandler_126248d2fe8.handle($ComponentEventRequestHandler_126248d2fe8.java)
#
org.apache.tapestry5.services.TapestryModule$36.handle(TapestryModule.java:2164)
#
$ComponentEventRequestHandler_126248d2fe8.handle($ComponentEventRequestHandler_126248d2fe8.java)
#
$ComponentEventRequestHandler_126248d2f4e.handle($ComponentEventRequestHandler_126248d2f4e.java)
#
org.apache.tapestry5.internal.services.ComponentRequestHandlerTerminator.handleComponentEvent(ComponentRequestHandlerTerminator.java:43)
#
com.titans.surveys.services.access.AccessComponentRequestFilter.handleComponentEvent(AccessComponentRequestFilter.java:32)
#
$ComponentRequestHandler_126248d2f4f.handleComponentEvent($ComponentRequestHandler_126248d2f4f.java)
#
$ComponentRequestHandler_126248d2f41.handleComponentEvent($ComponentRequestHandler_126248d2f41.java)
#
org.apache.tapestry5.internal.services.ComponentEventDispatcher.dispatch(ComponentEventDispatcher.java:46)
# $Dispatcher_126248d2f43.dispatch($Dispatcher_126248d2f43.java)
# $Dispatcher_126248d2f3a.dispatch($Dispatcher_126248d2f3a.java)
#
org.apache.tapestry5.services.TapestryModule$RequestHandlerTerminator.service(TapestryModule.java:245)
# com.titans.surveys.services.AppModule$1.service(AppModule.java:100)
# $RequestFilter_126248d2f39.service($RequestFilter_126248d2f39.java)
# $RequestHandler_126248d2f3b.service($RequestHandler_126248d2f3b.java)
#
org.apache.tapestry5.internal.services.RequestErrorFilter.service(RequestErrorFilter.java:26)
# $RequestHandler_126248d2f3b.service($RequestHandler_126248d2f3b.java)
#
org.apache.tapestry5.services.TapestryModule$4.service(TapestryModule.java:778)
# $RequestHandler_126248d2f3b.service($RequestHandler_126248d2f3b.java)
#
org.apache.tapestry5.services.TapestryModule$3.service(TapestryModule.java:767)
# $RequestHandler_126248d2f3b.service($RequestHandler_126248d2f3b.java)
#
org.apache.tapestry5.internal.services.StaticFilesFilter.service(StaticFilesFilter.java:85)
# $RequestHandler_126248d2f3b.service($RequestHandler_126248d2f3b.java)
#
org.apache.tapestry5.internal.services.CheckForUpdatesFilter$2.invoke(CheckForUpdatesFilter.java:90)
#
org.apache.tapestry5.internal.services.CheckForUpdatesFilter$2.invoke(CheckForUpdatesFilter.java:81)
#
org.apache.tapestry5.ioc.internal.util.ConcurrentBarrier.withRead(ConcurrentBarrier.java:85)
#
org.apache.tapestry5.internal.services.CheckForUpdatesFilter.service(CheckForUpdatesFilter.java:103)
# $RequestHandler_126248d2f3b.service($RequestHandler_126248d2f3b.java)
# $RequestHandler_126248d2f30.service($RequestHandler_126248d2f30.java)
#
org.apache.tapestry5.services.TapestryModule$HttpServletRequestHandlerTerminator.service(TapestryModule.java:197)
# org.apache.tapestry5.internal.gzip.GZipFilter.service(GZipFilter.java:53)
#
$HttpServletRequestHandler_126248d2f32.service($HttpServletRequestHandler_126248d2f32.java)
#
org.apache.tapestry5.internal.services.IgnoredPathsFilter.service(IgnoredPathsFilter.java:62)
#
$HttpServletRequestFilter_126248d2f2f.service($HttpServletRequestFilter_126248d2f2f.java)
#
$HttpServletRequestHandler_126248d2f32.service($HttpServletRequestHandler_126248d2f32.java)
#
org.apache.tapestry5.services.TapestryModule$2.service(TapestryModule.java:726)
#
$HttpServletRequestHandler_126248d2f32.service($HttpServletRequestHandler_126248d2f32.java)
#
$HttpServletRequestHandler_126248d2f2d.service($HttpServletRequestHandler_126248d2f2d.java)
# org.apache.tapestry5.TapestryFilter.doFilter(TapestryFilter.java:127) 

Here is the code of my Survey.tml

  <t:form t:id="survey_form">
    <t:radiogroup t:id="suggestionRG" value="selectedSuggestion"
encoder="suggestionEncoder">
    <t:loop source="suggestions" value="suggestionLoopValue"
formState="literal:ITERATION" 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>


This component was included into SuperComponent :

<t:loop source="surveys" value="surveyLoopValue" encoder="surveyEncoder">
  <t:surveys.survey surveyId="surveyLoopValue.id" />
</t:loop>


Am I missing something ???


Regards,
Antoine.


Thiago H. de Paula Figueiredo wrote:
> 
> On Tue, 12 Jan 2010 11:18:03 -0200, antb59 <an...@gmail.com> wrote:
> 
>> When you say "never use expansions in
>> component parameters", you mean this syntax
>> <t:surveys.surveySuggestionsForm  surveyId="surveyLoopValue.id" />
>> is better ?
> 
> Yes, because everytime you use an expansion to value is transformed in a  
> String.
> 
>> About the LoopFormState, I'm going to check this feature, I didn't know
>> it...
>> Do I have to change the LoopFormState of the loop of forms or the loop of
>> radio buttons ?
> 
> The ones inside Forms, I guess.
> 
> -- 
> Thiago H. de Paula Figueiredo
> Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
> and instructor
> Owner, software architect and developer, Ars Machina Tecnologia da  
> Informação Ltda.
> http://www.arsmachina.com.br
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 
> 

-- 
View this message in context: http://old.nabble.com/Loop%2C-RadioGroup-and-Coercion-tp26944581p27135715.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: Loop, RadioGroup and Coercion

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Tue, 12 Jan 2010 11:18:03 -0200, antb59 <an...@gmail.com> wrote:

> When you say "never use expansions in
> component parameters", you mean this syntax
> <t:surveys.surveySuggestionsForm  surveyId="surveyLoopValue.id" />
> is better ?

Yes, because everytime you use an expansion to value is transformed in a  
String.

> About the LoopFormState, I'm going to check this feature, I didn't know
> it...
> Do I have to change the LoopFormState of the loop of forms or the loop of
> radio buttons ?

The ones inside Forms, I guess.

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, software architect and developer, Ars Machina Tecnologia da  
Informação Ltda.
http://www.arsmachina.com.br

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


Re: Loop, RadioGroup and Coercion

Posted by antb59 <an...@gmail.com>.
Thanks for your fast answer !

When you say "never use expansions in  
component parameters", you mean this syntax 
<t:surveys.surveySuggestionsForm  surveyId="surveyLoopValue.id" /> 
is better ?


About the LoopFormState, I'm going to check this feature, I didn't know
it...
Do I have to change the LoopFormState of the loop of forms or the loop of
radio buttons ?

regards,
Antoine.


Thiago H. de Paula Figueiredo wrote:
> 
> On Tue, 12 Jan 2010 10:33:11 -0200, antb59 <an...@gmail.com> wrote:
> 
>> Hello again,
> 
> Hi again! :)
> 
>> <t:loop source="surveys" value="surveyLoopValue" encoder="surveyEncoder">
>>   <t:surveys.surveySuggestionsForm  surveyId="${surveyLoopValue.id}" />
>> </t:loop>
> 
> It probably isn't the source of your problem, but never use expansions in  
> component parameters.
> 
>> 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 :
> 
> Try using some value of Loop's formState parameter.
> 
> -- 
> Thiago H. de Paula Figueiredo
> Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
> and instructor
> Owner, software architect and developer, Ars Machina Tecnologia da  
> Informação Ltda.
> http://www.arsmachina.com.br
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 
> 

-- 
View this message in context: http://old.nabble.com/Loop%2C-RadioGroup-and-Coercion-tp26944581p27127401.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: Loop, RadioGroup and Coercion

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Tue, 12 Jan 2010 10:33:11 -0200, antb59 <an...@gmail.com> wrote:

> Hello again,

Hi again! :)

> <t:loop source="surveys" value="surveyLoopValue" encoder="surveyEncoder">
>   <t:surveys.surveySuggestionsForm  surveyId="${surveyLoopValue.id}" />
> </t:loop>

It probably isn't the source of your problem, but never use expansions in  
component parameters.

> 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 :

Try using some value of Loop's formState parameter.

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, software architect and developer, Ars Machina Tecnologia da  
Informação Ltda.
http://www.arsmachina.com.br

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


Re: Loop, RadioGroup and Coercion

Posted by antb59 <an...@gmail.com>.
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 <ch...@gmail.com>
>> 
>>> Hi
>>>
>>> I think you have to specify the encoder on the form element too.
>>>
>>> 2009/12/28 antb59 <an...@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-unsubscribe@tapestry.apache.org
>>>> For additional commands, e-mail: users-help@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-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Loop, RadioGroup and Coercion

Posted by antb59 <an...@gmail.com>.
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 <ch...@gmail.com>
> 
>> Hi
>>
>> I think you have to specify the encoder on the form element too.
>>
>> 2009/12/28 antb59 <an...@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-unsubscribe@tapestry.apache.org
>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>
>>>
>>
> 
> 

-- 
View this message in context: http://old.nabble.com/Loop%2C-RadioGroup-and-Coercion-tp26944581p26944825.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: Loop, RadioGroup and Coercion

Posted by cordenier christophe <ch...@gmail.com>.
Oups, it's the radiogroup that need it :)

2009/12/28 cordenier christophe <ch...@gmail.com>

> Hi
>
> I think you have to specify the encoder on the form element too.
>
> 2009/12/28 antb59 <an...@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-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>

Re: Loop, RadioGroup and Coercion

Posted by cordenier christophe <ch...@gmail.com>.
Hi

I think you have to specify the encoder on the form element too.

2009/12/28 antb59 <an...@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-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>