You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Gord Turner <gt...@exchangesolutions.com> on 2008/04/22 21:25:24 UTC

Is calling IValidationDelegate.record() in pageBeginRender a good idea?

I have question about setting an 'error state' prior to landing on a
page.

 

The requirement is that that, under certain conditions, when landing on
the page 

an error message appear and input element highlighted.

 

My attempt was to get the delegate and record an error in
pageBeginRender, as if

the user had already submitted the page and the validation delegate
caught the error.

 

The page has an input element (password) and a delegate (delegate) and I
have removed

the condition so that all pages would render with the error.

 

My original attempt resulted in:

 

"Caused by: java.lang.NullPointerException: Parameter fieldName must not
be null."

 

Which after digging around the source code, I fixed by adding before the
record():

 

"passwordIFormComponent.setName( "password" );"

 

This solution works, sort of, but I can't help but wonder if there is
something I 

am missing?

 

Should I be using another tapestry life cycle 'hook'?

 

We are using Tapestry 4.0.3.

 

Thanks for any suggestions,

Gord Turner.

 

...                              

  public void pageBeginRender( PageEvent event )

  {

    /*

     * Get delegate.

     */

    IValidationDelegate delegate = (IValidationDelegate)
getBeans().getBean(

        "delegate" );

 

    /*

     * Get password form component.

     */

    IFormComponent passwordIFormComponent = (IFormComponent)
getComponent( "password" );

 

    /*

     * Record error.

     */

    //passwordIFormComponent.setName( "password" ); // Uncommenting this
will prevent exception

    delegate.record( passwordIFormComponent,
"MESSAGE_FROM_PAGE_BEGIN_RENDER" );

  }

...

 

 

        at
org.apache.tapestry.ApplicationServlet.doService(ApplicationServlet.java
:123)

        at
org.apache.tapestry.ApplicationServlet.doGet(ApplicationServlet.java:79)

        at javax.servlet.http.HttpServlet.service(HttpServlet.java:115)

        at javax.servlet.http.HttpServlet.service(HttpServlet.java:92)

        at
com.caucho.server.dispatch.ServletFilterChain.doFilter(ServletFilterChai
n.java:99)

        at
net.exchangesolutions.loyalty.ui.session.CallSessionFilter.doFilter(Call
SessionFilter.java:41)

        at
com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.
java:70)

        at
com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.ja
va:163)

        at
com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.j
ava:208)

        at
com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:259)

        at
com.caucho.server.port.TcpConnection.run(TcpConnection.java:363)

        at com.caucho.util.ThreadPool.runTasks(ThreadPool.java:490)

        at com.caucho.util.ThreadPool.run(ThreadPool.java:423)

        at java.lang.Thread.run(Thread.java:595)

Caused by: java.lang.NullPointerException: Parameter fieldName must not
be null.

        at org.apache.hivemind.util.Defense.notNull(Defense.java:41)

        at
org.apache.tapestry.valid.FieldTracking.<init>(FieldTracking.java:59)

        at
org.apache.tapestry.valid.ValidationDelegate.findCurrentTracking(Validat
ionDelegate.java:279)

        at
org.apache.tapestry.valid.ValidationDelegate.record(ValidationDelegate.j
ava:225)

        at
org.apache.tapestry.valid.ValidationDelegate.record(ValidationDelegate.j
ava:207)

        at
org.apache.tapestry.valid.ValidationDelegate.record(ValidationDelegate.j
ava:240)

        at
net.exchangesolutions.loyalty.ui.pages.cssc.CsscLogin.pageBeginRender(Cs
scLogin.java:72)

        at
org.apache.tapestry.AbstractPage.firePageBeginRender(AbstractPage.java:4
78)

        at
org.apache.tapestry.AbstractPage.renderPage(AbstractPage.java:268)

        at
org.apache.tapestry.engine.RequestCycle.renderPage(RequestCycle.java:366
)

        ... 48 more