All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.thymeleaf.spring4.expression.RequestDataValues Maven / Gradle / Ivy

/*
 * =============================================================================
 * 
 *   Copyright (c) 2011-2016, The THYMELEAF team (http://www.thymeleaf.org)
 * 
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 * 
 *       http://www.apache.org/licenses/LICENSE-2.0
 * 
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 * 
 * =============================================================================
 */
package org.thymeleaf.spring4.expression;

import java.util.Map;

import org.thymeleaf.context.ITemplateContext;
import org.thymeleaf.spring4.requestdata.RequestDataValueProcessorUtils;

/**
 * 

* Expression object that offers the functionality of Spring MVC's RequestDataValueProcessor for * performing last-moment modifications to request data values such as URLs or form contents in order to * enable mechanism such as CSRF protection. *

*

* Methods in this class correspond to the methods in Spring MVC's * org.springframework.web.servlet.support.RequestDataValueProcessor. *

*

* Using this expression object is not needed in most scenarios, as its functionality will be automatically * applied by th:href, th:src, th:action, th:value, th:method * and th:field. But sometimes there is a need to manually apply these behaviours when e.g. creating * and using URLs outside attributes such as th:href or th:src. *

*

* An example of such scenario would be using an URL as a parameter in a message expression: *

* * msg.knowmore=Click <a href="{0}">here</a> if you want to know more. * *

* And then in template code: *

* * <p th:with="morelink=@{/detail/more}" * th:utext="#{msg.knowmore(${#requestdatavalues.url(morelink)})}"> * * * @author Daniel Fernández * * @since 3.0.0 * */ public class RequestDataValues { private ITemplateContext context; public RequestDataValues(final ITemplateContext context) { super(); this.context = context; } public String action(final String action, final String httpMethod) { return RequestDataValueProcessorUtils.processAction(this.context, action, httpMethod); } public String url(final String url) { return RequestDataValueProcessorUtils.processUrl(this.context, url); } public String formFieldValue(final String name, final String value, final String type) { return RequestDataValueProcessorUtils.processFormFieldValue(this.context, name, value, type); } public Map extraHiddenFields() { return RequestDataValueProcessorUtils.getExtraHiddenFields(this.context); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy