I have a page in my app with a dynamically-generated form, in which I need a number of <select> elements. Since I don't know in advance how many there will be, I need to put an ID number in the name attribute of each <select>. I'm trying to use the built-in #{select} tag (documentation here) like so:
#{ select 'select_' + ${IDnum}}
...options, etc...
#{/select}
When I do that I get a MissingMethodException:
No signature of method: Template_1009.$() is applicable for argument types:
(Template_1009$_run_closure1_closure2_closure3) values:
[Template_1009$_run_closure1_closure2_closure3#ad2388] Possible solutions:
_(java.lang.String), is(java.lang.Object), run(), run(), any(), get(java.lang.String).
When I instead do:
#{ select 'select_${IDnum}'}
the page renders correctly, but the select element renders like this in view-source:
<select name="select_${IDnum}" size="1" >
So, how do I get the value of ${IDnum} into the name attribute? I can do this with normal HTML <select> tags, but I'll need to write some Javascript to emulate Play's value:${x} functionality that I really don't want to bother with.
Thanks!
Try this :
#{select 'select_'+IDNum}
Related
Part of it look like this:
<input type="hidden" id="recaptcha-token" value="Need This Value">
I'm running Selenium like this:
driver.findElement(By.xpath("[#id=\"recaptcha-token\"]"));
How I can get "Need This Value" from running this code ?
For your specific case, you can first get the element like so:
driver.findElement(By.xpath("//*[#id='recaptcha-token']")); // Any element with that id
driver.findElement(By.xpath("//input[#id='recaptcha-token']")); // More specific to your tag
And then you get the attribute you want using getAttribute(String attrName).
A one-liner would then be:
driver.findElement(By.xpath("//input[#id='recaptcha-token']")).getAttribute("value");
If you only want to look for an element with that id, you could simplify that call by using By.id() instead of By.xpath():
driver.findElement(By.id("recaptcha-token"));
In Firebug and other DevTools you can get the DOM properties and values corresponding to an HTML element.
How can such values be extracted using selenium-java code?
I had tried getAttribute(), but it seems to be working only for HTML attributes and not for DOM properties like "value" or "spellcheck" etc.
The reason I went for this approach is that the value associated with the <input> text field (snippet below) is run-time generated and data is bound to it using Knockout. And hence it's not possible to capture them with standard approaches like getText(), getAttribute("value"), getAttribute("text"), getAttribute("innerHTML"), getAttribute("innertext"), etc.
HTML snippet for the HTML element:
<input class="form-control" type="text" style="cursor: text" readonly="readonly" data-bind="textInput: url">
I know this is an old question but it might give someone else a hand out
Use this in the console
$$("input.form-control").value
if it returns the required you will have to execute the Javascript using WebDriver i.e.
driver.ExecuteScript("var data = arguments[0].value; return data;", (Element as RemoteWebElement)
According to the Selenium documentation, there is only the getAttribute() function, which is described as follows:
Get the value of a the given attribute of the element. Will return the current value, even if this has been modified after the page has been loaded. More exactly, this method will return the value of the given attribute, unless that attribute is not present, in which case the value of the property with the same name is returned (for example for the "value" property of a textarea element). If neither value is set, null is returned. ...
According to this, getAttribute("value") should return the DOM property value in case there is no HTML attribute named value.
If that's not the case, it may be a timing issue. I.e. the value is read by Selenium before it gets set.
In Selenium 4 use getDomAttribute() and getDomProperty().
I'm trying to do a macro on freemarker, but I'm having problems to implement css class as parameter.
My object have some default css classes and I would like to add optional classes.
<#macro Button href extra...>
<a href="${href}" class="ui-button"
<#list extra?keys as attr>
${attr}="${extra[attr]?html}"
</#list>
>Anchor Button</a>
</#macro>
1) <#Button href="link.html"></#Button>
2) <#Button href="link.html" id="button1" class="marginrightnone"></#Button>
The line 2) only is rendering the "id" parameter. If I delete class="ui-button" of the macro, then it renders correctly.
What I could to do to render two or more class parameters???
You need to construct a string containing all the class parameters and use that as the value of a single HTML class attribute in the template.
You can't have an arbitrary number of class attribute/value pairs and still be legal HTML.
The simplest that would be basically what you have now would be to create a local with the "ui-button" value in it. As you iterate over extra?keys check for a "class" key and if found, append it to the local class (along with a leading space). The template would use that constructed value:
<a href="${href}" classes="${local_classes}"
I am having problems with ValueChangeListener attached to a dropdown list.
Here is the code:
<h:selectOneMenu
value = "#{MultiFileSelectMgmtBean.selectedLocationName}"
valueChangeListener = "#{MultiFileSelectMgmtBean.LocationChangeEvent}"
onchange = "submit();"
>
<f:selectItems
value = "#{MultiFileSelectMgmtBean.locationsListItems}">
</f:selectItems>
</h:selectOneMenu>
And here is the backing bean:
protected List<SelectItem> locationsListItems;
...
public void LocationChangeEvent( ValueChangeEvent vce ) throws Exception
{
selectedLocationName = (String) vce.getNewValue();
}
The problem is that 'selectedLocationName' gets a "11" or "13" value, even the dropdown list is populated with two strings "LocationTest1" and "LocationTest2".
What could be the problem with vce.getNewValue?
The submitted value of the dropdown list is the option value, not the option label as you seem to think. Note that the method is also called getNewValue(), not getNewLabel(). The option labels are not sent over HTTP from client to server by the HTML form submit. There's no way to extract them from the HTTP request.
If you really need the option label instead of the option value for some unclear reason, then you'll either need to use it instead of option value while creating the select items, or to have a mapping of all option labels associated with the option values somewhere, so that you can get the label by the value from this mapping. The chance is big is that you already have this sort of mapping in your bean, otherwise you wouldn't be able to populate the <f:selectItems> value :)
See also:
How to get both label and value from f:selectItems
Our <h:selectOneMenu> tag wiki page
Unrelated to the concrete problem: the combination of a <h:selectOneMenu>, a valueChangeListener and onchange="submit()" indicates that you're using a JSF 1.x specific hack in order to achieve the functional requirement of populating another dropdown or fields based on the change of the dropdown. Since you seem to be already using JSF 2.x, I recommend you to forget about this approach at all and just use <f:ajax listener> instead. The aforelinked wiki page contains one example.
Can anyone help me to understand the usage of TypedProperty in websphere commerce?
ie,How to pass values from one jsp to other using TypedProperty without a command class.I would prefer to handle it in my client side itself without invoking Command class..can anyone help me to sort out it?
Typed property is usually used to pass values from controller commands to JSPs. If you just want to pass values from one JSP to another, create a form in your first JSP and submit it to the second.
If this is a form submit, set the values you need to pass in element. In the results jsp you can get those values using ${WCParam.xxx} .
FYI - To list out all the values in WCParam object try to print the below in JSP :
${WCParamValues}
We use typedProperty when we need to send anything from the command. For example, you give an order ID from the first JSP and want to get the final amount to be passed the result JSP. Here in the command we use the orderID from the request object -> Then we use the OrderAccessBean to get the OrderTotal -> then we set this to a TypedProperty object -> we then set this TypedProperty object to request properties using setRequestProperties() OOB method in a controller command.
Hope this makes it clear !
TypedProperty is a class in Java which can be compared to Hashmap in Java for better understanding. It is a name value pair combination.
I just wanted to understand the problem before answering further.
Why do you want to use TypedProperty in Jsp to pass the value from one jsp to another?
Are you importing the second jsp or including the second jsp to which you have to pass the values to?
If you are importing, you can use c:param tag to pass the values to the second jsp.
For included jsps, the values are already available in the second JSP.
Please include code snippets to explain your problem so that it can be answered clearly.
You can pass parameters from one jsp to another by using the following code snippet:
<c:import url="child.jsp">
<c:param name="name1" value="value1" />
<c:param name="name2" value="value2" />
<c:param name="name3" value="value3" />
</c:import>
Within the child.jsp you can read the parameters by using:
<c:out value="${param.name1}" />
<c:out value="${param.name2}" />
<c:out value="${param.name3}" />
A TypedProperty is nothing but a Wrapper to HashMap. So that's nothing to do here with passing values from one JSP to another JSP. Without invoking a command, you can't pass a Java object to another JSP.
And that is the very basic of Command Framework. I would prefer to go with the first answer.