Parameters are not JavaBeans properties; they are read/write and "lazy" as you have now realized. They also do some caching.
Oh, and by the way, you can simplify your component a lot: <td>ticket?.ticketNumber</td> The ?. operator encapsulates the null check you were doing in Java code. Check out the Tapestry 5.0 refcard! On Tue, Mar 3, 2009 at 1:41 PM, Simon Raveh <simon.ra...@icann.org> wrote: > I figure out what was happening. I think tapestry is doing a lasy bind for > parameters and only getting them when thay bean access in the component. The > null pointer I've got was related to my internal domain object. > > Sorry for the confusion. > > Thanks, > Simon > > > On 3/2/09 9:45 PM, "Simon Raveh" <simon.ra...@icann.org> wrote: > > Yes but this is in the component template and it is being called before > tapestry is binding the parameter to the component. If you look at stack > trace you will see that the call to getTicketNumber() on the component is > coming before tapestry is calling getTicket() on the page object to get the > parameter that need to be pass to the component > > [DEBUG] components.ViewTicket [ENTER] beforeRenderTamplate > [DEBUG] components.ViewTicket [ EXIT] beforeRenderTamplate > [DEBUG] components.ViewTicket [ENTER] getTicketNumber() > [DEBUG] pages.Index [ENTER] getTicket() > [DEBUG] pages.Index [ EXIT] getTicket > > My dev environment is: > > Mac book pro with Intellij IDEA 8.1 and Apache Tomcat Version 6.0.10 JDK > 1.5_07. I'm running the project using maven 2.0.10 > > Thanks, > Simon > > > On 3/2/09 6:32 PM, "Howard Lewis Ship" <hls...@gmail.com> wrote: > >> I'm not sure what the confusion is: >> >> <td>${ticketNumber}</td> >> >> That's your call to getTicketNumber(). >> >> On Mon, Mar 2, 2009 at 6:04 PM, Alex Kotchnev <akoch...@gmail.com> wrote: >>> Simon, >>> I still can't figure out your dilemma, but I notice something >>> interesting.. In the stacktrace that you provided, it looks like this time >>> getStatus() is being called before getTicket.. >>> >>> Maybe some of the folks that are more familiar w/ the guts of T5 can look >>> at this. It doesn't look like this is due to anything you're doing, looks >>> like a race condition of some type. >>> >>> I think it would be helpful if you provide some more details on the >>> environment that you run your app in : e.g. JVM version, app server . Btw, >>> does this happen consistently if you run it on a different box (e.g. I've >>> had non-tapestry related stuff sometimes behave differently in terms of >>> threading on a single CPU vs dual core box) ? Maybe you can try different >>> JVMs as well, just to check that this is not JVM or version specific. >>> >>> Cheers, >>> >>> Alex kotchnev >>> >>> On Mon, Mar 2, 2009 at 4:23 PM, Simon Raveh <simon.ra...@icann.org> wrote: >>> >>>> Hi, >>>> >>>> Thanks for your help. >>>> I'm still trying to figure out why getTicketNumber() is being called before >>>> the parameter was set. From debugging this it seems that it is being called >>>> when the Index page is being render. Bellow you can find a thread dump: >>>> >>>> [INFO] Started Jetty Server >>>> 2009-03-02 13:09:48.951::INFO: Started >>>> selectchannelconnec...@0.0.0.0:8080 >>>> [DEBUG] components.ViewTicket [ENTER] beforeRenderTamplate() >>>> [DEBUG] components.ViewTicket [ EXIT] beforeRenderTamplate >>>> java.lang.Exception: Stack trace >>>> at java.lang.Thread.dumpStack(Thread.java:1224) >>>> at >>>> org.iana.ietf.ticketstatus.components.ViewTicket._$advised$getStatus(ViewTic >>>> ket.java:36) >>>> [DEBUG] components.ViewTicket [ENTER] getStatus() >>>> at >>>> org.iana.ietf.ticketstatus.components.ViewTicket$getStatus$invocation_11fc90 >>>> 9007b.invokeAdvisedMethod(ViewTicket$getStatus$invocation_11fc909007b.java) >>>> at >>>> org.apache.tapestry5.internal.services.AbstractComponentMethodInvocation.pro >>>> ceed(AbstractComponentMethodInvocation.java:71) >>>> at >>>> org.apache.tapestry5.ioc.internal.services.LoggingAdvice.advise(LoggingAdvic >>>> e.java:45) >>>> at >>>> > org.apache.tapestry5.internal.transform.LogWorker$1.advise(LogWorker.java:54>>> > ) >>>> at >>>> org.apache.tapestry5.internal.services.AbstractComponentMethodInvocation.pro >>>> ceed(AbstractComponentMethodInvocation.java:80) >>>> at >>>> org.iana.ietf.ticketstatus.components.ViewTicket.getStatus(ViewTicket.java) >>>> at $PropertyConduit_11fc9056327.get($PropertyConduit_11fc9056327.java) >>>> at >>>> org.apache.tapestry5.internal.bindings.PropBinding.get(PropBinding.java:53) >>>> at >>>> org.apache.tapestry5.internal.structure.ExpansionPageElement.render(Expansio >>>> nPageElement.java:47) >>>> at >>>> org.apache.tapestry5.internal.services.RenderQueueImpl.run(RenderQueueImpl.j >>>> ava:72) >>>> at >>>> org.apache.tapestry5.internal.services.PageRenderQueueImpl.render(PageRender >>>> QueueImpl.java:121) >>>> at >>>> $PageRenderQueue_11fc9056337.render($PageRenderQueue_11fc9056337.java) >>>> at >>>> $PageRenderQueue_11fc905632f.render($PageRenderQueue_11fc905632f.java) >>>> at >>>> org.apache.tapestry5.services.TapestryModule$19.renderMarkup(TapestryModule. >>>> java:1200) >>>> at >>>> org.apache.tapestry5.services.TapestryModule$29.renderMarkup(TapestryModule. >>>> java:1580) >>>> at >>>> $MarkupRenderer_11fc905633b.renderMarkup($MarkupRenderer_11fc905633b.java) >>>> at >>>> org.apache.tapestry5.services.TapestryModule$28.renderMarkup(TapestryModule. >>>> java:1561) >>>> at >>>> $MarkupRenderer_11fc905633b.renderMarkup($MarkupRenderer_11fc905633b.java) >>>> at >>>> org.apache.tapestry5.services.TapestryModule$27.renderMarkup(TapestryModule. >>>> java:1543) >>>> at >>>> $MarkupRenderer_11fc905633b.renderMarkup($MarkupRenderer_11fc905633b.java) >>>> at >>>> org.apache.tapestry5.services.TapestryModule$26.renderMarkup(TapestryModule. >>>> java:1525) >>>> at >>>> $MarkupRenderer_11fc905633b.renderMarkup($MarkupRenderer_11fc905633b.java) >>>> at >>>> org.apache.tapestry5.services.TapestryModule$25.renderMarkup(TapestryModule. >>>> java:1495) >>>> at >>>> $MarkupRenderer_11fc905633b.renderMarkup($MarkupRenderer_11fc905633b.java) >>>> at >>>> $MarkupRenderer_11fc9056335.renderMarkup($MarkupRenderer_11fc9056335.java) >>>> at >>>> org.apache.tapestry5.internal.services.PageMarkupRendererImpl.renderPageMark >>>> up(PageMarkupRendererImpl.java:64) >>>> at >>>> $PageMarkupRenderer_11fc9056333.renderPageMarkup($PageMarkupRenderer_11fc905 >>>> 6333.java) >>>> at >>>> org.apache.tapestry5.internal.services.PageResponseRendererImpl.renderPageRe >>>> sponse(PageResponseRendererImpl.java:57) >>>> at >>>> $PageResponseRenderer_11fc90562f0.renderPageResponse($PageResponseRenderer_1 >>>> 1fc90562f0.java) >>>> at >>>> org.apache.tapestry5.internal.services.PageRenderRequestHandlerImpl.handle(P >>>> ageRenderRequestHandlerImpl.java:59) >>>> at >>>> org.apache.tapestry5.services.TapestryModule$35.handle(TapestryModule.java:1 >>>> 779) >>>> at >>>> $PageRenderRequestHandler_11fc90562f1.handle($PageRenderRequestHandler_11fc9 >>>> 0562f1.java) >>>> at >>>> $PageRenderRequestHandler_11fc90562e4.handle($PageRenderRequestHandler_11fc9 >>>> 0562e4.java) >>>> at >>>> org.apache.tapestry5.internal.services.PageRenderDispatcher.process(PageRend >>>> erDispatcher.java:92) >>>> at >>>> org.apache.tapestry5.internal.services.PageRenderDispatcher.dispatch(PageRen >>>> derDispatcher.java:81) >>>> at $Dispatcher_11fc90562ea.dispatch($Dispatcher_11fc90562ea.java) >>>> at $Dispatcher_11fc90562dd.dispatch($Dispatcher_11fc90562dd.java) >>>> at >>>> org.apache.tapestry5.services.TapestryModule$17.service(TapestryModule.java: >>>> 1029) >>>> at >>>> org.iana.ietf.ticketstatus.services.AppModule$1.service(AppModule.java:77) >>>> at $RequestFilter_11fc90562dc.service($RequestFilter_11fc90562dc.java) >>>> at $RequestHandler_11fc90562de.service($RequestHandler_11fc90562de.java) >>>> at >>>> org.apache.tapestry5.internal.services.LocalizationFilter.service(Localizati >>>> onFilter.java:42) >>>> at $RequestHandler_11fc90562de.service($RequestHandler_11fc90562de.java) >>>> at >>>> org.apache.tapestry5.internal.services.RequestErrorFilter.service(RequestErr >>>> orFilter.java:26) >>>> at $RequestHandler_11fc90562de.service($RequestHandler_11fc90562de.java) >>>> at >>>> org.apache.tapestry5.services.TapestryModule$3.service(TapestryModule.java:6 >>>> 21) >>>> at $RequestHandler_11fc90562de.service($RequestHandler_11fc90562de.java) >>>> at >>>> org.apache.tapestry5.services.TapestryModule$2.service(TapestryModule.java:6 >>>> 11) >>>> at $RequestHandler_11fc90562de.service($RequestHandler_11fc90562de.java) >>>> at >>>> org.apache.tapestry5.internal.services.StaticFilesFilter.service(StaticFiles >>>> Filter.java:85) >>>> at $RequestHandler_11fc90562de.service($RequestHandler_11fc90562de.java) >>>> at >>>> org.apache.tapestry5.internal.services.CheckForUpdatesFilter$2.invoke(CheckF >>>> orUpdatesFilter.java:93) >>>> at >>>> org.apache.tapestry5.internal.services.CheckForUpdatesFilter$2.invoke(CheckF >>>> orUpdatesFilter.java:84) >>>> at >>>> org.apache.tapestry5.ioc.internal.util.ConcurrentBarrier.withRead(Concurrent >>>> Barrier.java:83) >>>> at >>>> org.apache.tapestry5.internal.services.CheckForUpdatesFilter.service(CheckFo >>>> rUpdatesFilter.java:106) >>>> at $RequestHandler_11fc90562de.service($RequestHandler_11fc90562de.java) >>>> at $RequestHandler_11fc90562d4.service($RequestHandler_11fc90562d4.java) >>>> at >>>> org.apache.tapestry5.services.TapestryModule$16.service(TapestryModule.java: >>>> 1007) >>>> at >>>> org.apache.tapestry5.internal.services.IgnoredPathsFilter.service(IgnoredPat >>>> hsFilter.java:62) >>>> at >>>> $HttpServletRequestFilter_11fc90562d3.service($HttpServletRequestFilter_11fc >>>> 90562d3.java) >>>> at >>>> $HttpServletRequestHandler_11fc90562d5.service($HttpServletRequestHandler_11 >>>> fc90562d5.java) >>>> at >>>> $HttpServletRequestHandler_11fc90562d2.service($HttpServletRequestHandler_11 >>>> fc90562d2.java) >>>> at org.apache.tapestry5.TapestryFilter.doFilter(TapestryFilter.java:179) >>>> at >>>> org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler >>>> .java:1084) >>>> at >>>> org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:360) >>>> at >>>> org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216) >>>> at >>>> org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181) >>>> at >>>> org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:726) >>>> at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405) >>>> [DEBUG] pages.Index [ENTER] getTicket() >>>> at >>>> org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerColl >>>> ection.java:206) >>>> at >>>> org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:11 >>>> 4) >>>> at >>>> org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152) >>>> at org.mortbay.jetty.Server.handle(Server.java:324) >>>> at >>>> org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505) >>>> at >>>> org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnectio >>>> n.java:828) >>>> at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:514) >>>> at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211) >>>> at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380) >>>> at >>>> org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395) >>>> at >>>> org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:4 >>>> 50) >>>> [DEBUG] pages.Index [ EXIT] getTicket >>>> [org.iana.ietf.ticketstatus.moodel.rtticketi...@2b60063] >>>> [DEBUG] components.ViewTicket [ EXIT] getStatus [null] >>>> [INFO] AppModule.TimingFilter Request time: 1832 ms >>>> >>>> >>>> >>>> >>>> On 3/1/09 4:44 AM, "Alex Kotchnev" <akoch...@gmail.com> wrote: >>>> >>>> Simon, >>>> I'm not entirely sure why the getTicketNumber() gets called before the >>>> ticket gets set, maybe you can put in a break point in the method and look >>>> at the stack trace and see what's calling it. Just looking at it like this, >>>> I have no explanation why it's being called. >>>> >>>> On your question of not rendering the component based on its state : it >>>> seems that it depends on how you want to do it. If this 'don't render >>>> empty' >>>> behavior is expected to be a part of the ViewTicket component, you can >>>> always use a t:if to inspect the state of the ticket in the component >>>> template render nothing if the ticket is in a state that shouldn't be >>>> rendered. It seems that the best approach there would be to have 2 blocks : >>>> one for empty ticket, one for "displayable" ticket, and then use a t:if to >>>> select which block to render, e.g. >>>> >>>> <div id='content'> >>>> <t:delegate to='contentBlock' /> >>>> </div> >>>> >>>> <t:block t:id="fullContent"> .... </t:block> >>>> <t:block t:id="emptyBlock"> ...</t:block> >>>> >>>> >>>> ... and then in the component class ... >>>> >>>> @Component >>>> Block fullContent >>>> @Component >>>> Block emptyBlock >>>> >>>> public Block getContentBlock() { >>>> if (this.ticket.foo='bar') { >>>> return emptyBlock; >>>> } else { >>>> fullContent; >>>> } >>>> } >>>> >>>> Something like that.. I haven't tested the exact code above, but I have a >>>> few similar examples. I think JumpStart ( >>>> http://jumpstart.doublenegative.com.au:8080/jumpstart/) has some examples >>>> to >>>> illustrate this but I don't have the exact URL for that. >>>> >>>> Cheers, >>>> >>>> Alex Kotchnev >>>> >>>> On Sun, Mar 1, 2009 at 12:09 AM, Simon Raveh <simon.ra...@icann.org> >>>> wrote: >>>> >>>>> Hi, >>>>> >>>>> I'm switching from Tapestry 4 to to Tapestry 5 and I need help with a >>>>> simple component. >>>>> I have a component ViewTicket that display Ticket information. The tml >>>> file >>>>> code: >>>>> >>>>> <t:container xmlns:t=" >>>> http://tapestry.apache.org/schema/tapestry_5_0_0.xsd >>>>> "> >>>>> <div style="display: block;" id="output"> >>>>> <div id="assessment_panel"> >>>>> <div class="safe" id="box_assessment"> >>>>> <h2>Ticket Information</h2> >>>>> </div> >>>>> </div> >>>>> <div id="results_panel"> >>>>> <table id="ns_table"> >>>>> <tbody> >>>>> <tr> >>>>> <th>Ticket ID</th> >>>>> <th>Status</th> >>>>> <th>Queue</th> >>>>> <th>Created</th> >>>>> </tr> >>>>> <tr> >>>>> <td>${ticketNumber}</td> >>>>> <td>${status}</td> >>>>> <td>${queue}</td> >>>>> <td>${created}</td> >>>>> </tr> >>>>> </tbody> >>>>> </table> >>>>> </div> >>>>> </div> >>>>> </t:container> >>>>> >>>>> And the java code >>>>> >>>>> public class ViewTicket implements TicketViewer { >>>>> >>>>> �...@inject >>>>> private Logger logger; >>>>> >>>>> �...@parameter(required = true) >>>>> private RTTicket ticket; >>>>> >>>>> �...@log >>>>> �...@beforerendertemplate >>>>> void beforeRenderTamplate(){ >>>>> } >>>>> >>>>> �...@log >>>>> public Long getTicketNumber() { >>>>> return ticket == null ? null : ticket.getId(); >>>>> } >>>>> >>>>> �...@log >>>>> public String getQueue() { >>>>> return ticket == null ? null :ticket.getQueue(); >>>>> } >>>>> >>>>> �...@log >>>>> public String getStatus() { >>>>> return ticket == null ? null :ticket.getStatus(); >>>>> } >>>>> >>>>> �...@log >>>>> public Date getCreated() { >>>>> return ticket == null ? null : ticket.getCreated(); >>>>> } >>>>> >>>>> public void addTicket(RTTicket ticket) { >>>>> this.ticket = ticket; >>>>> } >>>>> >>>>> public void clearTicket() { >>>>> this.ticket = new RTTicketImpl(); >>>>> } >>>>> } >>>>> And my page Index.tml >>>>> >>>>> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" " >>>>> http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> >>>>> <html t:type="layout" xmlns:t=" >>>>> http://tapestry.apache.org/schema/tapestry_5_0_0.xsd"> >>>>> <body> >>>>> <h1>Request (Ticket) Information</h1> >>>>> <p>To check the status of your request, please enter the ticket >>>>> number (numerical value only) below: </p> >>>>> <form t:type="form" t:id="search_form" action="#"> >>>>> <t:errors/> >>>>> Ticket ID: >>>>> <input t:type="TextField" t:id="ticketId" >>>>> t:clientId="id_query" validate="required"/> >>>>> <input type="submit" value="Submit Query" >>>>> id="form-submit-button"/> >>>>> </form> >>>>> <span t:type="ViewTicket" t:ticket="prop:ticket" /> >>>>> </body> >>>>> </html> >>>>> >>>>> Index.java >>>>> >>>>> public class Index { >>>>> >>>>> �...@inject >>>>> private Logger logger; >>>>> >>>>> �...@property >>>>> private long ticketId; >>>>> >>>>> void onValidateForm() { >>>>> >>>>> } >>>>> >>>>> void onSuccess() { >>>>> } >>>>> >>>>> �...@log >>>>> public RTTicket getTicket() { >>>>> return new RTTicketImpl(); >>>>> } >>>>> } >>>>> >>>>> My problem is that Tapestry is calling the method getTicketNumber before >>>>> the Ticket parameter is bound. >>>>> Here are the logging output: >>>>> >>>>> [DEBUG] components.ViewTicket [ENTER] beforeRenderTamplate() >>>>> [DEBUG] components.ViewTicket [ EXIT] beforeRenderTamplate >>>>> [DEBUG] components.ViewTicket [ENTER] getTicketNumber() >>>>> [DEBUG] pages.Index [ENTER] getTicket() >>>>> [DEBUG] pages.Index [ EXIT] getTicket >>>>> [org.iana.ietf.ticketstatus.moodel.rtticketi...@3805fd37] >>>>> [DEBUG] components.ViewTicket [ EXIT] getTicketNumber [null] >>>>> [DEBUG] components.ViewTicket [ENTER] getStatus() >>>>> [DEBUG] components.ViewTicket [ EXIT] getStatus [null] >>>>> [DEBUG] components.ViewTicket [ENTER] getQueue() >>>>> [DEBUG] components.ViewTicket [ EXIT] getQueue [null] >>>>> [DEBUG] components.ViewTicket [ENTER] getCreated() >>>>> [DEBUG] components.ViewTicket [ EXIT] getCreated [null] >>>>> >>>>> Any clue to what I'm doing wrong or help will be much appreciate >>>>> >>>>> My second question is what the best way to cause the component ViewTicket >>>>> not to render base on the state of the ticket it gets as parameter >>>>> >>>>> Thanks, >>>>> Simon >>>>> >>>> >>>> >>> >> >> >> >> -- >> Howard M. Lewis Ship >> >> Creator Apache Tapestry and Apache HiveMind >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org >> For additional commands, e-mail: users-h...@tapestry.apache.org >> >> > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org > For additional commands, e-mail: users-h...@tapestry.apache.org > > > -- Howard M. Lewis Ship Creator Apache Tapestry and Apache HiveMind --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org