3 Replies Latest reply on Jan 26, 2008 11:38 AM by Nick Belaevski

    possible rich faces bug

    x y Newbie

      hi - i might have found a bug with richfaces.

      i have a form that has a rich:listShuttle and s:fileUpload at the same time.

      if i add enctype="multipart/form-data" to the form, in order to get the s:fileUpload work, shuttle stops working.

      form submits, no error, but the target list is submitted empty.

      i will appreciate any opinion. thanks.

        • 1. Re: possible rich faces bug
          Sergey Smirnov Master

          code snippet is required.

          • 2. Re: possible rich faces bug
            x y Newbie

            when i remove enctype="multipart/form-data", it works as expected but i need it for s:upload.. on the same page..

            --The page is as follows:

            <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
            "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
            <ui:composition xmlns="http://www.w3.org/1999/xhtml"
            xmlns:s="http://jboss.com/products/seam/taglib"
            xmlns:ui="http://java.sun.com/jsf/facelets"
            xmlns:f="http://java.sun.com/jsf/core"
            xmlns:h="http://java.sun.com/jsf/html"
            xmlns:rich="http://richfaces.org/rich"
            template="layout/template.xhtml">

            <ui:define name="body">

            <h:form id="documentForm" enctype="multipart/form-data">

            <rich:tabPanel switchType="client">

            <rich:tab label="Document">

            <s:decorate id="nameDecoration" template="layout/edit.xhtml">
            <ui:define name="label">Name</ui:define>
            <h:inputText id="name" required="true"
            value="#{documentHome.instance.name}"/>
            </s:decorate>

            <s:decorate id="fileDecoration" template="layout/edit.xhtml">
            <ui:define name="label">
            #{documentHome.instance.filename}
            </ui:define>
            <s:fileUpload id="file"
            data="#{documentHome.bytes}"
            contentType="#{documentHome.instance.contentType}"
            fileName="#{documentHome.instance.filename}" />
            </s:decorate>

            </rich:tab>

            <rich:tab label="Organizations">

            <rich:listShuttle
            sourceValue="#{documentHome.organizationSourceList}"
            targetValue="#{documentHome.organizationTargetList}"
            var="organization"
            listHeight="300"
            listWidth="300"
            sourceCaptionLabel="All Organizations"
            targetCaptionLabel="Selected Organizations"
            converter="organizationConverter">

            <rich:column>
            #{organization.name}
            </rich:column>

            </rich:listShuttle>

            </rich:tab>

            </rich:tabPanel>


            <h:commandButton id="save"
            value="Save"
            action="#{documentHome.persist}"
            rendered="#{!documentHome.managed}"/>
            <h:commandButton id="update"
            value="Save"
            action="#{documentHome.update}"
            rendered="#{documentHome.managed}"/>
            <h:commandButton id="delete"
            value="Delete"
            action="#{documentHome.remove}"
            rendered="#{documentHome.managed}"/>
            <s:button propagation="end"
            id="done"
            value="Done"
            view="/documentFinder.xhtml"/>


            </h:form>

            </ui:define>

            </ui:composition>

            --Converter is as follows:

            @Name("organizationConverter")
            @BypassInterceptors
            @Converter
            public class OrganizationConverter implements javax.faces.convert.Converter
            {
            @Transactional
            public Object getAsObject(FacesContext context, UIComponent component, String value)
            {
            EntityManager entityManager = (EntityManager) Component.getInstance("entityManager");
            entityManager.joinTransaction();

            Long id = Long.valueOf(value.substring(value.indexOf(":") + 1));
            Organization o = entityManager.find(Organization.class, id);
            return o;
            }

            public String getAsString(FacesContext context, UIComponent component, Object value)
            {
            Organization o = (Organization) value;
            return o.getName() + ":" + o.getId();
            }
            }

            --Here is the backing bean..


            @Stateful
            @Scope(ScopeType.SESSION)
            @Name("documentHome")
            public class DocumentHome extends EntityHome implements LocalDocumentHome
            {

            private List organizationSourceList = new ArrayList();
            private List organizationTargetList = new ArrayList();

            public List getOrganizationSourceList()
            {
            return organizationSourceList;
            }

            public List getOrganizationTargetList()
            {
            return organizationTargetList;
            }

            public void setOrganizationSourceList(
            List organizationSourceList)
            {
            this.organizationSourceList = organizationSourceList;
            }

            public void setOrganizationTargetList(
            List organizationTargetList)
            {
            this.organizationTargetList = organizationTargetList;
            }


            @RequestParameter
            Long documentId;

            @Logger
            Log log;

            @In
            private FacesContext facesContext;

            @In(required=false)
            DocumentFinder documentFinder;

            private byte[] bytes;
            private String contentType;
            private String filename;

            public String getContentType() {
            return contentType;
            }

            public void setContentType(String contentType) {
            this.contentType = contentType;
            }

            public String getFilename() {
            return filename;
            }

            public void setFilename(String filename) {
            this.filename = filename;
            }

            @Override
            public Object getId()
            {
            if (documentId==null)
            {
            return super.getId();
            }
            else
            {
            return documentId;
            }
            }

            @Override @Begin
            public void create()
            {
            super.create();

            if (getInstance().getOrganizationList() != null)
            {
            for (Organization o: getInstance().getOrganizationList())
            {
            organizationTargetList.add(o);
            }
            }

            List organizationSourceList_ = getEntityManager().createQuery("from Organization")
            .getResultList();

            for (Organization o: organizationSourceList_)
            {
            if (!organizationTargetList.contains(o))
            {
            organizationSourceList.add(o);
            }
            }
            }

            public byte[] getBytes()
            {
            return bytes;
            }

            public void setBytes(byte[] bytes)
            {
            this.bytes = bytes;

            log.info("SET BYTES CALLED----" + bytes);
            }

            @Override
            public String update()
            {
            log.info("UPDATE CALLED");

            persistOrganizationList();
            return super.update();
            }

            private void persistOrganizationList()
            {
            if (getInstance().getOrganizationList() == null)
            {
            getInstance().setOrganizationList(new ArrayList());
            }
            else
            {
            getInstance().getOrganizationList().clear();
            }

            for (Organization o: organizationTargetList)
            {
            getEntityManager().merge(o);
            getInstance().getOrganizationList().add(o);

            log.info("PERSISTED " + o.getName());
            }
            }

            @Override
            public String persist()
            {
            log.info("PERSIST CALLED-----");

            getInstance().setFilename(filename);
            getInstance().setContentType(contentType);
            getInstance().setCreatedOn(new Date(System.currentTimeMillis()));
            String s = super.persist();

            persistOrganizationList();

            if (bytes == null)
            {
            log.info("BYTES IS NULL---");
            }

            if (bytes != null && bytes.length > 0)
            {

            log.info("PERSIST BYTES HERE ");
            }

            return s;
            }

            @Override
            public boolean isManaged()
            {
            return super.isManaged();
            }

            @Override
            public Document getInstance()
            {
            return super.getInstance();
            }

            @Override
            public String remove()
            {
            return super.remove();
            }

            @Destroy
            @Remove
            public void destroy() {}

            }

            • 3. Re: possible rich faces bug
              Nick Belaevski Master

              Thank you for reporting the issue! We'll investigate that: http://jira.jboss.com/jira/browse/RF-2073