Get session attribute having attribute name in a constants file - session

I want to get a session attribute from xhtml file. I know that if you put the attribute name like this #{sessionAttributeName.field} it works but my problem comes when I try to get the attribute name from a constants file.
I've imported the constants file with <p:importConstants type="Constants" var="constants"/>
I've tried get the attribute using #{constants.constantAttributeName.field} (constantAttributeName value is sessionAttributeName) but, how I expected, it doesn't work.
Is it possible get the session attribute using the constant with another method or another way to do this?
I could put directly the attribute name in all xhtml files, but if it changes, I should change all files.
Do you have idea?

I've solved it. I've used #{sessionScope[constants.constantAttributeName].field} and now it's working.

Related

org.thymeleaf.exceptions.TemplateProcessingException: Only variable expressions returning numbers or booleans are allowed in this context

I have been using thymeleaf th:onclick attribute to call javascript function with parameters as below
th:onclick="|myFunction('${parameter1}')|"
But with thymeleaf 3.1.10 this has been removed. and they are suggesting to use th:data attribute.
I however found workaround on as below and both of them are working perfectly.
th:attr="onclick=|myFunction('${parameter1}')|"
th:onclick="#{myFunction('${parameter1}')}">
Now i am not sure if these workarounds are correct way to do things and if yes which one is the better way.
The first will work like you want -- however, you are bypassing the the security restriction and now your pages are vulnerable to javascript injection (which is the original reason this change was made).
The second one just plain doesn't work. It doesn't expand out the variable ${parameter1}, instead just encoding it as a url like this:
onclick="myFunction?$%7Bparameter1%7D"
You really should be doing it as shown on the page.
th:data-parameter1="${parameter1}" onclick="myFunction(this.getAttribute('data-parameter1'));"

How to display cookie value in JSF facelet (xhtml file) by using implicit object; "cookie"

I wrote a code as follows in JSF facelet(xhtml file)
${cookie}
If I run the xhtml file on a web app server. The below is displayed on the screen.
{JSESSIONID=javax.servlet.http.Cookie#faf91d8}
However, it seems to be the address of where the cookie instance is stored.
I want to see the value(sessionid) in the cookie.
I tried this code, but it did not work.
${cookie[value]}
I tried reading the following specifications in JCP, but I could not find the answer.
https://jcp.org/en/jsr/detail?id=372
Could you please tell me how to properly write a code to display a value in a cookie? I would appreciate your help.
As you can see from what is printed, it looks like a key-value pair and since the spec says it maps to a single cookie,
#{cookie['JSESSIONID']}
is what returns an actual single cookie. But you still need the value of it so
#{cookie['JSESSIONID'].value}
is most likely what you need
See also
http://incepttechnologies.blogspot.com/p/jsf-implicit-objects.html
https://docs.oracle.com/javase/7/docs/api/java/net/HttpCookie.html

Could you pls let me know how do i pass variable if the URL is dynamic based on your search value in jmeter?

When is search for an item by giving its id the url i get is http://aa.bb.com/bikes/2 or http://aa.bb.com/bikes/3,
the value after bikes is dynamic based on my search results and corresponding page is displayed. How do i parameterize this in Jmeter?
I am using HTTP request sampler.
I added a csv config file, gave different ids and added these values in the parameter part and used the parameter variable in the URL path. But it is not working.
EX: the url path i gave as /aa.bb.com/bikes/${id} but its not working.
You can add 'debug sampler' to narrow down the root cause.
i figured out the way to do this.
I just mentioned the possible id values in a csv file.
Used the variable name in the url.
Ex: I created a idValues.csv file and used this file in CSV data set config.
Gave the variable name as value.
now in the HttpSampler in the path i mentioned as http://aa.bb.com/bikes/${value} and it worked.
Thank you.

Joomla File Handling - Variable name not passed

I made a component with a "file" field type, but the content of that single field are not passed at all, I was under the impression it should save the file name as text at least, if I change the field type to "text" the name saves so I know everything else is functioning. All the other fields are being passed. What am I doing wrong?
File handling aside, I just want it to save the name.
A detailed explanation would be appreciated, or even better, can I get someone who knows what he's doing re-write this component using MVC so I can compare.
Thanks
Can't really help with what you have so far as you haven't provided any code, however our website have recently made a small simple component for Joomla 2.5 for file uploading using the SWFUpload framework, should you want to use it.
http://joomjunk.co.uk/products/component-home/swfupload.html

MVC3 razor remote validation - Controller argument is always empty

I can call the controller but the argument (string) is always null.
All the examples I have found name the controller argument the same as the property we are validating remotely, sounds good/easy, but if you look at fiddler what is really being passed in is the name attribute from the input statement. Well that is problematic in that it is a subscripted name something like Person.EMailAddresses[0].Address, well I can't name my controller parameter like that.
So how do I get around this? There must be a way to specify the controllers parameter name in the remote() attribute?
It cannot be done using the default RemoteAttribute. This is a link to an example I posted of a reusable remote validation attribute, where you can specify the name of the controller, action and the name of the variable used to pass the value to the action.

Resources