I have in my JSP page code like this:
<spring:url value="" var="url"/>
EN
And issue is that parameter url in link is always set to empty String.I would expect that if I type url like localhost:8080/test the url variable will hold this value and it will be replaced in link so it would look like /change_locale?locale=EN¤t=test. However it is always generated like /change_locale?locale=EN¤t=.What I am doing wrong? Best regards
In
<spring:url value="" var="url"/>
Your value value is the empty String. Because of this, the URL is relative.
Spring uses UrlTag to construct the value from a <url> tag. You'll want to take a look at its createUrl method in the source code if you're curious.
In this case, it will generate a value that is the empty String and store it in a page scope attribute named url. That's what you get when rendering
${url}
Related
I'm new to Go and trying to modify some code written by someone else. Right now he tests the stored value of a given day to determine if someone took lunch that day or not.
What I want to do is see if there's a stored value and if there isn't, use the default value which is passed via URL parameter. The code looks like this:
<input id="lunch{{.place}}" type="checkbox" {{if index .week.NoMeals .place}} checked {{end}}>
I have a URL variable set like so:
sitename?nolunch=1
So the logic I want is that if the stored data for that day is set, the checkbox will reflect the stored value. If it hasn't been set, the box should be checked if the nolunch URL parameter is set and not checked if it's not.
How do I test for url parameters in Go template code?
I am converting some plain HTML to using spring form tags.Although it looks like
spring form input does not have the attribute type. I was able to successfully
pass a hidden variable as follows:
<form:input type="hidden" name="displayId" id="displayIdentifier" path="displayIdentifier" value="${value1}"/>
Earlier the plain HTML was as follows:
<input type="hidden" name="displayId" id="displayIdentifier" value="${value1}"/>
I looked online and saw that the for:input does not have the type attribute, yet it seems to be working correctly.
The input tag is declared with
<dynamic-attributes>true</dynamic-attributes>
That allows passing dynamic attributes, not explicitely declared in the tag. The tag simply stores their name and value and writes them as is on the generated HTML input. That allows adding a type, or a data attribute, or any attribute you want to the tag.
See http://docs.oracle.com/javaee/6/api/javax/servlet/jsp/tagext/DynamicAttributes.html for more information.
A jstl variable is set in request scope in a jsp
<c:set var="name" value="Tiger" scope="request" />
This variable is accessed from a jspf included to this jsp. Now, is there any difference in accessing the variable in these two ways ?
1) <c:out value="${name}" />
2) <c:out value="${requestScope.name}" />
When to use requestScope ?
You use requestScope when you absoluetely want your object to come from the request, and not from the page, session or application scope. Inded, using ${name} will search for a name attribute in the page, then in the request, then in the session, then in the application.
Let's say that some other code in the JSP set a name attribute in the page scope. But you want to access the name in the request: you're forced to use requestScope.
Let's say the session might have a name attribute. Not using requestScope.name would return the session-scoped name if the JSP forgot to set the name attribute in the request scope.
If the goal of the JSP fragment is to access something set in the enclosing JSP, maybe this JSP fragment should be a JSP tag, and you should pass the name as an argument to this tag.
Within my research (I am also new one for jstl),
request scope can set values to request page from response page for example assume that we have a page called index.jsp and its action page is index_action.jsp
if we, set values to the action page
<c:set var="nme" scope="request" value="Janaka aravinda"/>
<% request.getRequestDispatcher("index.jsp").forward(request, response); %>
(// I created nme variable and set its value as Janaka aravinda. and back to reload request page(index.jsp) )
Now we can call nme in index.jsp nme variable as follow
Request value
<c:out value="${nme}"/>
I am trying to write some kind of raw html to mimic what spring mvc tag produces after page rendering(and I do make them look exactly the same if you open them with a html element inspector). as I want to create dynamic input form using javascript. but it didn't work. it seems I had to use only what it offers: e.g. <form:input path="firstName" />.
to get the data binding working.
I thought the tag lib only help you to produce a html block that spring knows how to handle them in backend (action). from a web http perspective. what else it can send beyond a bunch of form data, and they should send the same thing. so I am really curious to learn what magic thing the tag lib dose beyond producing a html block.
the other thing I would like to know is where the model object is being hold when the form is being submit to a matched action. you know, you can get the model attribute by using #modelAttribute as the input parameter. is it in the original request object? or in the ActionRequest to which the dispatcherServlet build and put it. or even somewhere else?
thanks in advance.
I got it figured out. the raw html just works as spring tag does. as long as you are in the form tag block. you are okay to use raw html such as
<input type="text" id="abc" name="abc"/> just make sure name reflect your bean attribute path.
id is not mandatory and is just helping you to identify the very element. I guess I missed something when I work with the raw html by the time I ask the question. hope this helps for guys working with raw html approach, especially in case of dynamic input creation.
Not sure if this can be done but it seems my main issue is because i have a default route to a method called "index." I want to be able to list all users tagged with a specific keyword. In addition, users can search for other users based on these keywords.
i.e.
www.domain.com/tags/apples
www.domain.com/tags/oranges
www.domain.com/tags/blueberry
It works fine if I go to the URL manually. I'm having issues getting it to work with a form field.
Snippet of the form_open:
<?=form_open('tags/');?>
<p>Search for Tag: <input type="text" name="tag" /></p>
<p><input type="submit" value="Search" /></p>
Here's a snippet of my controller:
function index() {
$data['result'] = $this->tags_model->searchByTag($this->uri->segment(2));
$this->load->view('tags_view', $data);
}
Here's a snippet of my router:
$route['tags'] = "tags/index";
$route['tags/(:any)'] = "tags/index/$1";
Now, I can easily fix all this if I have a method called search, but I don't want the URL to show up as www.domain.com/tags/search/orange.
When you create your form you set it to use POST variables instead of GET, that way they don't go through the url, that's codeigniter's default method for forms.
So your form_open code will generate the following code:
<form method="post" action="tags/" />
If you want them to got through url though, call the form opener this way instead:
form_open('tags/', array('method' => 'get'));
The same applies to any other attributes you want to specify for the form, just follow the same pattern attribute_name => attribute_value inside the array.
More info on the user guide
The problem here is that your form will be submitting all it's data to "/tags", with nothing trailing it, as POST data doesn't come in as part of the URL. Even if it was a GET request however, I don't think that CodeIgniter will take anything out of the querystring and use it as part of the routing segments.
I think what you should do is have a small Javascript function that automatically updates the form action parameter to be tags/<select option value> whenever the select value is changed. This way it will submit to the right place. In order to handle non-javascript enabled browsers, you could have a default action called tags/search that would simply analyze your form data and put out a 301 redirect to the proper tags/<location> once you'd figured it out.
It seems like a bit of overkill here however, as you could really point the form at tags/index and not worry about it. I'm not sure search engines index form submission locations, and even if they did, they certainly wouldn't index a form that submits to dynamic URIs in the way that you want it to. You could still link to the search result pages using tags/apples, etc, but the form could work quite normally just by going to tags/index.
I ended up redirecting the URL and passed the keyword into the URI.
i.e. domain.com/tags/view/