Hi Markus,
On Mar 25, 2011, at 3:41 AM, Markus Ruggiero wrote:
> I have an EO that has business logic for creating an PDF file. There is a
> WOComponent that generates an XML which is then fed to ApacheFOP. Following
> code is in the EO:
>
> GeneratedDocument.java
>
> public void generatePDF(WOComponent sender) {
> if (sender == null) {
> return;
> }
>
> String generatorName = xmlGeneratorClassName();
> if (generatorName != null) {
> XmlGeneratorComponent xmlGenerator =
> (XmlGeneratorComponent)sender.pageWithName(generatorName);
That might be a problem there. Try this instead:
XmlGeneratorComponent xmlGenerator =
(XmlGeneratorComponent)WOApplication.application().pageWithName(generatorName,
new WOContent(sender.context().request()));
It is usually safer to create a new context for things like this.
Chuck
> PDFGenerator pdfGenerator =
> PDFGenerator.sharedInstance();
> pdfGenerator.generatePdfFile( this, xmlGenerator );
> }
> else {
> log.error( "*** No xmlGeneratorClassName available" );
> }
> }
>
>
> Depending on the context I call this I get a NullPointerException or not.
> This is the NPE, context info follows below:
>
> Mar 25 11:13:49 ec_admin[13000] WARN NSLog -
> <com.webobjects.appserver._private.WOComponentRequestHandler>: Exception
> occurred while handling request:
> java.lang.NullPointerException
> [2011-3-25 11:13:49 CET] <WorkerThread14> java.lang.NullPointerException
> at
> com.webobjects.appserver._private.WOComponentReference._popComponentFromContext(WOComponentReference.java:108)
> at
> com.webobjects.appserver._private.WOComponentReference.invokeAction(WOComponentReference.java:128)
> at
> er.extensions.components._private.ERXSwitchComponent.invokeAction(ERXSwitchComponent.java:117)
> at
> com.webobjects.appserver._private.WODynamicGroup.invokeChildrenAction(WODynamicGroup.java:105)
> at
> com.webobjects.appserver._private.WODynamicGroup.invokeAction(WODynamicGroup.java:115)
> at
> er.extensions.components._private.ERXWORepetition.invokeAction(ERXWORepetition.java:496)
> at
> com.webobjects.appserver._private.WODynamicGroup.invokeChildrenAction(WODynamicGroup.java:105)
> at
> er.extensions.components.conditionals.ERXWOConditional.invokeChildrenAction(ERXWOConditional.java:113)
> at
> com.webobjects.appserver._private.WODynamicGroup.invokeAction(WODynamicGroup.java:115)
> at
> er.extensions.components.conditionals.ERXWOConditional.invokeAction(ERXWOConditional.java:104)
> at
> com.webobjects.appserver.WOComponent.invokeAction(WOComponent.java:1079)
> at
> com.webobjects.appserver._private.WOComponentReference.invokeAction(WOComponentReference.java:127)
> at
> com.webobjects.appserver._private.WODynamicGroup.invokeChildrenAction(WODynamicGroup.java:105)
> at
> com.webobjects.appserver._private.WODynamicGroup.invokeAction(WODynamicGroup.java:115)
> at
> com.webobjects.appserver._private.WOComponentContent.invokeAction(WOComponentContent.java:38)
> at
> com.webobjects.appserver._private.WODynamicGroup.invokeChildrenAction(WODynamicGroup.java:105)
> at
> com.webobjects.appserver._private.WODynamicGroup.invokeAction(WODynamicGroup.java:115)
> at
> com.webobjects.appserver.WOComponent.invokeAction(WOComponent.java:1079)
> at
> com.webobjects.appserver._private.WOComponentReference.invokeAction(WOComponentReference.java:127)
> at
> er.extensions.components._private.ERXSwitchComponent.invokeAction(ERXSwitchComponent.java:117)
> at
> com.webobjects.appserver._private.WODynamicGroup.invokeChildrenAction(WODynamicGroup.java:105)
> at
> com.webobjects.appserver._private.WODynamicGroup.invokeAction(WODynamicGroup.java:115)
> at
> com.webobjects.appserver.WOComponent.invokeAction(WOComponent.java:1079)
> at er.directtoweb.pages.ERD2WPage.invokeAction(ERD2WPage.java:619)
> at
> er.directtoweb.pages.ERD2WListPage.invokeAction(ERD2WListPage.java:479)
> at com.webobjects.appserver.WOSession.invokeAction(WOSession.java:1357)
> at
> com.webobjects.appserver.WOApplication.invokeAction(WOApplication.java:1745)
> at
> er.extensions.appserver.ajax.ERXAjaxApplication.invokeAction(ERXAjaxApplication.java:93)
> at
> er.extensions.appserver.ERXApplication.invokeAction(ERXApplication.java:1863)
> at
> com.webobjects.appserver._private.WOComponentRequestHandler._dispatchWithPreparedPage(WOComponentRequestHandler.java:206)
> at
> com.webobjects.appserver._private.WOComponentRequestHandler._dispatchWithPreparedSession(WOComponentRequestHandler.java:298)
> at
> com.webobjects.appserver._private.WOComponentRequestHandler._dispatchWithPreparedApplication(WOComponentRequestHandler.java:332)
> at
> com.webobjects.appserver._private.WOComponentRequestHandler._handleRequest(WOComponentRequestHandler.java:369)
> at
> com.webobjects.appserver._private.WOComponentRequestHandler.handleRequest(WOComponentRequestHandler.java:442)
> at
> com.webobjects.appserver.WOApplication.dispatchRequest(WOApplication.java:1687)
> at
> er.extensions.appserver.ERXApplication.dispatchRequestImmediately(ERXApplication.java:1978)
> at
> er.extensions.appserver.ERXApplication.dispatchRequest(ERXApplication.java:1943)
> at com.dsm.ec_admin.Application.dispatchRequest(Application.java:289)
> at
> com.webobjects.appserver._private.WOWorkerThread.runOnce(WOWorkerThread.java:144)
> at
> com.webobjects.appserver._private.WOWorkerThread.run(WOWorkerThread.java:226)
> at java.lang.Thread.run(Thread.java:680)
>
> In some D2WInspectPages I have a nextPageDelegate. Calling from here
> everything works.
> This is the code in MyNextPageDelegate
>
> public WOComponent nextPage(WOComponent sender) {
>
> if (!(sender instanceof ERD2WInspectPage)) {
> return null;
> }
>
> // make sure that we are in Edit mode:
> String task =
> (String)((ERD2WInspectPage)sender).d2wContext().valueForKey( "task" );
> if (! "edit".equals( task )) {
> return null;
> }
>
> // trap cancel
> if (!((ERD2WInspectPage)sender).objectWasSaved()) {
> return null;
> }
>
> EOEnterpriseObject object =
> (EOEnterpriseObject)sender.valueForKey( "object" );
>
> if (object instanceof GeneratedDocument) {
> ((GeneratedDocument)object).generatePDF( sender );
> }
> return null;
> }
>
> In a ListPage I have a belowPropertyKey. This is handled by a custom property
> level component showing a WOHyperlink. When I call the same business logic
> from the action method bound to the link the PDF is created but at the end I
> get above mentioned NPE.
>
> public WOActionResults generateAll() {
> ERD2WListPage parentListPage = parentListPage();
> if (parentListPage != null) {
> WODisplayGroup displayGroup = parentListPage.displayGroup();
> NSArray<EOEnterpriseObject> objects = displayGroup.allObjects();
> generate(objects);
> }
> return parentListPage;
> }
>
>
> /** Utility to return the enclosing list page, if there is one. */
> protected ERD2WListPage parentListPage() {
> return (ERD2WListPage)ERD2WUtilities.enclosingPageOfClass(this,
> ListPageInterface.class);
> }
>
> private void generate(NSArray<EOEnterpriseObject> objects) {
>
> for (EOEnterpriseObject object : objects) {
> if (object instanceof GeneratedDocument) {
> ((GeneratedDocument)object).generatePDF(
> parentListPage());
> }
> }
> }
>
> I am sure I must be overlooking something but what? Any help insanely
> appreciated.
> Thanks
> ---markus---
>
>
>
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Webobjects-dev mailing list ([email protected])
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/webobjects-dev/chill%40global-village.net
>
> This email sent to [email protected]
--
Chuck Hill Senior Consultant / VP Development
Practical WebObjects - for developers who want to increase their overall
knowledge of WebObjects or who are trying to solve specific problems.
http://www.global-village.net/products/practical_webobjects
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list ([email protected]) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com This email sent to [email protected]
