Search in sources :

Example 1 with MutableRenderParameters

use of javax.portlet.MutableRenderParameters in project liferay-blade-samples by liferay.

the class UserController method submitApplicant.

@ActionMapping
public void submitApplicant(@ModelAttribute("user") User user, BindingResult bindingResult, ModelMap modelMap, Locale locale, ActionResponse actionResponse, SessionStatus sessionStatus) {
    _localValidatorFactoryBean.validate(user, bindingResult);
    if (!bindingResult.hasErrors()) {
        if (_logger.isDebugEnabled()) {
            _logger.debug("firstName=" + user.getFirstName());
            _logger.debug("lastName=" + user.getLastName());
        }
        MutableRenderParameters mutableRenderParameters = actionResponse.getRenderParameters();
        mutableRenderParameters.setValue("javax.portlet.action", "success");
        sessionStatus.setComplete();
    } else {
        bindingResult.addError(new ObjectError("user", _messageSource.getMessage("please-correct-the-following-errors", null, locale)));
    }
}
Also used : ObjectError(org.springframework.validation.ObjectError) MutableRenderParameters(javax.portlet.MutableRenderParameters) ActionMapping(com.liferay.portletmvc4spring.bind.annotation.ActionMapping)

Example 2 with MutableRenderParameters

use of javax.portlet.MutableRenderParameters in project liferay-faces-bridge-impl by liferay.

the class Tests method getRequestContentLengthTest.

// Test 6.144
@BridgeTest(test = "getRequestContentLengthTest")
public String getRequestContentLengthTest(TestBean testBean) {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    Bridge.PortletPhase portletRequestPhase = BridgeUtil.getPortletRequestPhase(facesContext);
    if (portletRequestPhase == Bridge.PortletPhase.ACTION_PHASE) {
        ExternalContext externalContext = facesContext.getExternalContext();
        ActionRequest actionRequest = (ActionRequest) externalContext.getRequest();
        ActionResponse actionResponse = (ActionResponse) externalContext.getResponse();
        MutableRenderParameters renderParameters = actionResponse.getRenderParameters();
        renderParameters.setValue("getRequestContentLengthTest", Boolean.valueOf(actionRequest.getContentLength() == externalContext.getRequestContentLength()).toString());
        return "multiRequestTestResultRenderCheck";
    } else if (portletRequestPhase == Bridge.PortletPhase.HEADER_PHASE) {
        ExternalContext externalContext = facesContext.getExternalContext();
        HeaderRequest headerRequest = (HeaderRequest) externalContext.getRequest();
        RenderParameters renderParameters = headerRequest.getRenderParameters();
        if (Boolean.valueOf(renderParameters.getValue("getRequestContentLengthTest"))) {
            testBean.setTestResult(true, "externalContext.getRequestContentLength() returned the expected value");
        } else {
            testBean.setTestResult(false, "externalContext.getRequestContentLength() did not return the expected value");
        }
        testBean.setTestComplete(true);
        if (testBean.getTestStatus()) {
            return Constants.TEST_SUCCESS;
        } else {
            return Constants.TEST_FAILED;
        }
    }
    return "";
}
Also used : FacesContext(javax.faces.context.FacesContext) ActionRequest(javax.portlet.ActionRequest) ExternalContext(javax.faces.context.ExternalContext) MutableRenderParameters(javax.portlet.MutableRenderParameters) HeaderRequest(javax.portlet.HeaderRequest) MutableRenderParameters(javax.portlet.MutableRenderParameters) RenderParameters(javax.portlet.RenderParameters) Bridge(javax.portlet.faces.Bridge) ActionResponse(javax.portlet.ActionResponse) BridgeTest(com.liferay.faces.bridge.tck.annotation.BridgeTest)

Example 3 with MutableRenderParameters

use of javax.portlet.MutableRenderParameters in project liferay-faces-bridge-impl by liferay.

the class ActionURLDemoPortlet method processAction.

