5 Replies Latest reply on Jan 16, 2009 4:04 AM by ilya_shaikovsky

    onsubmit when button is protected with Javascript

    tony.herstell1

      Is there any reason the onsubmit would not cause the panel referred to to be re-drawn?

      <a4j:commandButton styleClass="general_form_button" id="deleteEvent" action="#{eventsController.deleteEvent(eachEvent)}"
       value="#{messages.general_button_delete}" type="submit" onclick="this.disabled=true;if (! window.confirm('Woah! This is delete; are you sure?')) { this.disabled=false; return false }"
       oncomplete="this.disabled=false">
       <a4j:support event="onsubmit" limitToList="true" reRender="pickinglistOfEvents"/>
      </a4j:commandButton>
      


        • 1. Re: onsubmit when button is protected with Javascript
          nbelaevski

          Hello,

          a4j:commandButton doesn't have onsubmit handler. Use onclick.

          • 2. Re: onsubmit when button is protected with Javascript
            tony.herstell1

            I tried onclick... but that didnt work either...
            I have a list of things, this button (delete) deletes an item from the list... but I cant get it to refresh the list ... if I cnt solve this I will make it go to a confirm screen and then back again I suppose.
            Will try onclick again when I get home.
            Cheers.

            • 3. Re: onsubmit when button is protected with Javascript
              tony.herstell1

              No onclick didnt work either.
              I will just force the user to another page and confirm the delete there.

              • 4. Re: onsubmit when button is protected with Javascript
                tony.herstell1

                How do I force the DataModel (eventList) to be re-calculated?

                Stepping through the code for deleteEntry does remove the entry from the eventList.


                 @DataModel(value="availableEvents")
                 private List<Event> eventList;
                


                 @TransactionAttribute(TransactionAttributeType.REQUIRED)
                 @Override
                 public void deleteEvent(Event event) {
                 em.remove(event);
                 eventList.remove(event);
                 }
                



                <a4j:form id="eventListItemsForm">
                
                 <br/>
                 <br/>
                
                 <div class="main_title">
                 <h:outputText value="#{messages.events_page}" />
                 </div>
                
                 <fieldset class="general_form_fieldset">
                
                 <legend class="general_form_legend">
                 <h:outputText value="#{messages.events_fieldset_events}" />
                 <a4j:commandButton styleClass="general_form_button" id="eventsNewEvent" type="submit"
                 value="#{messages.general_button_new}"
                 action="#{eventsController.createEvent()}" onclick="this.disabled=true"
                 oncomplete="this.disabled=false">
                 </a4j:commandButton>
                 </legend>
                
                 <h:outputText value="#{messages.events_no_events}" rendered="#{availableEvents.rowCount == 0}"/>
                
                 <a4j:outputPanel id="pickinglistOfEvents">
                 <rich:dataTable id="events_list" value="#{availableEvents}" var="eachEvent" columnClasses="center"
                 rows="20" width="100%" rendered="#{availableEvents.rowCount > 0}"
                 onRowMouseOver="this.style.backgroundColor='#F8F8F8'"
                 onRowMouseOut="this.style.backgroundColor='#{a4jSkin.tableBackgroundColor}'">
                 <f:facet name="header">
                 <h:outputText value="Events" />
                 </f:facet>
                
                 <rich:column sortBy="#{eachEvent.description}">
                 <f:facet name="header">
                 <h:outputText value="Description" />
                 </f:facet>
                 <h:outputText value="#{eachEvent.description}" />
                 </rich:column>
                 <rich:column sortBy="#{eachEvent.publicised}">
                 <f:facet name="header">
                 <h:outputText value="Publicised" />
                 </f:facet>
                 <s:graphicImage rendered="#{eachEvent.publicised}" url="/images/tick.gif" />
                 <s:graphicImage rendered="#{not eachEvent.publicised}" url="/images/cross.gif" />
                 </rich:column>
                 <rich:column sortBy="#{eachEvent.graded}">
                 <f:facet name="header">
                 <h:outputText value="Graded" />
                 </f:facet>
                 <s:graphicImage rendered="#{eachEvent.graded}" url="/images/tick.gif" />
                 <s:graphicImage rendered="#{not eachEvent.graded}" url="/images/cross.gif" />
                 </rich:column>
                 <rich:column sortBy="#{eachEvent.entriesCloseDate}">
                 <f:facet name="header">
                 <h:outputText value="Closing Date"/>
                 </f:facet>
                 <h:outputText value="#{eachEvent.entriesCloseDate}">
                 <s:convertDateTime pattern="dd/MMM/yyyy"/>
                 </h:outputText>
                 </rich:column>
                 <rich:column sortBy="#{eachEvent.dates.creationDate}">
                 <f:facet name="header">
                 <h:outputText value="Creation Date" />
                 </f:facet>
                 <h:outputText value="#{eachEvent.dates.creationDate}">
                 <s:convertDateTime pattern="dd/MMM/yyyy"/>
                 </h:outputText>
                 </rich:column>
                 <rich:column sortBy="#{eachEvent.eventWorkflowStateKind}">
                 <f:facet name="header">
                 <h:outputText value="Status" />
                 </f:facet>
                 <h:outputText value="#{messages[eachEvent.eventWorkflowStateKind.inlLabel]}"/>
                 </rich:column>
                 <rich:column>
                 <f:facet name="header">
                 <h:outputText value="Action" />
                 </f:facet>
                 <a4j:commandButton styleClass="general_form_button" id="viewEvent" action="#{eventsController.viewEvent(eachEvent)}"
                 value="#{messages.general_button_view}" type="submit" onclick="this.disabled=true"
                 oncomplete="this.disabled=false">
                 </a4j:commandButton>
                 <a4j:commandButton styleClass="general_form_button" id="updateEvent" action="#{eventsController.updateEvent(eachEvent)}"
                 value="#{messages.general_button_update}" type="submit" onclick="this.disabled=true"
                 oncomplete="this.disabled=false">
                 </a4j:commandButton>
                 <a4j:commandButton styleClass="general_form_button" id="deleteEvent" action="#{eventsController.deleteEvent(eachEvent)}"
                 value="#{messages.general_button_delete}" type="submit" onclick="this.disabled=true;if (! window.confirm('Woah! This is delete; are you sure?')) { this.disabled=false; return false }"
                 oncomplete="this.disabled=false">
                 <a4j:support event="onclick" limitToList="true" reRender="pickinglistOfEvents"/>
                 </a4j:commandButton>
                 </rich:column>
                 </rich:dataTable>
                
                 <rich:datascroller for="events_list" maxPages="30" rendered="#{availableEvents.rowCount > 0}"/>
                
                 </a4j:outputPanel>
                
                 </fieldset>
                
                 <br/>
                 <br/>
                
                 <a4j:commandButton styleClass="general_form_button" action="#{eventsController.cancel}"
                 value="#{messages.general_button_cancel}" immediate="true" type="submit">
                 </a4j:commandButton>
                
                 </a4j:form>
                



                • 5. Re: onsubmit when button is protected with Javascript
                  ilya_shaikovsky

                  Looks strange..

                  <a4j:commandButton value="Say Hello" reRender="out" onclick="if (!confirm('you sure?')) return false;"/>
                  


                  works just as you need on my side.