PLS Help - a4j:CommandButton call converters when submit a d
timgozag Sep 19, 2009 2:05 AMIn my application, I have to disable a rich:calendar component using Java script. This calendar component has a converter attached to it. When I submit the form using a4j:commandButton, even though the component is disabled, it still called the converter which causes errors on my apps.
I tested with h:commandButton and it works fine. JSF h:commmandButton does not call converter when it submits a disabled component.
Why a4j:commandButton behaves differently? Is this a Richfaces bug? Is there anyway I can work around this issue? I very appreciate your help!!
Here is my test code example. In this example, I use h:commandButton as well as a4j:commandButton. First, enter something in rich:calendar's input date. Then click on Disable button to call a javascript to disable the rich calendar. Then click on either h_commandButton or a4j_commandButton. Notice that when a4j_commandButton is clicked, it calls the dateTimeConverter while h_commandButton does not.
<a4j:form id="test123">
<rich:calendar id="dateCalendarId" enableManualInput="true" datePattern="dd/MM/yyyy" value="#{testBean.dateValue}">
<f:converter converterId="dateTimeConverter"/>
</rich:calendar>
<h:commandButton value="h_CommandButton" actionListener="#{testBean.submitValue}" />
<a4j:commandButton value="a4j_CommandButton" actionListener="#{testBean.submitValue1}" />
</a4j:form>
<h:commandButton onclick="disableMe(true);" value="Disable"/>
<h:commandButton onclick="disableMe(false);" value="Enable"/>
<script type="text/javascript">
//<![CDATA[
function disableMe(flag) { document.getElementById('test123:dateCalendarIdInputDate').disabled=flag;}
//]]>
</script>
</ui:composition>
Here is a simple backing Bean:
@Name("testBean")
public class TestConverterBean {
private Object dateValue;
public Object getDateValue() { return this.dateValue; }
public void setDateValue(Object dateValue) { this.dateValue = dateValue;}
public void submitValue(final ActionEvent event) { }
public void submitValue1(final ActionEvent event) { }
}
Not only rich:calendar, I tested on inputText with converter --> same result:
<a4j:form id="test123">
<h:inputText id="inputTextId" value="#{testBean.value}">
<f:converter converterId="myConverter"/>
</h:inputText><br/>
<h:commandButton value="h_CommandButton" actionListener="#{testBean.submitValue}" />
<a4j:commandButton value="a4j_CommandButton" actionListener="#{testBean.submitValue1}" />
</a4j:form>
<h:commandButton onclick="disableMe(true);" value="Disable"/>
<h:commandButton onclick="disableMe(false);" value="Enable"/>
<script type="text/javascript">
//<![CDATA[
function disableMe(flag) {
document.getElementById('test123:inputTextId').disabled=flag;
}
//]]>
</script>
</ui:composition>
And here is a simple converter:
@Name("myConverter")
@org.jboss.seam.annotations.faces.Converter
@BypassInterceptors
public class MyConverter implements Converter {
public Object getAsObject(@SuppressWarnings("unused") FacesContext fc, @SuppressWarnings("unused") UIComponent uiComp, String string) {
return string + " test123";
}
public String getAsString(@SuppressWarnings("unused") FacesContext fc, @SuppressWarnings("unused") UIComponent uiComp, Object obj) {
return obj.toString();
}
}