Juergen Lorenz Simon | 27 Apr 11:17
Favicon
Gravatar

Re: Problem with download link in 'appendToResponse' [SOLVED]


Worked like a charm. Thanks!

On 26.04.2012, at 02:37, Alexis Tual wrote:

Hi,

2012/4/26 Juergen Lorenz Simon <simon <at> webtecc.com>
Hi,

I'm trying to generate some file content on the fly and return it when the user clicks a link. I'm doing this in a D2W context, the component is a propoerty level component. I had some success by overwriting appendToResponse like so:

public void appendToResponse(com.webobjects.appserver.WOResponse response, WOContext context) 
{
if ( shouldDownloadFile )
{
String fileName = "generated.properties";
String contentType = "text/ascii";
response.setHeader( contentType + "; name=\"" + fileName + "\"""Content-Type" ); 
response.setHeader( 
"attachment; filename=\"" + fileName + "\"""Content-Disposition");
String content = this.configuration();
response.setContent( content );
}
else
{
    super.appendToResponse( response, context );
}
}

The flag 'shouldDownloadFile' is set to true when the link contained in the component is clicked (normal action binding).

However, instead of only the generated content, I also get some other generated HTML in the file. Does somebody know what the problem is?

Your action returns probably null, so the current page is rerendered after the action, this causes your appendToResponse to be called on each components of your page (except the one nested into your property level component), as a result you get a funky response :)

For this kind of stuff, try to create a response in your action, for example :

    ERXDownloadResponse dl = pageWithName(ERXDownloadResponse.class);
    byte[] someData = this.configuration().getBytes();
    dl.setInputStreamToDownload(new ByteArrayInputStream(someData), someData.length);
    dl.setContentType("text/ascii")
    dl.setDownloadFilename("generated.properties");
    return dl;
 
Alex

_______________________________________________
WebObjects-dev mailing list
WebObjects-dev <at> omnigroup.com
http://www.omnigroup.com/mailman/listinfo/webobjects-dev
Ondřej Čada | 26 Apr 17:13
Picon

decimal . or , interchangeable

Hello again,

the client want me to change a pretty old and pretty big WO application so that both '.' and ',' work
interchangeably for a decimal point on input, in all fields of all forms.

I know a number of ways to do that for a specific field, but before I dive into that, isn't there a way to say
globally for an entire WO application: "Hey, whenever and wherever you are converting a string to a
number, consider '.' and ',' equal"? That would help a lot.

