webtier@glassfish.java.net

Re: [webtier] Question about Jim Driscoll's Ajax EditText Component Example

From: Jim Driscoll <Jim.Driscoll_at_Sun.COM>
Date: Sat, 07 Feb 2009 20:58:10 -0800

I have an additional question: what's the submitButton call doing on
the same tag as the f:ajax tag? Doesn't the submitButton call also call
jsf.request.ajax? Doesn't that mean you're calling jsf.ajax.request
twice? Does it work if you take that out, or still fail?

Jim

On 2/7/09 8:37 AM, Lincoln Baxter, III wrote:
> I tried to trace the exception but it goes into the
> ViewRoot.processApplication() method, and for some reason I can't
> visually debug through it. Somewhere in that method call is where the
> NPE originates.
>
> Ok, so here's what I'm trying to do in my view:
>
> <a:editText value="#{viewProjectBean.projectGoals}"
> actionListener="#{myBean.listenerSignatureMethod}" />
>
> And here's my component. I've tried various methods of attaching the
> action listener (actionSource, usingPageChildren, etc...) all with the
> same result, the listener is not called. I've tried using a
> valueChangeListener on the inputText field itself (this would be the
> best case scenario I think):
>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
> <html xmlns="http://www.w3.org/1999/xhtml"
> xmlns:h="http://java.sun.com/jsf/html"
> xmlns:f="http://java.sun.com/jsf/core"
> xmlns:ui="http://java.sun.com/jsf/facelets"
> xmlns:composite="http://java.sun.com/jsf/composite">
>
> <composite:interface name="editText"
> displayName="Editable Text Component"
> shortDescription="Editable Text Component">
> <composite:attribute name="actionListener" required="true" />
> <composite:attribute name="value" required="true" type="String" />
> </composite:interface>
>
> <composite:implementation>
> <h:outputScript name="jsf.js" library="javax.faces" target="head" />
> <h:outputScript name="ajax/editText.js" target="head" />
> <h:outputStylesheet name="ajax/editText.css" />
> <script type="text/javascript">
> init("#{compositeComponent.clientId}", "#{compositeComponent.attrs.value}");
> </script>
> <h:panelGroup id="edit1">
> <h:outputLink id="editLink" title="Click to edit"
> styleClass="editLink"
> onclick="return
> linkClick('#{compositeComponent.clientId}');">#{compositeComponent.attrs.value}</h:outputLink>
> </h:panelGroup>
> <h:panelGroup id="edit2" style="display:none;">
> <h:inputText id="editInput" value="#{compositeComponent.attrs.value}"
> styleClass="editInput" />
> <h:commandButton value="Submit" id="submit"
> actionListener="#{compositeComponent.attrs.actionListener}"
> onclick="return submitButton('#{compositeComponent.clientId}', event);">
> <f:ajax execute="submit editInput" render="editLink" />
> </h:commandButton>
> <h:commandButton value="Cancel" id="cancel" styleClass="faded"
> onclick="return cancelButton('#{compositeComponent.clientId}');" />
> </h:panelGroup>
> </composite:implementation>
>
>
>
> *These attempts result in a NPE:*
>
>
> com.ocpsoft.storylib.exceptions.SiteRuntimeException:
> java.lang.NullPointerException
> at
> com.ocpsoft.storylib.jsf.filter.ExceptionFilter.wrapException(ExceptionFilter.java:62)
> at
> com.ocpsoft.storylib.jsf.filter.ExceptionFilter.doFilter(ExceptionFilter.java:47)
> 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:191)
> 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:845)
> 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(Thread.java:619)
> Caused by: java.lang.NullPointerException
> at java.io.Writer.write(Writer.java:140)
> at
> com.sun.faces.context.AjaxExceptionHandlerImpl.handlePartialResponseError(AjaxExceptionHandlerImpl.java:193)
> at
> com.sun.faces.context.AjaxExceptionHandlerImpl.handle(AjaxExceptionHandlerImpl.java:120)
> at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:116)
> at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
> at javax.faces.webapp.FacesServlet.service(FacesServlet.java:310)
> at
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
> at
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
> at
> org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:359)
>
>
> On Thu, 2009-02-05 at 10:54 -0800, webtier_at_javadesktop.org wrote:
>> Hey Jim,
>>
>> Yeah your example works great actually. When I get access to my PC I'll send my examples.
>>
>> The reason I'm adding the actionListener tag is because I want to be able to take an action once the value has been submitted back to the server.
>>
>> Right now I am getting around it by using a field in my Managed bean as an intermediary between editText and the nested object field I wish to update. (object.child.field) So editText triggers the setField(String value) method to be called, which in turn is doing a database update in the setter itself.
>>
>> What I prefer, is to be able to set the value into the object directly, then trigger an action method or actionlistener to be called, which will perform the database update on that object.
>>
>> This workaround fails, however, as soon as I want to use a<ui:repeat> tag to display a list of components, each of which is editable.
>>
>> Is there a simple answer I'm missing?
>>
>> Thanks,
>> Lincoln
>> [Message sent by forum member 'lincolnbaxter' (lincolnbaxter)]
>>
>> http://forums.java.net/jive/thread.jspa?messageID=330360
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail:webtier-unsubscribe_at_glassfish.dev.java.net <mailto:webtier-unsubscribe_at_glassfish.dev.java.net>
>> For additional commands, e-mail:webtier-help_at_glassfish.dev.java.net <mailto:webtier-help_at_glassfish.dev.java.net>
>>