开发者

Cannot 'hide' rich:fileUpload

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"
                     开发者_如何学Go       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>


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() { }...
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