PRPierFrame>>#notFound and images

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

PRPierFrame>>#notFound and images

Nick
Hi,

I had a component in Pier which included in a rendering message:

html div class: 'grey_copy14'; style: 'background-image:url(img/faq_title.gif);'

If you can ignore my poor style with inline css, when 'img/faq_title.gif' wasn't present, PRPierFrame>>#notFound is called. This then caused a new component to be created and my context to be reset (see my previous post "sessions, continuation keys, restful urls and component state")

Even if we fix the new component creation but it still seems unnecessary that for images #notFound resets the structure and view:

notFound
"This method is called whenever the current request cannot be resolved to a structure."
self context: (self context
structure: self context root
view: PRNotFoundView)

I propose a fix to only redirect if the MimeType is non-binary, something along the lines of

notFound
"This method is called whenever the current request cannot be resolved to a structure."
self requestContext request mimeType isBinary ifTrue: [ self requestContext responseGenerator notFound ] 
self context: (self context
structure: self context root
view: PRNotFoundView)

Assuming others think this is a reasonable idea, a problem arises in that WARequest doesn't implement #mimeType. I'd propose refactoring WAExternalFileLibrary>>#mimetypeForRequest: and WAFileLibrary>>#mimetypeFor: 

Does that seem a reasonable course of action?

Nick

_______________________________________________
Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki
Reply | Threaded
Open this post in threaded view
|

Re: PRPierFrame>>#notFound and images

Nick
The change doesn't require the "random refactoring" I feared.

Assuming others think this is a reasonable idea, a problem arises in that WARequest doesn't implement #mimeType. I'd propose refactoring WAExternalFileLibrary>>#mimetypeForRequest: and WAFileLibrary>>#mimetypeFor: 

Does that seem a reasonable course of action?

Instead I implement 

PRPierFrame>>#isFileRequest
| path |
path := self requestContext request url path.
^ (path notEmpty and: [ path last includes: $. ])

and modify PRPierFrame>>#notFound to read:

notFound
"This method is called whenever the current request cannot be resolved to a structure."
self isFileRequest ifTrue: [ self requestContext respond: [: response | response notFound ] ].
self context: (self context
structure: self context root
view: IZNotFoundView)


Anyone think this is a bad idea? If not I'll check it in. 

_______________________________________________
Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki
Reply | Threaded
Open this post in threaded view
|

Re: PRPierFrame>>#notFound and images

Lukas Renggli
Hi Nick,

I don't like the solution that looks for the $. It assumes that there
are only dots in resources (which is not necessarily the case).

Why don't you create the image in your component through a correct
context? Something along ...

   html image src: (self context structure: aImageResource) url

Not sure if I recall the exact API.

Lukas


On 18 May 2011 20:03, Nick Ager <[hidden email]> wrote:

> The change doesn't require the "random refactoring" I feared.
>>
>> Assuming others think this is a reasonable idea, a problem arises in that
>> WARequest doesn't implement #mimeType. I'd propose
>> refactoring WAExternalFileLibrary>>#mimetypeForRequest: and
>> WAFileLibrary>>#mimetypeFor:
>> Does that seem a reasonable course of action?
>
> Instead I implement
> PRPierFrame>>#isFileRequest
> | path |
> path := self requestContext request url path.
> ^ (path notEmpty and: [ path last includes: $. ])
> and modify PRPierFrame>>#notFound to read:
> notFound
> "This method is called whenever the current request cannot be resolved to a
> structure."
> self isFileRequest ifTrue: [ self requestContext respond: [: response |
> response notFound ] ].
> self context: (self context
> structure: self context root
> view: IZNotFoundView)
>
> Anyone think this is a bad idea? If not I'll check it in.
> _______________________________________________
> Magritte, Pier and Related Tools ...
> https://www.iam.unibe.ch/mailman/listinfo/smallwiki
>



--
Lukas Renggli
www.lukas-renggli.ch

_______________________________________________
Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki