无法“隐藏”丰富:文件上传

发布于 2024-10-06 06:38:09 字数 7969 浏览 5 评论 0原文

我正在尝试创建一个使用 rich:fileUpload 的页面来(令人惊讶地)上传图像,上传完成后我想“隐藏” rich:fileUpload 组件并显示 jQuery 插件 jCrop 以便可以裁剪图像保存之前。一旦从所选裁剪中保存图像,这两个组件应再次切换其可见性。

但是,我似乎无法将 rich:fileUpload 隐藏起来。 jCrop 组件显示良好,jCrop 功能也显示良好。但无论我如何尝试 rich:fileUpload 仍然显示在屏幕上。实际上,如果我将 rendered="#{!uploadAndCrop.newImage}" 添加到 rich:fileUpload 所在的 rich:panel 中,似乎没有任何更新。我必须删除它才能显示 jCrop 组件。

我的代码如下,有点混乱,因为我尝试了很多不同的东西。如果有人能指出我正确的方向,或者建议更好的方法,我将非常感激。

谢谢

<ui:define name="head">
    <link href="stylesheet/jquery.Jcrop.css" rel="stylesheet"
        type="text/css" />

    <script type="text/javascript" src="scripts/jquery-1.4.4.min.js"></script>
    <script type="text/javascript" src="scripts/jquery.Jcrop.js"></script>

    <script language="Javascript">// <![CDATA[ //
     {      
        var $J = jQuery.noConflict();
     }
    //]]> //</script>


</ui:define>