@Override
public void processAction(ActionRequest actionRequest, ActionResponse actionResponse) throws PortletException, IOException {
    ActionParameters actionParameters = actionRequest.getActionParameters();
    String viewState = null;
    for (String actionParameterName : actionParameters.getNames()) {
        // necessary to iterate through the action parameter names in order to find the view state parameter.
        if (actionParameterName.contains(ResponseStateManager.VIEW_STATE_PARAM)) {
            viewState = actionParameters.getValue(actionParameterName);
            break;
        }
    }
    String nonFacesPostback = actionParameters.getValue("Non-Faces-Postback");
    if ((viewState == null) && ("true".equalsIgnoreCase(nonFacesPostback))) {
        MutableRenderParameters mutableRenderParameters = actionResponse.getRenderParameters();
        mutableRenderParameters.setValue("Non-Faces-Postback", nonFacesPostback);
        String foo = actionParameters.getValue("foo");
        if (foo != null) {
            mutableRenderParameters.setValue("foo", foo);
        }
    } else {
        super.processAction(actionRequest, actionResponse);
    }
}
Also used : ActionParameters(javax.portlet.ActionParameters) MutableRenderParameters(javax.portlet.MutableRenderParameters)

Example 4 with MutableRenderParameters

use of javax.portlet.MutableRenderParameters in project liferay-faces-bridge-impl by liferay.

the class ActionURLDemoPortlet method doView.

@Override
protected void doView(RenderRequest renderRequest, RenderResponse renderResponse) throws PortletException, IOException {
    RenderParameters renderParameters = renderRequest.getRenderParameters();
    String nonFacesPostback = renderParameters.getValue("Non-Faces-Postback");
    if (nonFacesPostback == null) {
        super.doView(renderRequest, renderResponse);
    } else {
        PrintWriter writer = renderResponse.getWriter();
        writer.write("<p>");
        writer.write("Successfully executed ");
        writer.write("<strong>non-JSF postback</strong> in ");
        writer.write(ActionURLDemoPortlet.class.getName());
        writer.write("</p>");
        String foo = renderParameters.getValue("foo");
        writer.write("<p>");
        writer.write("Action Parameter:<pre>foo=" + foo + "</pre>");
        writer.write("</p>");
        PortletURL renderURL = renderResponse.createRenderURL();
        MutableRenderParameters mutableRenderParameters = renderURL.getRenderParameters();
        mutableRenderParameters.setValue("componentPrefix", "portlet");
        mutableRenderParameters.setValue("componentName", "actionurl");
        mutableRenderParameters.setValue("componentUseCase", "general");
        writer.write("<p>");
        writer.write("<a href=\"");
        writer.write(renderURL.toString());
        writer.write("\">");
        writer.write("Return to portlet:actionURL in the Liferay Faces Showcase");
        writer.write("</a>");
        writer.write("</p>");
    }
}
Also used : MutableRenderParameters(javax.portlet.MutableRenderParameters) MutableRenderParameters(javax.portlet.MutableRenderParameters) RenderParameters(javax.portlet.RenderParameters) PortletURL(javax.portlet.PortletURL) PrintWriter(java.io.PrintWriter)

Aggregations

MutableRenderParameters (javax.portlet.MutableRenderParameters)4 RenderParameters (javax.portlet.RenderParameters)2 BridgeTest (com.liferay.faces.bridge.tck.annotation.BridgeTest)1 ActionMapping (com.liferay.portletmvc4spring.bind.annotation.ActionMapping)1 PrintWriter (java.io.PrintWriter)1 ExternalContext (javax.faces.context.ExternalContext)1 FacesContext (javax.faces.context.FacesContext)1 ActionParameters (javax.portlet.ActionParameters)1 ActionRequest (javax.portlet.ActionRequest)1 ActionResponse (javax.portlet.ActionResponse)1 HeaderRequest (javax.portlet.HeaderRequest)1 PortletURL (javax.portlet.PortletURL)1 Bridge (javax.portlet.faces.Bridge)1 ObjectError (org.springframework.validation.ObjectError)1