예제 #1
0
  // used in ITFocusValidationAware#testGlobalMessageIsIgnored
  public void createGlobalMessageAndCheckFocus() {
    FacesContext context = FacesContext.getCurrentInstance();
    AbstractFocus comp = getComponent();
    FocusRendererBase renderer = getRenderer();

    // form should be focused
    final String expectedFocusCandidates = "form";
    String actualFocusCandidates = renderer.getFocusCandidatesAsString(context, comp);
    if (!expectedFocusCandidates.equals(actualFocusCandidates)) {
      createGlobalMessageAndCheckFocusResult =
          MessageFormat.format(
              "Only form should be focused. Expected focus candidates <{0}>, but have: <{1}>.",
              expectedFocusCandidates, actualFocusCandidates);
      return;
    }

    // create global message
    context.addMessage(null, new FacesMessage("global message"));

    // form should be still focused
    actualFocusCandidates = renderer.getFocusCandidatesAsString(context, comp);
    if (!expectedFocusCandidates.equals(actualFocusCandidates)) {
      createGlobalMessageAndCheckFocusResult =
          MessageFormat.format(
              "Only form should be focused. Expected focus candidates <{0}>, but have: <{1}>.",
              expectedFocusCandidates, actualFocusCandidates);
      return;
    }
    createGlobalMessageAndCheckFocusResult = PASSED;
  }
예제 #2
0
  // used in ITFocusValidationAware#testValidateMultipleInputsDuringFormSubmission and
  // ITFocusValidationAware#testValidateMultipleInputsDuringAjax
  public void invalidateBothInputsAndCheckFocus() {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    AbstractFocus comp = getComponent();
    FocusRendererBase renderer = getRenderer();

    // assert intial focus on form
    String expectedFocusCandidates = "form";
    String actualFocusCandidates = renderer.getFocusCandidatesAsString(facesContext, comp);
    if (!expectedFocusCandidates.equals(actualFocusCandidates)) {
      invalidateBothInputsAndCheckFocusResult =
          MessageFormat.format(
              "Only form should be focused. Expected focus candidates <{0}>, but have: <{1}>.",
              expectedFocusCandidates, actualFocusCandidates);
      return;
    }

    // invalidate first two inputs
    for (String invalidate : new String[] {"form:input1", "form:input2"}) {
      facesContext.addMessage(invalidate, new FacesMessage("invalidated " + invalidate));
    }

    if (!facesContext.getClientIdsWithMessages().hasNext()) {
      invalidateBothInputsAndCheckFocusResult = "Messages should be generated.";
      return;
    }

    // assert focus on first input
    expectedFocusCandidates = "form:input1 form:input2";
    actualFocusCandidates = renderer.getFocusCandidatesAsString(facesContext, comp);
    if (!expectedFocusCandidates.equals(actualFocusCandidates)) {
      invalidateBothInputsAndCheckFocusResult =
          MessageFormat.format(
              "First input should be focused. Expected focus candidates <{0}>, but have: <{1}>.",
              expectedFocusCandidates, actualFocusCandidates);
      return;
    }
    invalidateBothInputsAndCheckFocusResult = PASSED;
  }
예제 #3
0
 public String getFocusCandidates() {
   FacesContext context = FacesContext.getCurrentInstance();
   FocusRendererBase renderer = getRenderer();
   return renderer.getFocusCandidatesAsString(context, component);
 }