<ui:define name="body">
    <h:form>
        <h:panelGrid columns="2" columnClasses="top,top">

            <h:panelGroup id="uploadgroup">
                <a4j:outputPanel id="uploadpanel">
                    <rich:panel rendered="#{!uploadAndCrop.newImage}">
                        <rich:fileUpload fileUploadListener="#{uploadAndCrop.listener}"
                            maxFilesQuantity="#{uploadAndCrop.uploadsAvailable}" id="upload"
                            immediateUpload="#{uploadAndCrop.autoUpload}"
                            acceptedTypes="jpg, gif, png, bmp"
                            allowFlash="#{uploadAndCrop.useFlash}" listHeight="80px">
                            <ui:remove>
                                onfileuploadcomplete="Richfaces.showModalPanel('croppanel');">
                            </ui:remove>
                            <a4j:support event="onuploadcomplete"
                                reRender="info, uploadgroup, cropgroup" />
                        </rich:fileUpload>
                        <h:outputText value="#{uploadAndCrop.newImage}" id="newimage" />
                        <a onclick="Richfaces.showModalPanel('croppanel');" href="#">Show
                        ModalPanel</a>
                    </rich:panel>
                </a4j:outputPanel>
            </h:panelGroup>



            <h:panelGroup id="info">
                <rich:panel bodyClass="info" rendered="#{!uploadAndCrop.newImage}">
                    <f:facet name="header">
                        <h:outputText value="Uploaded Image Preview" />
                    </f:facet>

                    <rich:dataGrid columns="1" value="#{uploadAndCrop.files}"
                        var="file" rowKeyVar="row">
                        <rich:panel bodyClass="rich-laguna-panel-no-header">
                            <h:panelGrid columns="2">
                                <a4j:mediaOutput element="img" mimeType="#{file.mime}"
                                    createContent="#{uploadAndCrop.paint}" value="#{row}"
                                    style="width:156x; height:71px;" cacheable="false">
                                    <f:param value="#{uploadAndCrop.timeStamp}" name="time" />
                                    <s:conversationId />
                                </a4j:mediaOutput>

                            </h:panelGrid>
                        </rich:panel>
                    </rich:dataGrid>
                </rich:panel>
                <rich:spacer height="3" />
                <br />
                <a4j:commandButton action="#{uploadAndCrop.clearUploadData}"
                    reRender="info, upload" value="Clear Uploaded Image" />
            </h:panelGroup>


            <h:panelGroup id="cropgroup">
                <rich:panel rendered="#{uploadAndCrop.newImage}">
                    <f:facet name="header">
                        <h:outputText value="Crop Image" />
                    </f:facet>
                    <a4j:outputPanel id="crop" layout="inline">
                        <rich:jQuery selector="#cropbox" timing="immediate"
                            query="Jcrop()" />
                        <a4j:mediaOutput element="img"
                            mimeType="#{uploadAndCrop.tempImageStore.mime}" id="cropbox"
                            createContent="#{uploadAndCrop.paintCrop}" value="null"
                            style="width:312; height:142px;" cacheable="false">
                            <f:param value="#{uploadAndCrop.timeStamp}" name="time" />
                            <s:conversationId />
                        </a4j:mediaOutput>
                        <rich:spacer height="3" />
                        <br />
                        <a4j:commandButton action="#{uploadAndCrop.clearUploadData}"
                            reRender="info, upload" value="Crop" />
                    </a4j:outputPanel>
                </rich:panel>
            </h:panelGroup>


        </h:panelGrid>

        <h:commandButton id="save" value="Save"
            action="#{uploadAndCrop.save}">
            <f:param name="cmsCompanyIdCom" value="" />
        </h:commandButton>
        <s:button id="cancelEdit" value="Cancel" propagation="end"
            view="/CmsCompany.xhtml">
            <f:param name="cmsCompanyIdCom" value="" />
        </s:button>
    </h:form>

    <ui:remove>
        <rich:modalPanel id="croppanel" width="350" height="240">
            <f:facet name="header">
                <h:panelGroup>
                    <h:outputText value="Crop Image"></h:outputText>
                </h:panelGroup>
            </f:facet>
            <f:facet name="image">
                <ui:remove>
                    <h:panelGroup>
                        <h:outputText value="close" />
                        <rich:componentControl for="croppanel" attachTo="close"
                            operation="hide" event="onclick" />
                    </h:panelGroup>
                </ui:remove>
            </f:facet>

            <rich:panel rendered="#{uploadAndCrop.newImage}">
                <ui:remove>
                    <f:facet name="header">
                        <h:outputText value="Crop Image" />
                    </f:facet>
                </ui:remove>
                <a4j:outputPanel id="crop" layout="inline">

                    <a4j:mediaOutput element="img"
                        mimeType="#{uploadAndCrop.tempImageStore.mime}" id="cropbox"
                        createContent="#{uploadAndCrop.paintCrop}" value="null"
                        style="width:312; height:142px;" cacheable="false">
                        <f:param value="#{uploadAndCrop.timeStamp}" name="time" />
                        <s:conversationId />
                    </a4j:mediaOutput>


                    <ui:remove>
                        <rich:spacer height="3" />
                        <br />
                        <a4j:commandButton action="#{uploadAndCrop.clearUploadData}"
                            reRender="info, upload" value="Crop" />
                    </ui:remove>
                </a4j:outputPanel>
            </rich:panel>

            <a onclick="Richfaces.hideModalPanel('croppanel');" href="#">Hide
            ModalPanel</a>
        </rich:modalPanel>
    </ui:remove>

</ui:define>

<代码>

Im trying to create a page that uses the rich:fileUpload, to (surprisingly) upload an image, once the upload is completed I want to 'hide' the rich:fileUpload component and display the jQuery plugin jCrop so that the image can be cropped before saving. once the image is saved from the crop selected, the two components should toggle their viewability again.

However, I dont appear to be able to get the rich:fileUpload to 'hide'. the jCrop component displays fine, as does the jCrop functionality. but no matter what I try rich:fileUpload is still displayed on the screen. Actually if I add rendered="#{!uploadAndCrop.newImage}"to the rich:panel that the rich:fileUpload is in, nothing seems to update. I have to remove this for the jCrop component to appear.

