I want to substring a variable which is my JPA class id field and then add it to an URL in Thymeleaf.
My URL is like
/Myapplication/sortddoc/value=__${entity.id}__
So I need to do something like
${entity.id}.substr(0, 8)
before concatenating it to the URL.
I tried to create a new Transient field in my entity class containing the substring variable but it doesn't work because it seems like to need database field that I cant provide.
Can Anyone help me, please ?
You should be doing this with Thymeleaf's standard URL syntax, instead of concatenating string variables or using preprocessing (there is no need for either of those).
<a th:with="${value=#strings.substring(entity.id,0,8)}"
th:href="#{/Myapplication/sortddoc/(value=${value})}"></a>
or
<a th:href="#{/Myapplication/sortddoc/(value=${#strings.substring(entity.id,0,8)})}"></a>
Related
I am new in this environment and i just want to ask somebody if it is possible to get the string value not the index value using string[] array as a parameter?
Below are those images: ajax pass this data into controller
I am using ajax to pass my data in to the url controller in c# mvc.
By the way, here's my sample array data: prepared data..
the highlighted one is my array and in my parameter in mvc # is declared as string [] methodParam: highlighted parameter,
Those not highlighted parameter are working. all i want to do is getting one by one string in methodParam. i tried to use this
GetMethodParam.IndexOf("Date").ToString() but the output is -1 which probably not available in context.
i just want to get each string and its value because i send it to the email outlook..
like this. enter image description here.
Any Suggestions, clarification or comments is highly appreciated. Thank you ;) .
You don't need the individual input in data on ajax call, just use the last one UserHeader
and in Acton(C#) use a model as argument with containing all attributes of UserHeader.
Or, remove UserHeader from data and Use each attributes as individual argument in C# Action with same name.
In my app, many of my translation string need to include the user name in them.
For example: Hello {{user_name}}!
(User name has to be part of the translation string since the position of the name in the string depends on the language))
The way to set attributes is {{"TRANSLATE_ID" | translate:{user_name:myUserName}}}
Since {{user_name}} appears in more than 100 translation strings, I don't want to send the user_name parameter so many times. I'd like to have a way to set this parameter only one.
I can't replace the {{user_name}} string in the config because the user_name is set asynchronously (fetched from the server) and isn't available when translateProvider sets the strings.
Thanks
AngularTranslate allows you to translate tags from the html itself or inside the controller through a promise. I believe the elegant way to do what you want is to create a method/function in your controller that handles the translation in the way you want and then call this method/function in your html passing the username as a parameter.
Address the username in your JSON translation files as "USERNAME" for instance, such as "Hello, USERNAME!", do the translation in a method created in your controller using AngularTranslate and then do a string replacement changing the word USERNAME for the method parameter (the real username) and use this string as the method's return value, which will be called in your html.
Hope this helps.
This is a javascript geo-target code:
<script src='http://promos.fling.com/geo/txt/location.php?testip='></script>
Is possible add the results of it in the end of URL?
Fairfield, CT
The javascript result put after ?q=
Thanks!
You can assign a value to location.search. Anything you assign gets placed in front of the ?. You may need additional parsing to extract or append specific values and reconstruct it to form a query string. Note that the page will refresh when doing so.
On some of my pages, I have a hash in the url like this: http://localhost/#/products/6959
How can I check if I have a product ID available and so I can save it in a variable to use later? Any help would be greatly appreciated!
You want a regexp to extract the number at the end of the url in javascript?
"http://localhost/#/products/6959".match(/[0-9]+$/);
Edit: Or if you want to make sure this is products:
"http://localhost/#/products/6959".match(/products\/([0-9]+$)/)[1]);
The parenthesis indicate a matching group that you find in [1].
You should be able to get that id out of the URL through accessing the params variable. In this case, params[:id] should do the trick.
Also, I do not recommend using a regex.
I get some strings from an external source, and I display them in spans on my page.
I need a way to get back to those strings using document.getElementById() or jQuery's $("#XXXX"), so along with each string I get some sort of an identifier, I use that identifier as the ID of the span.
The problem is that the identifier I get could contain chars like + for example. Which is not allowed as a value for the id attribute http://www.w3schools.com/tags/att_standard_id.asp
Additionally, these identifiers are case-sensitive. So I thought of using a hashing function like SHA or MD5, to hash the identifiers I get, then use them as ids for my spans, and I can apply the hashing function again to find my element.
This seems complicated for such a simple functionality. Is there a better way to do this? or maybe a very simple hashing function that would guarantee id-friendly chars and case-sensitivity? (HTML's id is not case-sensitive, that's another reason to consider hashing functions)
Can you ditch the identifier you get and just implement something simple like this:
var counter = 0;
function uniqueId(){
return "Id" + ++counter;
}
You could just increment the id's with a number and some sort of string to begin the ID.
The span id's would be "a1", "a2" etc.
I'm guessing that the problem is that you're thinking later you'll be getting the same strings and will want to transform them in the same way, and then use these to find the original corresponding elements?
If so, you'll just need to sanitize your strings carefully. A series of regular expressions could help you map from invalid to valid characters, and make the capitals unique. For instance, you could transform "A" into "-a-", and "+" into "-plus-".
A carefully chosen scheme should guarantee that the chances of a collision (i.e. someone giving you a string that looks like an escaped version of another string) should be very small, and in any case, detectable immediately.