0

I have a submit button on top that's normally doing a partial refresh of the form.

When I added a fileUpload control that won't due, as I need to do a full refresh. But I only wish this to happen if the user has added a file to be uploaded. So if the file Upload is empty I want to use a partialRefresh to submit.

I can check if a file is added easily enough and I could have two buttons with different refresh modes and hide them using JS, but that's a clunky solution.

What I would like to do is change the refresh mode on the submit button depending on a submitted value in the current form.

Any ideas?

Thanks!

/J

jBoive
  • 1,219
  • 1
  • 14
  • 40

2 Answers2

6

You can do this by adding a second event handler to your button: One event handler is for a full refresh, the other one for the partial refresh.

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">

   <xp:div id="divRefresh">
      <xp:label value="#{javascript:java.lang.System.currentTimeMillis()}" id="label1" />
      <xp:label value="#{javascript:java.lang.System.currentTimeMillis()}" id="label2" />
   </xp:div>

   <xp:br></xp:br>

   <xp:button value="Refresh" id="button1">
      <xp:eventHandler event="onclick" submit="true"
         refreshMode="complete">
            <xp:this.script>
               <![CDATA[alert("Complete!"); return false;]]>
            </xp:this.script>
      </xp:eventHandler>
      <xp:eventHandler event="onclick" submit="true"
         refreshMode="partial" refreshId="label2">
            <xp:this.script>
               <![CDATA[alert("Partial!");return true;]]>
            </xp:this.script>
      </xp:eventHandler>
   </xp:button> 

</xp:view>

The CSJS code in the events has to return false to stop the event.

Sven Hasselbach
  • 10,455
  • 1
  • 18
  • 26
  • I suspected as much, but didn't realise that you could prevent the SSJS event by using CSJS. Worked like a charm! Thanks! – jBoive Nov 22 '12 at 09:08
1

I do this in http://www.intrapages.com when posting new stream content.

in the onchange event for the upload control I set a requestScope variable. and if that is set I perform a full refresh. works great

enter image description here

Community
  • 1
  • 1
Thomas Adrian
  • 3,543
  • 6
  • 32
  • 62