I am trying to do the following:
rendered="#{billBean.company.equals("something")}"
But the problem is I cannot write "something" inside #{}. It causes the below XML parsing error:
Element type "h:commandLink" must be followed by either attribute specifications, ">" or "/>".
How can I achieve this?
Use single quote (') to refer to a plain String inside EL:
rendered="#{billBean.company.equals('something')}"
Related
I am trying to replace an entire description string contained in an XML file. I would like to replace that string with a variable. I am using a SED command within a Groovy script.
I have the following code. I am expecting the string "foo" to replace the description text but it doesn't.
Instead the following line causes the XML to change to:
Description="sDescription"
What am I doing wrong?
def sDescription = "foo"
def sedCommand = 'sed -i \'s/Description="[^"]*"/Description="'$sDescription'"/g\' package.appxmanifest' as String
In Groovy variable/expression substitution inside of strings (interpolation) only works with certain types of string literal syntax. Single quote syntax ('content') is not one of them. However, if you replace the outer single quotes with double quotes ("content") then you should get the interpolation effect you are looking for:
def sDescription = "foo"
def sedCommand = "sed -i 's/Description=\"[^\"]*\"/Description=\"$sDescription\"/g\' package.appxmanifest" as String
This should give you the string that contains the command you wish to run. Please note how I changed the special character escaping (\) within the string to reflect the change in string delimiters.
Aside: As noted by #tim_yates, Why would you want to invoke a separate ad hoc process to do this substitution when Groovy contains excellent XML manipulation facilities built into the language?
I have inherited a cookbook that sets some attributes in the ./attributes/default.rb file as per normal.
However, we have a problem with one of the lines is, which is:
default["obscured"]["mysql"] = "#{node['jboss']['jboss_home']}/modules/com/mysql/jdbc/main"
When run, it write this into the node as:
{}/com/mysql/jdbc/main
I can confirm that the node['jboss']['jboss_home'] attribute exists and has correct values.
So, I cannot see any problem with the above, except that every other declaration of this type in our cookbooks has single quotes on the attribute to be set (i.e. left side), not double quotes. I haven't heard this of as being an issue before, but I am pretty new to chef.
Is there any rule that says they must be single quotes?
The answer is that there is no rule.
Using double-quotes in something like this is completely fine:
default["obscured"]["mysql"] = blah blah
The reason I know that is that I just found one being set, with double quotes, that actually works. :-)
What you have there is fine, how are you confirming the value of node['jboss']['jboss_home'] and how are you using it in the template?
In Ruby single and double quoted literals both become Strings but single quotes are relatively literal while double quotes allow backslash escapes and #{} interpolation.
You are most likely hitting the derived attributes problem:
https://coderanger.net/derived-attributes/
The attribute code in your cookbook is getting parsed before the jboss_home attribute is being set. One way or another the solution is to move the interpolation into recipe code.
You could just use a plain old ruby variable instead of the attribute you are trying to construct -- particularly if nothing else in your system ever sets that attribute.
You also should be able to delete the declaration from your attributes file and use this in recipe code as well:
node.default_unless["obscured"]["mysql"] =
"#{node['jboss']['jboss_home']}/modules/com/mysql/jdbc/main"
Although you need to place that statement early in your run_list, before you ever use node["obscured"]["mysql"] as an argument to any resource.
I get the Error: EL Expression Unbalanced while trying to add quotation mark in EL String. How can I do that?
#{chainModel.selectedChain.equalsIgnoreCase("")
? 'Kettenbearbeitung' :
'Verkettung'
.concat('"')
.concat(chainModel.selectedChain)
.concat('"')}
Try to use \" ASCII HTML Names to avoid JSF Syntax validations when you need to concat JAVA values with complex strings. Or use \" for double quotes or \' for simple quotes and it will be simplified when you need for a simple string.
In your case I propouse the following:
? 'Kettenbearbeitung' :
'Verkettung'
.concat('\"')
.concat(chainModel.selectedChain)
.concat('\"')
Firebug identified xpath not working in protractor.I ahve cretaed xpath using firebug.When I identify the xpath using IDE,it is working fine.However when I use the same xpath in protractor,it is not working.My element does not have id or name.So here i can use only xpath option.
Please find the below image for reference.
Here I need to verify whether that particular element has "IRCTC Attractions" text.
Could you please help me?
HTML code:
//div style="width:100%;" class="g_hedtext">IRCTC Attractions /div
Find the element by text and assert it's present:
var elm = element(by.xpath("//div[. = 'IRCTC Attractions']"));
expect(browser.isElementPresent(elm)).toBe(true);
OK, looking at your error message (in the comment):
Exception loading: SyntaxError:
C:\Users\XXXX\AppData\Roaming\npm\TC_model2.js:7
var disclaimermessage = element(by.xpath('//[#id='disclaimer-message']'));
^^^^^^^^^^ Unexpected identifier
(I'm guessing where the carets before "Unexpected identifier" were aligned. Is that right?)
The problem is that you've used single quotes both to delimit the string 'disclaimer-message', and to delimit the whole XPath expression '//[#id='disclaimer-message']'. Thus it appears to the parser that your XPath expression is the stuff between the first two single quotes: '//[#id=', and then the disclaimer-message is some other identifier without any comma or other operator to show what it's doing there.
The solution is to use double quotes inside the XPath expression. XPath accepts either single or double quotes; it doesn't care, as long as you match them with each other. So change the offending line to
var disclaimermessage = element(by.xpath('//[#id="disclaimer-message"]'));
And you should be good to go.
For future reference, this question would have been quicker and easier to answer if you had told us about the error message in the first place.
I want to write a string with quotes in a jsp page which is using jstl tag c:out for its value that means I want to write:
c:out value = '"4"'
Please suggest asap..
Did you try to use escapeXml attribute?
<c:out value='"4"' escapeXml="false"></c:out>
Try this.
<c:out value='\\"4\\"'/>