6 Replies Latest reply on Apr 26, 2007 12:49 AM by courtneycouch

    using seam component for a4j:mediaOutput paint bean

    courtneycouch

      I'm not sure if this isnt possible or if I'm simply doing something wrong but I'm trying to use seam injected components with the mediaOutput tag.

      i.e. <a4j:mediaOutput element="img" cacheable="false" session="true" createContent="#{paintBean.paint}" mimeType="image/jpeg"/>

      where paintBean is a seam managed components.

      I am thinking that I cannot use seam components (as it would render the value parameter unnecessary anyway).

      I can use it without a problem adding the manage-bean definitions in faces-config.xml and then passing a value class so getting it working isnt the problem... It would just be VERY convenient to be able to use bijection in the bean creating the content rather than serializing a class in the value parameter since that only lets me inject a serializable class to the paint bean.

      -c

        • 1. Re: using seam component for a4j:mediaOutput paint bean

          There is a dilemma there. You can use the whole JSF lifecycle with restoring the session for each request to resources like this OR serialize only the required data and pass it directly to the method.
          Ajax4jsf uses the second approach. value attribute is used to point to the serializable data. The first approach has to high price (from the performance point of view, first of all).

          • 2. Re: using seam component for a4j:mediaOutput paint bean
            courtneycouch

            gotcha.

            I realize there is a performance hit involved, but for if the paintBean has to outject data there is a problem.

            If the bean only needs basic data injected for rendering then that method of behavior is fine. In my case I need the rest of the application aware of how much of the generated file was downloaded (which would be simple if I could simply outject the return of the transferTo and compare that to the channels size() value).

            Perhaps there is an easier way to handle this. If someone takes the URL for the media object I simply dont want them to be able to paste that url into the browser indefinetely to grab the file. I need the application to control a limited number of complete downloads.

            Since its few large files, the lifecycle overhead in my case is minimal.

            Am I better off rolling a custom solution? If I cant biject from the paint bean, perhaps there is another workaround? Just going a completely different route would be fine, just seems a shame when simply being able to biject from the paintbean would solve the entire dilema (or at least the option of having the paintbean be a seam component).

            • 3. Re: using seam component for a4j:mediaOutput paint bean

              I just have told with Alex. There some point there.

              a4j:mediaOutput has a 'session' attribute. If it set to true, the session id is attached to the URL that is used for accessing to the resource. (It is only important if user has cookie set off)

              The session is restored is a4j:mediaOutput has access to session beans. (otherwise, it does not)

              So, I still recommend you to separate the paint bean and the data bean. I.e., use value attribute to the data you want to use in the pint bean. Let paint bean has a session scope and contains the property used as a counter of activity progress.
              In this way, you can invoke the paint bean method with a4j:mediaOutput and then control the progress with a4j:poll that checks the counter and shows the progress on the page.

              • 4. Re: using seam component for a4j:mediaOutput paint bean
                henrik.lindberg

                I used a different approach - when trying out stuff with the mediaOutput, I used a String as the paint data and then used Seam context methods to get a real paint object - thus getting bijection in code.

                • 5. Re: using seam component for a4j:mediaOutput paint bean

                  In any case, you need to use 'value' attribute that is changed when data is changed. Otherwise, you can a problem with cache when the output is not updated

                  • 6. Re: using seam component for a4j:mediaOutput paint bean
                    courtneycouch

                     

                    "henrik.lindberg" wrote:
                    I used a different approach - when trying out stuff with the mediaOutput, I used a String as the paint data and then used Seam context methods to get a real paint object - thus getting bijection in code.


                    Yea thats what I'm doing now.

                    In my case I need to disallow a download if its already happened x number of times, track attempts, etc. Since the URL could be simply re-used there has to be a way to track and store it. Using session scoped beans works as long as the downloads all happen in the same session, but when its spread across sessions, without bijection or trying to use some database operation it doesnt seem to be feasible. Using a a4j:poll would rely on the client for security and tracking (which would break as soon as they copied the URL).

                    In either case using the context methods works (curious how efficient that is in comparison to being able to have the option of using a seam component directly instead of a managed-bean).

                    Also, I guess this is more seam related than a4j related (wanted to mention it at least) but in a seam application since you are using a seam phase listener, and in seam your using seam components in favor of managed-beans, the managed-beans lose some functionality you would have in a sans-seam environment. The managed-bean lifecycle, ejb injection, etc. dont seem to work. This seems to limit flexibility in regards to tags like the mediaOutput tag when used within a seam application.

                    Anyway, cheers. thanks for the replies.

                    -c