voyent
ReferenceError: submit is not defined  XML
Forum Index -> General Help
Author Message
futhark77

Joined: 18/Sep/2009 00:00:00
Messages: 57
Offline


In one of my forms, I have a check box that's used to enable or disable a date control. I have found the value change listener is called no more than two times when checking / unchecking the box repeatedly (not frantically clicking). The third time I click the box, the form does not get submitted and I find the following error in my javascript console:

ReferenceError: submit is not defined

The problem occurs even after trimming my jsf and bean to the bone.

This is with ICEFaces 3.1.0. Can someone explain what is happening?

The JSF:

Code:
    <?xml version='1.0' encoding='UTF-8' ?>
 
 <ui:composition template="/WEB-INF/xhtml/MainTemplate.xhtml"
                 xmlns="http://www.w3.org/1999/xhtml"
                 xmlns:ice="http://www.icesoft.com/icefaces/component"
                 xmlns:icecore="http://www.icefaces.org/icefaces/core"
                 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:c="http://java.sun.com/jsp/jstl/core">
 	<ui:define name="content">
 
     <ice:form id="f">
 
       <ice:selectBooleanCheckbox id="cb" value="#{form.customPastDate}" 
                                      onchange="submit()"
                                      immediate="true"
                                      valueChangeListener="#{form.updateCustomDateCheckbox}" />
       
 		</ice:form>
 
 	</ui:define>	
 </ui:composition>
 
 


The bean:


Code:
 package x.y;
 
 import java.io.Serializable;
 import javax.faces.bean.ManagedBean;
 import javax.faces.bean.RequestScoped;
 
 @ManagedBean(name="form")
 @RequestScoped
 public class Form
 {
   private boolean customPastDate;
   
 	public boolean isCustomPastDate()
 	{
 		return customPastDate;
 	}
 
 	public void setCustomPastDate(boolean customPastDate)
 	{
 		this.customPastDate = customPastDate;
 	}
 	
   public void updateCustomDateCheckbox(ValueChangeEvent event)
   {
     logger.debug("custom past date clicked");
     FacesContext.getCurrentInstance().renderResponse();    
   }	
 
 }
 

futhark77

Joined: 18/Sep/2009 00:00:00
Messages: 57
Offline


Maybe I am using the checkbox in a stupid way? I changed my app to use a select item instead of a checkbox,. It works as expected.
philip.breau


Joined: 08/May/2006 00:00:00
Messages: 2989
Offline


When it breaks, it's likely just because the DOM diff is erasing your submit function with the subsequent DOM update (you can verify this by looking at the network traffic and partial updates). Why not just use an <f:ajax> tag inside your checkbox instead of using the onchange handler directly?

If you really need to keep your submit function for other reasons, you may just need to protect it from the DOM diff. Try wrapping your form tag with an panelGroup. The extra element with an id might be enough to stop the DOM diff from percolating up to wherever it's going.

.
futhark77

Joined: 18/Sep/2009 00:00:00
Messages: 57
Offline


At first I was using singlesubmit. Something else didn't work as intended. Checking the box enabled my popup date component. But I needed two clicks to actually open the date popup.

I will have another look at f:ajax. My naive attempts have been unsuccessful.

Thank you!

EDIT: i was initially using singlesubmit, not partialsubmit.
futhark77

Joined: 18/Sep/2009 00:00:00
Messages: 57
Offline


Your suggestion to wrap the form inside a panel group didn't work.

The good news is I finally succeeded fixing my problem with f:ajax. With one caveat: I had to convert ice:selectBooleanCheckbox to h:selectBooleanCheckbox. Why didn't the ice tag work?

And more importantly, how to know when to use h tags instead of ice tags (other than when there is no ice equivalent) ? I have to say I am a bit puzzled when I see h tags instead of ice tags in tutorials.

Thanks again for your help!
philip.breau


Joined: 08/May/2006 00:00:00
Messages: 2989
Offline


Glad you got it working. The ice component probably has some other javascript handler that's interfering. The 'standard' ice components, like selectBooleanCheckbox are really legacy components from the JSF 1.x era. They were migrated to ICEfaces 2 and 3 to ease the migration of older ICEfaces apps, but it's usually best to stick with h: version for new development, unless the ice version has some extra features that you need.

Philip

.
futhark77

Joined: 18/Sep/2009 00:00:00
Messages: 57
Offline


Maybe my use of f:ajax is more complicated than necessary. Do I need PushRenderer at all on the server side to do simple component updates?

Not that adding 2 lines is hard, but it adds one concern: I have to minimally understand how push works to be confident updates won't be pushed to the wrong person. The less concerns there are, the easier it is to get started.
philip.breau


Joined: 08/May/2006 00:00:00
Messages: 2989
Offline


No, you just need Push when the user hasn't triggered the event. Otherwise they'll get the update anyway.

.
futhark77

Joined: 18/Sep/2009 00:00:00
Messages: 57
Offline


The ajax update does not work for my ice:selectInputDate component. When I click the checkbox to enable the date, I have an exception:

