use of jakarta.faces.component.ActionSource2 in project faces by jakartaee.
the class BaseActionSource2TestServlet method actionSource2GetSetActionExpressionTest.
// init
// ------------------------------------------------------------ Test Methods
public void actionSource2GetSetActionExpressionTest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
request.setAttribute("bean", new SimpleBean());
ExpressionFactory factory = JspFactory.getDefaultFactory().getJspApplicationContext(servletContext).getExpressionFactory();
MethodExpression expression = factory.createMethodExpression(getFacesContext().getELContext(), "#{bean.action}", java.lang.String.class, new Class[] {});
ActionSource2 source2 = (ActionSource2) createComponent();
source2.setActionExpression(expression);
if (source2.getActionExpression() != expression) {
out.println(JSFTestUtil.FAIL + " Unexpected return value from" + " getActionExpression() after having just called" + " setActionExpression().");
out.println("Expected: " + expression);
out.println("Received: " + source2.getActionExpression());
return;
}
out.println(JSFTestUtil.PASS);
}
use of jakarta.faces.component.ActionSource2 in project faces by jakartaee.
the class BaseActionSourceTestServlet method actionSourceRemoveActListNPETest.
// ActionSource.removeActionListener() throws NullPointerException if
// ActionListener is null.
public void actionSourceRemoveActListNPETest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
ActionSource2 source = (ActionSource2) createComponent();
JSFTestUtil.checkForNPE(source.getClass(), "removeActionListener", new Class<?>[] { ActionListener.class }, new Object[] { null }, out);
}
use of jakarta.faces.component.ActionSource2 in project faces by jakartaee.
the class BaseActionSourceTestServlet method actionSourceGetSetActListTest.
// ActionSource.{set,get}ActionListener()
public void actionSourceGetSetActListTest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
request.setAttribute("actionListener", new ActionListener() {
public void processAction(ActionEvent event) throws AbortProcessingException {
// no-op
}
});
FacesContext context = getFacesContext();
ELContext elcontext = context.getELContext();
MethodExpression binding = getApplication().getExpressionFactory().createMethodExpression(elcontext, "#{requestScope.actionListener.processAction}", null, new Class[] { ActionEvent.class });
ActionSource2 source = (ActionSource2) createComponent();
MethodExpressionActionListener listener = new MethodExpressionActionListener(binding);
source.addActionListener(listener);
ActionListener[] result = source.getActionListeners();
if (result[0] != listener) {
out.println(JSFTestUtil.FAIL + " getActionListener() failed to return " + "the value set via setActionListener().");
out.println("Expected: " + binding);
out.println("Received: " + result);
return;
}
out.println(JSFTestUtil.PASS);
}
use of jakarta.faces.component.ActionSource2 in project faces by jakartaee.
the class BaseActionSourceTestServlet method actionSourceSetIsImmediateTest.
// ActionSource.{set,is}Immediate
public void actionSourceSetIsImmediateTest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
ActionSource2 source = (ActionSource2) createComponent();
if (source.isImmediate()) {
out.println(JSFTestUtil.FAIL + " Expected isImmediate() to return" + " false as the default value");
return;
}
source.setImmediate(true);
if (!source.isImmediate()) {
out.println(JSFTestUtil.FAIL + " Expected isImmediate() to return" + " true after having explicitly set it as such via" + " setImmediate()");
return;
}
source.setImmediate(false);
if (source.isImmediate()) {
out.println(JSFTestUtil.FAIL + " Expected isImmediate() to return" + " false after having explicitly set it as such via" + " setImmediate()");
return;
}
out.println(JSFTestUtil.PASS);
}
use of jakarta.faces.component.ActionSource2 in project myfaces by apache.
the class ActionListenerImpl method processAction.
@Override
public void processAction(ActionEvent actionEvent) throws AbortProcessingException {
FacesContext facesContext = actionEvent.getFacesContext();
Application application = facesContext.getApplication();
UIComponent component = actionEvent.getComponent();
MethodExpression methodExpression = null;
String fromAction = null;
String outcome = null;
if (component instanceof ActionSource2) {
// Must be an instance of ActionSource2, so don't look on action if the actionExpression is set
methodExpression = ((ActionSource2) component).getActionExpression();
}
if (methodExpression != null) {
fromAction = methodExpression.getExpressionString();
Object objOutcome = methodExpression.invoke(facesContext.getELContext(), null);
if (objOutcome != null) {
outcome = objOutcome.toString();
}
}
UIViewRoot root = facesContext.getViewRoot();
ViewPoolProcessor processor = ViewPoolProcessor.getInstance(facesContext);
ViewPool pool = (processor != null) ? processor.getViewPool(facesContext, root) : null;
if (pool != null && pool.isDeferredNavigationEnabled() && processor.isViewPoolStrategyAllowedForThisView(facesContext, root) && (PhaseId.INVOKE_APPLICATION.equals(facesContext.getCurrentPhaseId()) || PhaseId.APPLY_REQUEST_VALUES.equals(facesContext.getCurrentPhaseId()))) {
NavigationHandler navigationHandler = application.getNavigationHandler();
if (navigationHandler instanceof ConfigurableNavigationHandler) {
NavigationCase navigationCase = ((ConfigurableNavigationHandler) navigationHandler).getNavigationCase(facesContext, fromAction, outcome);
if (navigationCase != null) {
// Deferred invoke navigation. The first one wins
if (!facesContext.getAttributes().containsKey(ViewPoolProcessor.INVOKE_DEFERRED_NAVIGATION)) {
String toFlowDocumentId = (component != null) ? (String) component.getAttributes().get(ActionListener.TO_FLOW_DOCUMENT_ID_ATTR_NAME) : null;
if (toFlowDocumentId != null) {
facesContext.getAttributes().put(ViewPoolProcessor.INVOKE_DEFERRED_NAVIGATION, new Object[] { fromAction, outcome, toFlowDocumentId });
} else {
facesContext.getAttributes().put(ViewPoolProcessor.INVOKE_DEFERRED_NAVIGATION, new Object[] { fromAction, outcome });
}
}
}
}
} else {
NavigationHandler navigationHandler = application.getNavigationHandler();
String toFlowDocumentId = (component != null) ? (String) component.getAttributes().get(ActionListener.TO_FLOW_DOCUMENT_ID_ATTR_NAME) : null;
if (toFlowDocumentId != null) {
navigationHandler.handleNavigation(facesContext, fromAction, outcome, toFlowDocumentId);
} else {
navigationHandler.handleNavigation(facesContext, fromAction, outcome);
}
// Render Response if needed
facesContext.renderResponse();
}
}
Aggregations