use of com.sun.ts.tests.jsf.api.jakarta_faces.component.common.TCKValueChangeListener in project faces by jakartaee.
the class TestServlet method setupTree.
private void setupTree(UIComponent root, UIData data) {
FacesContext fc = getFacesContext();
ELContext elContext = fc.getELContext();
// Attach our UIData to the view root
// UIData data = new UIData();
data.setId("data");
root.getChildren().add(data);
// Set up columns with facets and fields for each property
UIColumn column;
UICommand command;
UIInput input;
UIOutput output;
UIOutput label;
UIOutput constant;
column = new UIColumn();
column.setId("commandColumn");
label = new UIOutput();
label.setId("commandHeader");
label.setValue("Command Header");
column.getFacets().put("header", label);
label = new UIOutput();
label.setId("commandFooter");
label.setValue("Command Footer");
column.getFacets().put("footer", label);
command = new UICommand();
command.setId("command");
command.setValueExpression("value", getApplication().getExpressionFactory().createValueExpression(elContext, "#{foo.command}", Object.class));
column.getChildren().add(command);
data.getChildren().add(column);
command.addActionListener(new TCKDataActionListener());
column = new UIColumn();
column.setId("inputColumn");
label = new UIOutput();
label.setId("inputHeader");
label.setValue("Input Header");
column.getFacets().put("header", label);
label = new UIOutput();
label.setId("inputFooter");
label.setValue("Input Footer");
column.getFacets().put("footer", label);
input = new UIInput();
input.setId("input");
input.setValueExpression("value", getApplication().getExpressionFactory().createValueExpression(elContext, "#{foo.input}", Object.class));
column.getChildren().add(input);
data.getChildren().add(column);
input.addValidator(new TCKValidator());
input.addValueChangeListener(new TCKValueChangeListener());
column = new UIColumn();
column.setId("outputColumn");
label = new UIOutput();
label.setId("outputHeader");
label.setValue("Output Header");
column.getFacets().put("header", label);
label = new UIOutput();
label.setId("outputFooter");
label.setValue("Output Footer");
column.getFacets().put("footer", label);
output = new UIOutput();
output.setId("output");
output.setValueExpression("value", getApplication().getExpressionFactory().createValueExpression(elContext, "#{foo.output}", Object.class));
column.getChildren().add(output);
data.getChildren().add(column);
column = new UIColumn();
column.setId("constantColumn");
label = new UIOutput();
label.setId("constantHeader");
label.setValue("Constant Header");
column.getFacets().put("header", label);
label = new UIOutput();
label.setId("constantFooter");
label.setValue("Constant Footer");
column.getFacets().put("footer", label);
constant = new UIOutput();
constant.setId("constant");
constant.setValue("Constant Value");
column.getChildren().add(constant);
data.getChildren().add(column);
}
use of com.sun.ts.tests.jsf.api.jakarta_faces.component.common.TCKValueChangeListener in project faces by jakartaee.
the class TestServlet method uiInputBroadcastTest.
// ------------------------------------------- Test Methods ----
// ----------------------------------------------------------------- UIInput
// Test event queuing and broadcasting (any phase listeners)
public void uiInputBroadcastTest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
FacesContext facesContext = getFacesContext();
UIInput input = (UIInput) createComponent();
UIViewRoot root = facesContext.getApplication().getViewHandler().createView(facesContext, "/root.xhtml");
root.getChildren().add(input);
ValueChangeEvent event = new ValueChangeEvent(input, null, null);
event.setPhaseId(PhaseId.PROCESS_VALIDATIONS);
// Register three listeners
input.addValueChangeListener(new TCKValueChangeListener("AP0"));
input.addValueChangeListener(new TCKValueChangeListener("AP1"));
input.addValueChangeListener(new TCKValueChangeListener("AP2"));
// Fire events and evaluate results
TCKValueChangeListener.trace(null);
input.queueEvent(event);
root.processDecodes(facesContext);
root.processValidators(facesContext);
root.processApplication(facesContext);
String trace = TCKValueChangeListener.trace();
String expectedTrace = "/AP0@PROCESS_VALIDATIONS/AP1@PROCESS_VALIDATIONS/AP2@PROCESS_VALIDATIONS";
if (!expectedTrace.equals(trace)) {
out.println(JSFTestUtil.FAIL + " Unexpected listener trace.");
out.println("Expected trace: " + expectedTrace);
out.println("Trace received: " + trace);
return;
}
out.println(JSFTestUtil.PASS);
}
use of com.sun.ts.tests.jsf.api.jakarta_faces.component.common.TCKValueChangeListener in project faces by jakartaee.
the class TestServlet method uiInputValidate3bTest.
public void uiInputValidate3bTest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
UIInput input = (UIInput) createComponent();
FacesContext context = getFacesContext();
UIViewRoot root = getApplication().getViewHandler().createView(context, "/root.xhtml");
context.setViewRoot(root);
root.getChildren().add(input);
// Verify that a UIInput instance that has a local value,
// and the valid property is true all validators associated
// with the component are invoked, if the component is marked
// invalid by a validator, no listener is invoked.
input.setSubmittedValue("previous");
// Setup the validators
TCKValidator validator1 = new TCKValidator("VL1", false);
TCKValidator validator2 = new TCKValidator("VL2", true);
input.addValidator(validator1);
request.setAttribute("TCKValidator", validator2);
ELContext context2 = context.getELContext();
MethodExpression binding = getApplication().getExpressionFactory().createMethodExpression(context2, "#{requestScope.TCKValidator.validate}", null, new Class[] { FacesContext.class, UIComponent.class, Object.class });
MethodExpressionValidator validator = new MethodExpressionValidator(binding);
input.addValidator(validator);
// Setup the listeners
TCKValueChangeListener listener = new TCKValueChangeListener("VCL1");
input.addValueChangeListener(listener);
input.setSubmittedValue("new-value");
TCKValueChangeListener.trace(null);
TCKValidator.clearTrace();
root.processValidators(context);
// All validators succeed, and the value differs from the previous.
// ensure the listener was invoked.
validator2.markInvalid(false);
TCKValueChangeListener.trace(null);
TCKValidator.clearTrace();
input.setValid(true);
root.processValidators(context);
String valTrace = TCKValidator.getTrace();
if (!"/VL1/VL2".equals(valTrace)) {
out.println(JSFTestUtil.FAIL + " Validator trace did not return as " + "expected.");
out.println("Traced expected: /VL1/VL2");
out.println("Trace received: " + valTrace);
return;
}
String listenerTrace = TCKValueChangeListener.trace();
if (!"/VCL1@ANY_PHASE".equals(listenerTrace)) {
out.println(JSFTestUtil.FAIL + " Unexpected listener trace.");
out.println("Expected: /VCL1@ANY_PHASE");
out.println("Received: " + listenerTrace);
return;
}
out.println(JSFTestUtil.PASS);
}
use of com.sun.ts.tests.jsf.api.jakarta_faces.component.common.TCKValueChangeListener in project faces by jakartaee.
the class TestServlet method uiInputBroadcastValueChangeListenerTest.
public void uiInputBroadcastValueChangeListenerTest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
FacesContext facesContext = getFacesContext();
UIInput input = (UIInput) createComponent();
UIViewRoot root = new UIViewRoot();
root.getChildren().add(input);
TCKValueChangeListener listener = new TCKValueChangeListener("VCLR");
ELContext context2 = facesContext.getELContext();
MethodExpression binding = getApplication().getExpressionFactory().createMethodExpression(context2, "#{requestScope.reqVCL.processValueChange}", null, new Class[] { ValueChangeEvent.class });
request.setAttribute("reqVCL", listener);
MethodExpressionValueChangeListener lnr = new MethodExpressionValueChangeListener(binding);
input.addValueChangeListener(lnr);
ValueChangeEvent event = new ValueChangeEvent(input, null, null);
event.setPhaseId(PhaseId.PROCESS_VALIDATIONS);
TCKValueChangeListener.trace(null);
input.queueEvent(event);
root.processDecodes(facesContext);
root.processValidators(facesContext);
root.processApplication(facesContext);
String trace = TCKValueChangeListener.trace();
if (trace.length() == 0) {
out.println(JSFTestUtil.FAIL + " The ValueChangeListener as referenced" + " by ValueChangeListenerRef 'requestScope.reqVCL.processValueChange'" + " was not invoked.");
return;
}
if (!"/VCLR@PROCESS_VALIDATIONS".equals(trace)) {
out.println(JSFTestUtil.FAIL + " Unexpected Listener trace.");
out.println("Expected: /VCLR@PROCESS_VALIDATIONS");
out.println("Received: " + trace);
return;
}
out.println(JSFTestUtil.PASS);
}
use of com.sun.ts.tests.jsf.api.jakarta_faces.component.common.TCKValueChangeListener in project faces by jakartaee.
the class TestServlet method uiInputValidate3aTest.
public void uiInputValidate3aTest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
UIInput input = (UIInput) createComponent();
FacesContext context = getFacesContext();
UIViewRoot root = getApplication().getViewHandler().createView(context, "/root.xhtml");
context.setViewRoot(root);
root.getChildren().add(input);
// Verify that a UIInput instance that has a local value,
// and the valid property is true all validators associated
// with the component are invoked, if the component is marked
// invalid by a validator, no listener is invoked.
input.setSubmittedValue("previous");
// Setup the validators
TCKValidator validator1 = new TCKValidator("VL1", false);
TCKValidator validator2 = new TCKValidator("VL2", true);
input.addValidator(validator1);
request.setAttribute("TCKValidator", validator2);
ELContext context2 = context.getELContext();
MethodExpression binding = getApplication().getExpressionFactory().createMethodExpression(context2, "#{requestScope.TCKValidator.validate}", null, new Class[] { FacesContext.class, UIComponent.class, Object.class });
MethodExpressionValidator validator = new MethodExpressionValidator(binding);
input.addValidator(validator);
// Setup the listeners
TCKValueChangeListener listener = new TCKValueChangeListener("VCL1");
input.addValueChangeListener(listener);
input.setSubmittedValue("new-value");
TCKValueChangeListener.trace(null);
TCKValidator.clearTrace();
root.processValidators(context);
String valTrace = TCKValidator.getTrace();
if (!"/VL1/VL2".equals(valTrace)) {
out.println(JSFTestUtil.FAIL + " Validator trace did not return as " + "expected.");
out.println("Traced expected: /VL1/VL2");
out.println("Trace received: " + valTrace);
return;
}
String listenerTrace = TCKValueChangeListener.trace();
if (listenerTrace.length() != 0) {
out.println(JSFTestUtil.FAIL + " ValueChangeListener was incorrectly" + " invoked after a Validator marked the component as invalid.");
return;
}
out.println(JSFTestUtil.PASS);
}
Aggregations