Code:
 SEVERE: ICEfaces rendering required by icefaces-compat.jar components. Enable via <icecore:config render="true" />.
 java.lang.UnsupportedOperationException: ICEfaces rendering required.
 	at com.icesoft.faces.context.DOMContext.attachDOMContext(DOMContext.java:93)
 	at com.icesoft.faces.component.selectinputdate.SelectInputDateRenderer.encodeEnd(SelectInputDateRenderer.java:194)
 	at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
 	at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1763)
 	at org.icefaces.impl.context.DOMPartialRenderCallback.visit(DOMPartialViewContext.java:622)
 	at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:183)
 	at javax.faces.component.UIComponent.visitTree(UIComponent.java:1589)
 	at javax.faces.component.UIComponent.visitTree(UIComponent.java:1600)
 	at javax.faces.component.UIComponent.visitTree(UIComponent.java:1600)
 	at javax.faces.component.UIComponent.visitTree(UIComponent.java:1600)
 	at javax.faces.component.UIForm.visitTree(UIForm.java:344)
 	at javax.faces.component.UIComponent.visitTree(UIComponent.java:1600)
 	at javax.faces.component.UIComponent.visitTree(UIComponent.java:1600)
 	at org.icefaces.impl.context.DOMPartialViewContext.renderSubtrees(DOMPartialViewContext.java:371)
 	at org.icefaces.impl.context.DOMPartialViewContext.processPartial(DOMPartialViewContext.java:160)
 	at javax.faces.component.UIViewRoot.encodeChildren(UIViewRoot.java:981)
 	at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1756)
 	at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:390)
 	at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
 	at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
   ...
 


Adding the tag to the page does not work. I shouldn't need it anyway, since I have:

Code:
org.icefaces.render.auto: true [default]


The ajax update works fine if I replace the selectInputDate with a simpler control (ex: h:inputtext).
philip.breau


Joined: 08/May/2006 00:00:00
Messages: 2989
Offline


That stack trace just means that the <ice:selectInputDate> doesn't support the f:ajax tag. You can try just using the partialSubmit attribute of the <ice:selectInputDate> or you can try the newer <ace:dateTimeEntry>.

Philip

.
futhark77

Joined: 18/Sep/2009 00:00:00
Messages: 57
Offline


I am back to square one. This is what I was doing initially.

Code:
 <icecore:singleSubmit>            
 <h:selectBooleanCheckbox value="#{form.customPastDate}"/>
 </icecore:singleSubmit>
 
 <ice:selectInputDate disabled="#{!inboundStatusForm.customPastDate}" .../>
 


Everytime I tick the checkbox, the form reloads and my date gets enabled/disabled. That's what I want. However, there is a small bug (and that's what I wanted to correct). The next click will not 'pass through'. For example:
- I need to click twice on the icon to open my selectInputDate popup
- I need to click twice to change the date in another selectInputDate on my page.
- I need to click twice to submit the form.

Do you know why this extra click is needed and how to fix it? That should have been my first question.
philip.breau


Joined: 08/May/2006 00:00:00
Messages: 2989
Offline


The <icecore:singleSubmit> isn't supposed to wrap components, you just put a single instance in the form and it has an effect on the form level:

Code:
 <h:form>
     <icecore:singleSubmit/>
      ....
 </h:form>
 


Sorry, why wasn't the singleSubmit working? Have you tried something like this:

Code:
  <h:form id="f">
      <ice:selectBooleanCheckbox id="cb" 
           value="#{form.customPastDate}" 
           partialSubmit="true" />
 
      <ice:selectInputDate ...
           disabled="#{form.customPastDate}"/>
        
  </h:form>
 


Try the simplest case first. Calling renderResponse() from the valueChangeListener might have not been what you wanted, because by doing that you're skipping the update models phase. And you only need to use immediate="true" if you need to bypass validation.

Philip

.
futhark77

Joined: 18/Sep/2009 00:00:00
Messages: 57
Offline


I had forgotten about partial submit. I was too focused on trying stuff I had read about.

Partial submit almost does the job. It enables/disables my date component correctly when I click the checkbox. Unfortunately it stops updating the date component once there are validation errors on the page (required fields). I tried a bunch of hacks and partialSubmit/immediate combinations that didn't work.

Yesterday I implemented an action listener toggle that works fine in all cases. Contrary to the checkbox+partial submit, clicking a button clears errors on the page. I will stick to that for now.

BTW, do you have any good JSF books to recommend? I am sure ICEFaces will be a lot easier to grasp when I have a proper understanding of jsf intricacies.

Thanks for your assistance!
philip.breau


Joined: 08/May/2006 00:00:00
Messages: 2989
Offline


We have a bunch of choices for JSF and ICEfaces training, including a lot of free recorded videos that you can check out.

http://www.icesoft.org/java/training/icefaces-training.jsf

I also recommend JSF 2: The Complete Reference.

Philip

.
 
Forum Index -> General Help
Go to:   
Powered by JForum 2.1.7ice © JForum Team