Why Do I get Entity & in url formed with spring:url - spring-mvc

I am working with Spring MVC and I need to create a url with two parameters:
<spring:url value="/test" var="myUrl" >
<spring:param name="param1" value="1" />
<spring:param name="param2" value="2" />
</spring:url>
I get this: myUrl = /test?param1=1&amp ;param2=2 (note that this url have a entity &amp ; inside)
and when I put this url in a href=${myUrl} this don't work like I want.
Though, If I use c:url and c:param I get that I want :
<c:url value="/test" var="myUrl">
<c:param name="param1" value="1" />
<c:param name="param2" value="2" />
</c:url>
myUrl = /test?param1=1&param2=2
What is the problem with "spring:param" ? Do I need to configure some parameter in my Spring mvc configuration?
Thanks.

Related

Convert from Name of Bean and Name of Property to the property in JSP

I have a been called “FooOneBean” and that has a number of properties, one of which is “fooOnePropA’ which is a list of Foo objects.
In a Java Controller, this bean is set in the request as follows:
request.setAttibute(“FooOneBean”, FooOneBean.instance());
Normally, this can be used in a JSP to display the dropdown as follows:
<tiles:importAttribute name="elementName" />
<c:set var=”dropdown” value=”${FooOneBean.fooOnePropA}” /> <!—Name of the bean and property hard-coded here -- >
<form:select path="${elementName}" id="${elementName}">
<form:options items="${dropdown}" itemLabel="displayName" itemValue="code" />
</form:select>
However, what we have is a very generic JSP that should be able to display the dropdown based on the String name of the bean and property set in the JSP. The name of the bean or property can change based on how the JSP is invoked. So,
<tiles:importAttribute name="elementName" />
<tiles:importAttribute name="resourceBean" />
<tiles:importAttribute name="resourceList" />
<%--
<c:out value="${resourceBean}" /> <!—Displays “FooOneBean” -->
<c:out value="${resourceList}" /> <!—Displays “fooOnePropA” -->
--%>
<c:set var="beanName" value="${resourceBean}" />
<c:set var="propName" value="${resourceList}" />
<c:set var="dropdown" value="${beanName.propName }" />
<form:select path="${elementName}" id="${elementName}">
<form:options items="${dropdown}" itemLabel="displayName" itemValue="code" />
</form:select>
This will fail with the message: '${beanName.propName}' Property 'propName' not found on type java.lang.String
On the otherhand if dropdown is set as:
<c:set var="dropdown" value="${beanName}.${propName}" />
It fails with the error: Type [java.lang.String] is not valid for option items
How can this be accomplished in JSP? I am able to do this using Scriptlets that I want to avoid.
Thanks for the comments from JB Nizet. This can be done as:
<tiles:importAttribute name="elementName" />
<tiles:importAttribute name="resourceBean" />
<tiles:importAttribute name="resourceList" />
<c:set var="dropdown" value="${requestScope[resourceBean][resourceList]}”/>
<form:select path="${elementName}" id="${elementName}">
<form:options items="${dropdown}" itemLabel="displayName" itemValue="code" />
</form:select>

Create custom search form indexed_search TYPO3 v8