I went through the NSNumberFormatter API, but found nothing :(

Thanks and all the best,
---
Ondra Čada
OCSoftware:     ocs <at> ocs.cz               http://www.ocs.cz
private         ondra <at> ocs.cz             http://www.ocs.cz/oc
Ondřej Čada | 26 Apr 15:17
Picon

setPageRefreshOnBacktrackEnabled problem?

Hello there,

either setPageRefreshOnBacktrackEnabled does not work, or I am missing something fundamental.

In my "class Application extends ERXApplication" I do "setPageRefreshOnBacktrackEnabled(true)". All
the HTTP headers are generated all right, far as I can say:

===
12 ~P/WebObjects> curl -D - <my app URL>
HTTP/1.1 200 Apple
Date: Thu, 26 Apr 2012 13:05:20 GMT
Server: Apache/2.2.21 (Unix) mod_ssl/2.2.21 OpenSSL/0.9.8r
cache-control: private
cache-control: no-cache
cache-control: no-store
cache-control: must-revalidate
cache-control: max-age=0
expires: Sun, 22-Apr-2012 20:37:15 GMT
pragma: no-cache
set-cookie: wosid=YCGjnZm0l4GhkbB33k27C0; version="1"; path=/cgi-bin/WebObjects/CEBOIS.woa
set-cookie: woinst=1; version="1"; path=/cgi-bin/WebObjects/CEBOIS.woa
connection: close
content-length: 5452
MS-Author-Via: DAV
Content-Type: text/html; charset=UTF-8

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
...
===

In my session there is "SomeClass foo".

In one of my pages, there is (essentially) this:

===
<wo:if condition=$session.foo> OK <wo:str value=$session.foo.title/> </wo>
<wo:else>
  <wo:hyperlink action=$selectFoo1>Foo1</wo>
  <wo:hyperlink action=$selectFoo2>Foo2</wo>
</wo>
===

with the actions trivial "WOComponent selectFoo1() { session().foo=foo1; return null; }" and similar
with Foo2. (There is also a "select Foo" action in the OK part which does session().foo=null, but that's
not important here, it works perfectly.)

It works perfectly -- till I use backtrack. With backtrack, it goes all wrong :(

1. page is opened, shows "Foo1 Foo2"
2. "Foo1" is clicked, shows correctly the "OK Foo1.title" contents
3. back button is used --> oops, shows again "Foo1 Foo2"!

Here I probably am missing something -- given I have set pageRefreshOnBacktrackEnabled=true, it should
show still OK, since my session still contains non-null foo, should it not?

Anyway, seems no part of my application gets activated at this moment; not even appendToResponse logs anything.

4. "Foo2" is clicked --> oops, shows again "OK Foo1.title"

whilst none of the selectFoo1/selectFoo2 actions is ever called. appendToResponse is called, though.

What am I missing, and, more important, how to fix the problem? I don't care whether
(a) back keeps showing the "OK Foo1.title" contents (
(b) back goes to "Foo1 Foo2" AND selection works all right.

I've googled out a trick based on contextID comparation, but that one fails with automatic refresh (which
it considers to be same as "back") :(

Thanks and all the best,
---
Ondra Čada
OCSoftware:     ocs <at> ocs.cz               http://www.ocs.cz
private         ondra <at> ocs.cz             http://www.ocs.cz/oc
Ondřej Čada | 26 Feb 01:24
Picon

Weird OGNL problem?

Hello there,

at the moment, I'm getting the following exception. Can anybody see where the null extra argument got from?
I'd be grateful for any advice:

Feb 26 01:18:29 CEBOIS[56000] ERROR ognl.webobjects.WOOgnlAssociation  - Exception invoking
valueInComponent on WOOgnlAssociation with keyPath '!sess().currentUserCanEditAuction(auctionItem)'
MissingMethodException: No signature of method: app.Session.currentUserCanEditAuction() is
applicable for argument types: (null, model.DBAuction) values: [null, { ... the auction from
auctionItem ... }]
Possible solutions: currentUserCanEditAuction(model.DBAuction)
...

Thanks and best,
---
Ondra Čada
OCSoftware:     ocs <at> ocs.cz               http://www.ocs.cz
private         ondra <at> ocs.cz             http://www.ocs.cz/oc
Ondřej Čada | 23 Feb 12:00
Picon

WOLips HTML formatter woes

Hello there,

is it possible to make the thing *not* to turn accented characters to HTML entitites?

When I put "á" into my UTF-8 HTML template, I'd rather it stayed "á"; that it gets turned into &aacute; is
extremely annoying.

Thanks and best,
---
Ondra Čada
OCSoftware:     ocs <at> ocs.cz               http://www.ocs.cz
private         ondra <at> ocs.cz             http://www.ocs.cz/oc
Ondřej Čada | 22 Feb 13:21
Picon

access to enclosing component bindings?

Hello there,

in a structure similar to

<wo:repeat ... list="$something.out.there">
  <wo:MyComponent partOfList="$something.out.there"/>
</wo>
<wo:repeat ... list="$another.list.here">
  <wo:MyComponent partOfList="$another.list.here"/>
</wo>
<wo:repeat ... list="$and.just.another.one">
  <wo:MyComponent partOfList="$and.just.another.one"/>
</wo>

if would be pretty convenient if I could implement MyComponent so that instead of binding its "partOfList"
explicitly, it finds the enclosing WORepetition (innermost if more, crash if none) and reads in its list binding.

Is it possible? If so, can you please point me to some hint/example/doc of howto?

Thanks a lot,
---
Ondra Čada
OCSoftware:     ocs <at> ocs.cz               http://www.ocs.cz
private         ondra <at> ocs.cz             http://www.ocs.cz/oc
Louis Demers | 22 Feb 01:26
Picon

Barcode with iText

Hi,

	I'm trying to create barcodes with iText without inserting them into a PDF, but instead for inclusion into
a wocomponent. The barcode is returned as a com.itextpdf.text.Image but I can't figure out how to get a
usable image for woimage. Alternatively, I could get a java.awt.Image, But I'm equally dum and clueless
with those.

Any past experience and pointers would be welcomed.

Cordially.

Louis Demers eng.
www.obzerv.com
Ondřej Čada | 21 Feb 15:33
Picon

Quick OGNL question

Hello there,

among others, I'm exploring the WOOgnl power (quite nice stuff!)

Now I've got a subcomponent whose bindings are "auction" and "field". Auction has methods

// Auction -- the object to which the component's "auction" binding leads
String listFieldValue(Field field) { return .... }
void setListFieldValue(Field field, Strin val) { .... }

The subcomponents contains, among others,

<wo:textfield value = "~auction.listFieldValue(field)"/>

and I was rather surprised seeing the form gets created properly -- the OGNL thing is quite nice :)

Of course, as you probably guessed long ago, self-evidently the form can't save with this binding. Now, is
there an OGNL trick to fix it in the HTML/WOD so that it does save all right, or do I have to implement glue code
in my component and bind to that, like

// Component glue code
String listFieldValue() { auction.listFieldValue(field) }
void setListFieldValue(String val) { auction.setListFieldValue(field,val) }

<!-- and new binding -->
<wo:textfield value = "$listFieldValue"/>

Thanks and all the best,
---
Ondra Čada
OCSoftware:     ocs <at> ocs.cz               http://www.ocs.cz
private         ondra <at> ocs.cz             http://www.ocs.cz/oc
Ondřej Čada | 19 Feb 22:25
Picon

form woes

Well, a few hours ago I've set up my first file uploading form in WONDER/WOLips/WO 5.4.3.

Incredible fun.

As soon as I've set up "multipart/form-data", I've stopped getting my action. That one was comparatively
easy -- I just had to copy the action from the submit button binding to the form binding.

As soon as the action was fixed, it got couriouser and couriouser -- I've found I'm not getting any form data.

Overriding takeValuesFromRequest at all levels I've found that both application and session get the form
all right, in other words, the ERXRequest's formValues does contain proper data there. Nevertheless, at
the very beginning of component's takeValuesFromRequest the form gets weirdly re-interpreted --
formValues are empty; on the other hand, the ERXRequest body is nonempty now.

Spending some time googling I've found this happens when encodings are switched; nevertheless, I do not
switch encodings at all. At the beginning I set
ERXMessageEncoding.setDefaultEncodingForAllLanguages("UTF-8") and that's all.

Well I've overridden application's _createRequest, and using my own ERXRequest subclass I've
intercepted methods to see what happens betw. session and first component takeValuesFromRequest. Far
as I can say, nothing happens.

After trying lots and lots of things, I've eventually stuck with this class (whose instance is returned
from ). It's rather ugly, but whatever I did, I did not find any other way to make it work :(

===
class WTFRequest extends ERXRequest {
	NSMutableDictionary savedFormValues;
	NSDictionary formValues() {
		NSDictionary d=super.formValues();
		if (d?.count()==0) {
			if (savedFormValues) return savedFormValues;
		} else {
			if (!savedFormValues)
				savedFormValues=d.mutableClone();
			else savedFormValues.addEntriesFromDictionary(d);
		}
		return d;
	}
}
===

Now I am getting the form data, normal ones and WOFileUpload ones as well -- but for mimeType, that one comes
in the form all right, but for whatever weird reason the binding does not fill the variable. Oh, well; I'm
using file name suffix instead...

Sum it all, six-odd hours to implement something which used to take full six minutes in WOBuilder, Xcode and
WO 5.3 and before :( I do wonder what's the culprit; this is sorta big mess to my liking :(

All the best,
---
Ondra Čada
OCSoftware:     ocs <at> ocs.cz               http://www.ocs.cz
private         ondra <at> ocs.cz             http://www.ocs.cz/oc
Ondřej Čada | 19 Feb 15:09
Picon

sql to update existing database?

Hello there,

is there a script or Entity Modeller tool or whatever to generate a "diff" SQL for given model and existing
database, so that tables get created for new entities, but updated (by adding columns) for the already
existing ones?

Seems to me basic enough functionality for someone already have done that, but can't find anything on the web...

Thanks and all the best,
---
Ondra Čada
OCSoftware:     ocs <at> ocs.cz               http://www.ocs.cz
private         ondra <at> ocs.cz             http://www.ocs.cz/oc
Ondřej Čada | 11 Feb 08:34
Picon

WOComponent editor

Hello there,

there are a couple of things I seem not able to find an answer on the web -- if you could help perhaps...

(a) is there a way to switch betw. the inline (<wo:string value="$foo"/>) and classic (<webobject
name=Foo/> in html, Foo:WOString { value=foo; } in wod) patterns automatically, without having to
re-write and copy/paste manually? Some smart script which could do that in batches based on list of tags
and number of bindings would be about perfect, but even a shortcut which would work over one selected tag
would help.

(b) happens somebody to know what's the difference betw. HTML and WOD Content Assist? For my java
components they both work consistently. The weird thing is, for my groovy components the HTML Content
Assist works just as well as it does for java ones; nevertheless, in WODs it does not offer anything from the
class. Though I supposed it would not work at all with Groovy, seeing  it works in HTML perfectly, I'd like to
fix the problem in WOD, if possible?

And writing the above, I recalled I've got two more unanswered questions, one WOLips, one Eclipse:

(d) is it possible to place the generated files outside of projects? I'm rather used to zip or send projects
as they are; whilst it is of course possible to filter out the generated files at that moment, it would be
rather more convenient if they could be simply placed in some extra folder by Eclipse/WOLips/whomever
creates them.

(e) any way to make the Eclipse editors to wrap lines like Xcode does? The reformatting is not a good option
(it does not format the code a way I'd like, not by far), and the com.ahtik.wordwrap.feature.group Word
Wrap Feature does not work quite well either :/

Thanks and all the best,
---
Ondra Čada
OCSoftware:     ocs <at> ocs.cz               http://www.ocs.cz
private         ondra <at> ocs.cz             http://www.ocs.cz/oc

Gmane