"Required" attribute results in action not being executed
sam-user Oct 18, 2010 6:31 AMHello,
I have an application based on Seam 2.1.1 and Richfaces 3.3.1 and I came across to a rather strange thing.
I have a field where the users enter a value. This value is used to pupulate another field from the form. The second field is a "required" field.
The problem is that if the user types a value in the first field and then submits the form by clicking directly to the submit button, then the action on the "oncomplete" event is not executed.
The code below is a simplified version of the actual code, but it behaves exactly the same way - if I enter a value in field1 and click directly on "Submit" -
.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich"
xmlns:s="http://jboss.com/products/seam/taglib"><ui:composition template="layout/template.xhtml">
<ui:define name="body">
<h:form>
<h:panelGrid columns="2">
<s:decorate id="codeField" template="layout/edit.xhtml">
<ui:define name="label">Code </ui:define>
<h:inputText value="#{test.s}" valueChangeListener="#{test.action1}" id="field1">
<a4j:support event="onblur" reRender="codeField" ajaxSingle="true"/></h:inputText>
<h:inputText value="#{test.valueOfBean}" id="outtext" required="true"/>
</s:decorate></h:panelGrid>
<h:panelGrid columns="2">
<a4j:commandButton action="#{test.action2}" value="Submit"
eventsQueue="q1" oncomplete="#{test.action3()}" />
</h:panelGrid>
</h:form>
</ui:define>
</ui:composition></html>
package come.package;
import javax.faces.event.ValueChangeEvent;
import org.jboss.seam.Component;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;@Name("test")
@Scope(ScopeType.CONVERSATION)
public class Test
{
private String s;
public void action1(ValueChangeEvent event)
{System.out.println("Executing action 1");
String c= (String) event.getNewValue();
setValueOfBean(c);
}
public void action2()
{
System.out.println("Executing action 2");
}public String getS() {
return s;
}public void setS(String s) {
System.out.println("Setting the valueOfBean to " + s);
this.s = s;
}private String valueOfBean;
public String getValueOfBean() {
return valueOfBean;
}public void setValueOfBean(String valueOfBean) {
System.out.println("Setting the valueOfBean to " + valueOfBean);
this.valueOfBean = valueOfBean;
}
public void action3()
{
System.out.println("Executing action 3");
}
}
The action "test.action2" of the command button is not executed and I get a warning saying
INFO [lifecycle] WARNING: FacesMessage(s) have been enqueued, but may not have been displayed.
sourceId=j_id30:codeField:outtext[severity=(ERROR 2), summary=(value is required), detail=(value is required)]
I tried using queues, but that didn't change anything.
If I remove the required attribute from field "outtext" however, test.action2 is executed.
Could someone tell me if this is a bug or if there's something wrong with the code.
Thanks.