I'm trying to add a custom search form into my template, the TypoScript I used in a v7 install no longer works.
If I copy the Fluid form used in the extension (Form.html) and place it into one of my Fluid template a search box appears but it posts back to itself, even though I have set a rootPidList in my constants. This is the code I copy:
<f:form action="search" method="post" id="tx_indexedsearch" pageUid="{settings.targetPid}">
<div class="tx-indexedsearch-hidden-fields">
<f:form.hidden name="search[_sections]" value="0" />
<f:form.hidden name="search[_freeIndexUid]" id="tx_indexedsearch_freeIndexUid" value="_" />
<f:form.hidden name="search[pointer]" id="tx_indexedsearch_pointer" value="0" />
<f:form.hidden name="search[ext]" value="{searchParams.ext}" />
<f:form.hidden name="search[searchType]" value="{searchParams.searchType}" />
<f:form.hidden name="search[defaultOperand]" value="{searchParams.defaultOperand}" />
<f:form.hidden name="search[mediaType]" value="{searchParams.mediaType}" />
<f:form.hidden name="search[sortOrder]" value="{searchParams.sortOrder}" />
<f:form.hidden name="search[group]" value="{searchParams.group}" />
<f:form.hidden name="search[languageUid]" value="{searchParams.languageUid}" />
<f:form.hidden name="search[desc]" value="{searchParams.desc}" />
<f:form.hidden name="search[numberOfResults]" value="{searchParams.numberOfResults}" />
<f:form.hidden name="search[extendedSearch]" value="{searchParams.extendedSearch}" />
</div>
<fieldset>
<legend><f:translate key="form.legend" /></legend>
<div class="tx-indexedsearch-form">
<label for="tx-indexedsearch-searchbox-sword"><f:translate key="form.searchFor" />:</label>
<f:form.textfield name="search[sword]" value="{sword}" id="tx-indexedsearch-searchbox-sword" class="tx-indexedsearch-searchbox-sword" />
</div>
<div class="tx-indexedsearch-search-submit">
<f:form.submit name="search[submitButton]" value="{f:translate(key: 'form.submit')}" id="tx-indexedsearch-searchbox-button-submit" class="tx-indexedsearch-searchbox-button" />
</div>
</fieldset>
And my typoscript:
config.index_enable = 1
page.config.index_enable = 1
plugin.tx_indexedsearch.settings.targetPid = 31
If I add the stock indexed search plugin to a random page, this will work.
Just to rule it out, I've also disable realurl just in case.
Thanks again T3 community.
if you just copy the search template into your output/ page template, there is no plugin available which provides values for the specific variables needed in this template-part.
either you use an output of a page where you have inserted the plugin (copy from HTML-source)
or you insert the plugin in all pages:
this can be done with a column you inherit and where the plugin is inserted on top level
or you use typoscript to render the plugin into a fluid-variable and display the generated HTML in your (page-)template.

How to use spring mvc controller make a post request?

How to make a controller method to redirect to other site with a post request?
#RequestMapping("/link)
public RedirectView goToTheSite(ModelMap model) {
model.put("name", "wow");
return new RedirectView("https://www.thesite.com", true, false, false);
}
but, this is not working,
How to do that in right way?
How to make a controller method to redirect to other site with a post
request?
Redirect means you telling browser to make a GET request, There is no out of the box feature in Spring MVC to make POST request from controller.
How to do that in right way?
Use Apache HTTP client:
Request.Post("https://www.thesite.com/login")
.bodyForm(Form.form().add("username", "vip").add("password", "secret").build())
.execute().returnContent();
The only way to send a POST is to send a populated HTML form to the browser, with the action parameter pointing to the new site and method="POST".
<form name="myform" action="https://www.thesite.com" method="post">
<input name="name" type="hidden" value="true" />
<input name="phone" type="hidden" value="false" />
<input name="phone" type="hidden" value="false" />
<noscript>
<input type="submit" value="Click here to continue" />
</noscript>
</form>
Then Add javascript to automatically submit the form :
<script type="text/javascript">
$(document).ready(function() {
document.myform.submit();
});
</script>

Having trouble with form requests

I've setup two pages. 1.aspx, and 2.aspx.
on 1.aspx I have a form like so:
<form action="2.aspx" method="post" id="myform">
<input type="hidden" value="this works" id="mydata" />
<input type="submit" />
</form>
on 2.aspx I have this code:
Response.Write(Request.Form("mydata"))
This returns nothing.
I also tried
Response.Write(Request.Form(0))
but I get "Index was out of range." Message from the server.
I know I'm probably missing something very simple, but, I can't seem to find it!
What am I doing wrong?
Thanks!
ID is used for client-side access. Give your hidden field name="mydata" for server-side form access
Instead of having
<input type="hidden" value="this works" id="mydata" />
have
<input type="hidden" value="this works" name="mydata" />
IF you want to keep id instead of name you have to write it out differently.
you want to use document.getElementById instead of Request.form

Handle HTML array input elements

I know in PHP we can easily create something like this to handle HTML array elements:
<input name="test[0]" value="1" />
<input name="test[1]" value="2" />
<input name="test[2]" value="3" />
Then in code I can access this as an array:
$arrElements = $_POST['test'];
echo $arrElements[0]; // prints: 1
I have been trying to do the same in ASP.NET (Web Applications). But unfortunately this (also) doesn't work that easy.
So if i use the same HTML as above, i then tried to do the following in my CodeBehind:
var test = Request.Form.GetValues("test");
But this results in test being null. Is there anyway to handle HTML array elements like i can with PHP?
Change your html :
<input name="test" value="1" />
<input name="test" value="2" />
<input name="test" value="3" />
code behind :
var test = Request.Form.GetValues("test");
And now you will get array of values in test var.
If you can't change html you can use this code :
var testList = new List<string>();
foreach (string key in Request.Form.AllKeys)
{
if (key.StartsWith("test[") && key.EndsWith("]"))
{
testList.Add(Request.Form[key]);
}
}

Resources