My code is below, it is a little messy as ive tried so many different things. Would be extremely grateful if someone could point me in the right direction with this, or advise a better way of doing it.

Thanks

<ui:define name="head">
    <link href="stylesheet/jquery.Jcrop.css" rel="stylesheet"
        type="text/css" />

    <script type="text/javascript" src="scripts/jquery-1.4.4.min.js"></script>
    <script type="text/javascript" src="scripts/jquery.Jcrop.js"></script>

    <script language="Javascript">// <![CDATA[ //
     {      
        var $J = jQuery.noConflict();
     }
    //]]> //</script>


</ui:define>

<ui:define name="body">
    <h:form>
        <h:panelGrid columns="2" columnClasses="top,top">

            <h:panelGroup id="uploadgroup">
                <a4j:outputPanel id="uploadpanel">
                    <rich:panel rendered="#{!uploadAndCrop.newImage}">
                        <rich:fileUpload fileUploadListener="#{uploadAndCrop.listener}"
                            maxFilesQuantity="#{uploadAndCrop.uploadsAvailable}" id="upload"
                            immediateUpload="#{uploadAndCrop.autoUpload}"
                            acceptedTypes="jpg, gif, png, bmp"
                            allowFlash="#{uploadAndCrop.useFlash}" listHeight="80px">
                            <ui:remove>
                                onfileuploadcomplete="Richfaces.showModalPanel('croppanel');">
                            </ui:remove>
                            <a4j:support event="onuploadcomplete"
                                reRender="info, uploadgroup, cropgroup" />
                        </rich:fileUpload>
                        <h:outputText value="#{uploadAndCrop.newImage}" id="newimage" />
                        <a onclick="Richfaces.showModalPanel('croppanel');" href="#">Show
                        ModalPanel</a>
                    </rich:panel>
                </a4j:outputPanel>
            </h:panelGroup>



            <h:panelGroup id="info">
                <rich:panel bodyClass="info" rendered="#{!uploadAndCrop.newImage}">
                    <f:facet name="header">
                        <h:outputText value="Uploaded Image Preview" />
                    </f:facet>

                    <rich:dataGrid columns="1" value="#{uploadAndCrop.files}"
                        var="file" rowKeyVar="row">
                        <rich:panel bodyClass="rich-laguna-panel-no-header">
                            <h:panelGrid columns="2">
                                <a4j:mediaOutput element="img" mimeType="#{file.mime}"
                                    createContent="#{uploadAndCrop.paint}" value="#{row}"
                                    style="width:156x; height:71px;" cacheable="false">
                                    <f:param value="#{uploadAndCrop.timeStamp}" name="time" />
                                    <s:conversationId />
                                </a4j:mediaOutput>

                            </h:panelGrid>
                        </rich:panel>
                    </rich:dataGrid>
                </rich:panel>
                <rich:spacer height="3" />
                <br />
                <a4j:commandButton action="#{uploadAndCrop.clearUploadData}"
                    reRender="info, upload" value="Clear Uploaded Image" />
            </h:panelGroup>


            <h:panelGroup id="cropgroup">
                <rich:panel rendered="#{uploadAndCrop.newImage}">
                    <f:facet name="header">
                        <h:outputText value="Crop Image" />
                    </f:facet>
                    <a4j:outputPanel id="crop" layout="inline">
                        <rich:jQuery selector="#cropbox" timing="immediate"
                            query="Jcrop()" />
                        <a4j:mediaOutput element="img"
                            mimeType="#{uploadAndCrop.tempImageStore.mime}" id="cropbox"
                            createContent="#{uploadAndCrop.paintCrop}" value="null"
                            style="width:312; height:142px;" cacheable="false">
                            <f:param value="#{uploadAndCrop.timeStamp}" name="time" />
                            <s:conversationId />
                        </a4j:mediaOutput>
                        <rich:spacer height="3" />
                        <br />
                        <a4j:commandButton action="#{uploadAndCrop.clearUploadData}"
                            reRender="info, upload" value="Crop" />
                    </a4j:outputPanel>
                </rich:panel>
            </h:panelGroup>


        </h:panelGrid>

        <h:commandButton id="save" value="Save"
            action="#{uploadAndCrop.save}">
            <f:param name="cmsCompanyIdCom" value="" />
        </h:commandButton>
        <s:button id="cancelEdit" value="Cancel" propagation="end"
            view="/CmsCompany.xhtml">
            <f:param name="cmsCompanyIdCom" value="" />
        </s:button>
    </h:form>

    <ui:remove>
        <rich:modalPanel id="croppanel" width="350" height="240">
            <f:facet name="header">
                <h:panelGroup>
                    <h:outputText value="Crop Image"></h:outputText>
                </h:panelGroup>
            </f:facet>
            <f:facet name="image">
                <ui:remove>
                    <h:panelGroup>
                        <h:outputText value="close" />
                        <rich:componentControl for="croppanel" attachTo="close"
                            operation="hide" event="onclick" />
                    </h:panelGroup>
                </ui:remove>
            </f:facet>

            <rich:panel rendered="#{uploadAndCrop.newImage}">
                <ui:remove>
                    <f:facet name="header">
                        <h:outputText value="Crop Image" />
                    </f:facet>
                </ui:remove>
                <a4j:outputPanel id="crop" layout="inline">

                    <a4j:mediaOutput element="img"
                        mimeType="#{uploadAndCrop.tempImageStore.mime}" id="cropbox"
                        createContent="#{uploadAndCrop.paintCrop}" value="null"
                        style="width:312; height:142px;" cacheable="false">
                        <f:param value="#{uploadAndCrop.timeStamp}" name="time" />
                        <s:conversationId />
                    </a4j:mediaOutput>


                    <ui:remove>
                        <rich:spacer height="3" />
                        <br />
                        <a4j:commandButton action="#{uploadAndCrop.clearUploadData}"
                            reRender="info, upload" value="Crop" />
                    </ui:remove>
                </a4j:outputPanel>
            </rich:panel>

            <a onclick="Richfaces.hideModalPanel('croppanel');" href="#">Hide
            ModalPanel</a>
        </rich:modalPanel>
    </ui:remove>

