13 Replies Latest reply on Jan 17, 2009 1:35 AM by Tony Herstell

    Server Side code in Demo

    Tony Herstell Master

      Server Side code in Demo

      It is great to see the xhtml code in the demo site but ti would be great to also see the backing bean (especailly now it is in seam).

      Can you "view source" and also have "view bean".

        • 1. Re: Server Side code in Demo
          Sergey Smirnov Master

          some examples have such link, some are not if it is so important. What exactly the example, you want to see the bean source of?

          • 2. Re: Server Side code in Demo
            Tony Herstell Master

            Thanks for quick reply...

            Following (even cutting and pasting) the xhtml from teh demo page is REALLY great... (I still have the RF and SEAM pdf open all the time of course).

            But eventhen, like the upload component it simply does not work or I am trying to push things a bit further.



            Like the problem I have right now...

            The upload component is failing to upload (correctly) as the supplied file is over the max size but the upload component does not show any error message (unlike the demo which does).

            Solution
            =====

            Try on of the usual "crap":
            1. Check openclose tags (make sure the support tag is actually enclosed!)
            2. Stick it in its own panel - This often fixes things!
            3. Stick it in its own form (checking for form nesting which really hurst RF! - humm you may want to put a check in for this!!!! to tell stupid users they have nested forms!)
            4. force the component to be updated using a support tag.

            Well... that didn't solve it so....

            Try, in this case, adding in rich:message components to try to catch the error that must be thrown... etc.


            Check server log (AHA!) the message is there so why is not being displayed! GGGRRRR...


            Also.. to even get the Uplaod component working gave me a few questions.... it has a data attribute and a listener attribute... I had to figure out that It was the listener method that actually got the data!! I had assumed that the listener method was to pass back update status infomation.... so was trying to get the image from the data attribute and was trying to pass it a List to add the images into.

            SO...... having the ability to see the bean side could would have made this all easier.

            • 3. Re: Server Side code in Demo
              Sergey Smirnov Master

              It like it is better for you just to download the richfaces-demo source code and the ready-to-deploy war file. Follow the link under my signature below.

              • 4. Re: Server Side code in Demo
                Jason Long Master

                The file upload has also been a problem for me with Seam.
                I am hoping I can get this to work with the new a4j:queue component.

                It would be great to see an example of this used with Seam and the fileUpload component seems like a good candidate to me.

                • 5. Re: Server Side code in Demo
                  Tony Herstell Master

                   

                  "SergeySmirnov" wrote:
                  It like it is better for you just to download the richfaces-demo source code and the ready-to-deploy war file. Follow the link under my signature below.


                  Sounds like a plan.

                  Thx.

                  • 6. Re: Server Side code in Demo
                    Tony Herstell Master

                    I am guessing but I think a few of my problems are to do with the fact I am conversational when using the Upload component (will be in an awful lot of places!) and I am not entirley sure the RF Upload Component works too well in seam conversational mode.

                    Anyhow; that is why I was SO excitied that the RF components back end is moving more towards a Seam back end... so, then, at least they can have tested all the components in Conversational mode (HINT!).

                    Seems to work ok, conversationl, in single upload mode though.
                    go http://www.selwynequestriancentre.co.nz and register (just go as far as upload avatar)

                    It may crash as Version of MySQL is not happy storing some chars (image is stored in Dbase) and I am in process of updating version to one that is happier!

                    Humm...

                    • 7. Re: Server Side code in Demo
                      Jason Long Master

                      I was not aware that RF was moving towards Seam usage except for adding a4j:queue.

                      I am inside a long running conversation and it works, but not in a stable manner.

                      If anyone gets this working smoothly I would greatly appreciate an example of rich:fileUpload used inside a long running Seam conversation.

                      • 8. Re: Server Side code in Demo
                        Tony Herstell Master

                         

                        "supernovasoftware.com" wrote:
                        I was not aware that RF was moving towards Seam usage except for adding a4j:queue.


                        The stacktrace from their demo code when it fails is a seam dump! I suppose it makes sense commerically to use Seam as its part of JBoss stack like I imagine it may be running on a JBoss server.


                        "supernovasoftware.com" wrote:
                        If anyone gets this working smoothly I would greatly appreciate an example of rich:fileUpload used inside a long running Seam conversation.


                        Me 2

                        It MAY be a red herring about the Long Running conversation! - ask the experts!

                        • 9. Re: Server Side code in Demo
                          Jason Long Master

                          That is great to hear. I always wished for Richfaces examples that were built on Seam.

                          • 10. Re: Server Side code in Demo
                            Tony Herstell Master

                            Hi Jason/Sergey.

                            Now have seem code behind; its not Seam based at all... [Egg on face].

                            Anyhow its really useful looking at that source.


                            ...


                            Here is the code that seems to work ok with richUpload and multiple files conversationally.


                            XHTML

                            <a4j:outputPanel id="prizes">
                             <fieldset class="general_form_fieldset">
                            
                             <legend class="general_form_legend">
                             <h:outputText value="#{messages.events_fieldset_prizes} " />
                             <s:fragment rendered="#{eventsPrizePics.rowCount > 0}">
                             <h:outputText value="[#{eventsPrizePics.rowCount}/#{prizePicsMaxUploadsAvailable}]"/>
                             </s:fragment>
                             </legend>
                            
                            
                             <table width="100%">
                             <tr>
                             <td>
                             <rich:dataTable value="#{eventsPrizePics}" var="eachPic" columnClasses="center"
                             rows="10" width="100%" rendered="#{eventsPrizePics.rowCount > 0}"
                             onRowMouseOver="this.style.backgroundColor='#F8F8F8'"
                             onRowMouseOut="this.style.backgroundColor='#{a4jSkin.tableBackgroundColor}'">
                             <rich:column>
                             <f:facet name="header">
                             <h:outputText value="Image"/>
                             </f:facet>
                             <s:graphicImage fileName="#{eachPic.image}" value="#{eachPic.image}" width="70px" />
                             </rich:column>
                             <rich:column>
                             <f:facet name="header">
                             <h:outputText value="Name"/>
                             </f:facet>
                             <h:outputText value="#{eachPic.name}" />
                             </rich:column>
                             </rich:dataTable>
                             </td>
                            
                             <td>
                             <a4j:form id="imagesUploadForm">
                             <rich:fileUpload id="eventPrizeImages" acceptedTypes="png, jpg, gif, bmp"
                             fileUploadListener="#{eventsController.listener}" autoclear="true" immediateUpload="false"
                             maxFilesQuantity="#{prizePicsUploadsAvailable}" allowFlash="true">
                             <f:facet name="label">
                             <h:outputText value="{_KB}KB from {KB}KB uploaded --- {mm}:{ss}"/>
                             </f:facet>
                             <a4j:support event="onuploadcomplete" limitToList="true" reRender="prizes" />
                             </rich:fileUpload>
                             </a4j:form>
                             </td>
                             </tr>
                             </table>
                             </fieldset>
                            </a4j:outputPane
                            


                            Controller
                            note that the list of Images (prizes) is contained in an event

                            @SuppressWarnings("serial")
                            @Stateful
                            @Conversational
                            @Scope(value=ScopeType.CONVERSATION)
                            @Name("eventsController")
                            


                             /**
                             * Inject the EJB3 Persistence context.
                             */
                             @PersistenceContext(type=PersistenceContextType.EXTENDED)
                             private EntityManager em;
                            


                             @DataModel(value="eventsPrizePics")
                             private List<Image> eventsPrizePics;
                            


                             /**
                             * Outject the maximum number of uploadsAvailabe for Prize prictures.
                             */
                             @Out
                             int prizePicsMaxUploadsAvailable = 10;
                            
                             /**
                             * Outject the number of uploadsAvailabe for Prize prictures.
                             */
                             @Out
                             int prizePicsUploadsAvailable = 10;
                            


                             @Override
                             @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
                             public String viewEvent(Event event) {
                             this.event = event;
                             this.mode = Mode.READ;
                             this.allEventsClasses = event.getClasses();
                             prizePicsUploadsAvailable = 10;
                             if (event.getPrizes() != null && event.getPrizes().getActualImages() != null) {
                             this.eventsPrizePics = event.getPrizes().getActualImages();
                             prizePicsUploadsAvailable = 10 - this.eventsPrizePics.size();
                             }
                             return "viewEvent";
                             }
                            


                            @Override
                             @TransactionAttribute(TransactionAttributeType.REQUIRED)
                             public void listener(UploadEvent event) throws IOException {
                             List<UploadItem> uploadedImages = event.getUploadItems();
                             for (UploadItem eachItem : uploadedImages) {
                             Image theImage = new Image();
                             theImage.setImage(eachItem.getData());
                             theImage.setName(eachItem.getFileName());
                             String mime;
                             int extDot = eachItem.getFileName().lastIndexOf('.');
                             if(extDot > 0){
                             String extension = eachItem.getFileName().substring(extDot +1);
                             if("bmp".equals(extension)){
                             mime="image/bmp";
                             } else if("jpg".equals(extension) || "jpeg".equals(extension)){
                             mime="image/jpeg";
                             } else if("gif".equals(extension)){
                             mime="image/gif";
                             } else if("png".equals(extension)){
                             mime="image/png";
                             } else {
                             mime = "image/unknown";
                             }
                             theImage.setType(mime); // eachItem.getContentType() <- Always octet type
                             }
                             if (this.event.getPrizes() == null) {
                             Images images = new Images();
                             images.setActualImages(new ArrayList<Image>());
                             this.event.setPrizes(images);
                             }
                             Images prizes = this.event.getPrizes();
                             List<Image> actualImages = prizes.getActualImages();
                             actualImages.add(theImage);
                             prizes.setActualImages(actualImages);
                             this.event.setPrizes(prizes);
                             this.eventsPrizePics = this.event.getPrizes().getActualImages();
                             prizePicsUploadsAvailable = 10 - this.eventsPrizePics.size();
                             }
                             em.persist(this.event);
                             }
                            



                            Entites

                            Event
                            @SuppressWarnings("serial")
                            @Entity
                            @Name("event")
                            public class Event implements Serializable {
                            ...
                            private Images prizes;
                             @OneToOne(fetch = FetchType.LAZY, cascade={CascadeType.ALL})
                            


                            Images
                            @SuppressWarnings("serial")
                            @Entity
                            @Name("images")
                            public class Images implements Serializable {
                            ...
                            @OneToMany(fetch = FetchType.LAZY, cascade={CascadeType.ALL})
                             private List<Image> actualImages;
                            


                            Image
                            @SuppressWarnings("serial")
                            @Entity
                            @Name("image")
                            public class Image implements Serializable {
                            ...
                            private String name;
                             @NotNull(message="required")
                             @Length(max = 30)
                             private String type;
                             @NotNull(message="required")
                             @Lob
                             private byte[] image;
                            


                            • 11. Re: Server Side code in Demo
                              Tony Herstell Master

                              Actually its not quite perfect...

                              For an oversize image I get this in the server log:

                              12:58:03,562 ERROR [STDERR] ERROR 413request entity is larger than the server is willing or able to process.
                              


                              But the component says NOTHING

                              Its not a faces massage either...

                              Basically its appears to be a BUG but it works on the Demo version...




                              • 12. Re: Server Side code in Demo
                                Tony Herstell Master

                                This is what made me think it was Seam backed.

                                
                                JBoss Seam Debug Page
                                This page allows you to browse and inspect components in any of the Seam contexts associated with the current session. It also shows a list of active, long-running conversations. You can select a conversation to view its contents or destroy it.
                                Conversations
                                No long-running conversations exist
                                + - Component (None selected)
                                Select a component from one of the contexts below
                                + - Conversation Context (None selected)
                                org.jboss.seam.international.statusMessages
                                + - Business Process Context
                                Empty business process context
                                + - Session Context
                                org.jboss.seam.core.conversationEntries
                                org.jboss.seam.international.localeSelector
                                org.jboss.seam.international.timeZoneSelector
                                org.jboss.seam.security.credentials
                                org.jboss.seam.security.identity
                                org.jboss.seam.security.rememberMe
                                org.jboss.seam.web.session
                                + - Application Context
                                


                                • 13. Re: Server Side code in Demo
                                  Tony Herstell Master

                                  Don't update the rich:fileUpload component! it looks after itself...
                                  This solved my disappearing message problem.