</ui:define>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

指尖上的星空 2024-10-13 06:38:09

我不知道你的 uploadAndCrop.newImage 方法怎么样,但你可以只使用一个布尔值并将其设置为 false 在 fileUploadListener 上。

但重新渲染 ,而不是 或组。

<a4j:outputPanel id="uploadpanel" rendered="#{bean.fileUpRendered}">
   (...)

   <rich:fileUpload...
      <a4j:support event="onuploadcomplete"
                            reRender="info, uploadpanel, cropgroup" />
   </rich:fileUpload>

   (...)
</a4j:outputPanel>

豆:

Boolean fileUpRendered;

(...)

public void listener(UploadEvent event) throws Exception {
   try {
      (...)

      fileUpRendered = false;
   catch (...) { (...) }

}

//Get set
public get/set fileUpRendered() { }...

I dont know how is your uploadAndCrop.newImage method, but you can just use a boolean and sets it to false on the fileUploadListener.

But reRender the <a4j:outputPanel id="uploadpanel">, not the <rich:fileUpload> or the group.

<a4j:outputPanel id="uploadpanel" rendered="#{bean.fileUpRendered}">
   (...)

   <rich:fileUpload...
      <a4j:support event="onuploadcomplete"
                            reRender="info, uploadpanel, cropgroup" />
   </rich:fileUpload>

   (...)
</a4j:outputPanel>

Bean:

Boolean fileUpRendered;

(...)

public void listener(UploadEvent event) throws Exception {
   try {
      (...)

      fileUpRendered = false;
   catch (...) { (...) }

}

//Get set
public get/set fileUpRendered() { }...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文