Play Framework 1.2.4: Selected Option for #{select} template - java

I am passing a Model and a List<String> from controller to .html file using the render method invocation. The Model passed contains some values that has to be populated in different components present in the UI and the List<String> is used for binding with the combo-box.
For binding the List<String> with combo-box in the .html using the below code and this is working fine:
#{select 'employee.role', items:userRoles, valueProperty:'userRoles', labelProperty:'userRoles'/}
What I want to achieve:
Suppose the List<String> contains the roles as Trainer, Educator, Trainee, Staff and the Model passed has a role property with value Staff. When the page loads, then Staff should be in selected state in the combo-box display.
Problem
I am aware of how to iterate through a List in Play framework template but I am not aware of how to keep a value selected in the drop-down based on one of the property values present in the Model
Kindly help me on this.

From the documentation:
This tag can generate options using items attribute.
items (optional) - list of objects, used to create options
value (optional) - selected element in items (note that multiple selections are not supported)
labelProperty (optional) - for each item, attribute used as option’s label
valueProperty (optional) - for each item, attribute used as option’s value. id is used by default
So, the code should be:
#{select 'employee.role', items: userRoles, value: model.role /}

Related

unable to get the default selected value of drop down from selenium

Scenario1: I have two fields in the screen district and territory. For some user it has default value selected and the drop down is disabled.
PFB code for reference.
<select id="abcd" name="xyz" class="12234" style="ghfhgfhfh">
<option class="hide" value="4541ghj" selected="">valley
none</option>
</select>.
I am trying to get the "valley none" as the output if the drop down is disabled.
Scenario 2: I have two fields in the screen district and territory. For some user it has default value selected and the drop down is enabled.
At this time I want to select the option from the drop down now.
For this I am trying to make a common code.
What I am doing now:-
I am making a select type element and them I am trying to get the default value by getfirstselectedvalue() and then saving it in the webelement and then I am doing .gettext(). to get the option selected.
other wise if the null is returned from thr firstselectvalue() function then I am trying to select the value by visible text.
Error:-
if the default value is selected and the drop down is disbaled The getfirstselectedvalue() function is returning null ,if the element type is select but if I make it as webelement and then doing gettext it gives me the value in the field but this cannot be done if the drop down is senabled as at that time the type to element should be select to select the value from enabled drop down. At both the scenario the class is select for the fields
Please help....
As mentioned by Greg we need the html and the code you tried for better understanding. However, this is the simple logic that you can use.
//get the listBox Element
WebElement list = driver.findElement(By.xpath("//select[#id='abcd']"));
// check if it's disabled
if (!list.isEnabled()) {
// get value from option 1 as listbox is disabled.
System.out.println(list.findElement(By.tagName("option")).getText());
}else {
// select value as listbox is enabled. (Chnage 'Scenario2' with desired list item
list.findElement(By.xpath(".//option[.='scenario2']")).click();
}

Make dynamically created AttributeDefImpl read only after it is populated

I am new to using the ADF framework. I am dynamically creating view objects that appear on a JSF front-end page. I want to create a dynamic view on the front end that cannot be edited once it is populated and rendered. My code is as follows:
AttributeDefImpl dynamicViewAttribute = dynamicViewDef.addViewAttribute(name, alias, javaType);
dynamicViewAttribute.setUpdateableFlag(AttributeDef.READONLY);
This fails as once the view object is set to READONLY, it cannot be updated. If I change the line of code as follows:
dynamicViewAttribute.setUpdateableFlag(AttributeDef.UPDATEABLE);
There is no error and the page displays correctly, but the user can edit/update the text in the view object.
How can I accomplish what I need i.e. display the view object text without letting the user edit/update it? Remember this has to be dynamically created so I cannot set readOnly=true on the jsf.
If this will be dynamically determined , then you can send your flag or Attribute i.e ("IsReadOnlyFlag") in the ViewObject.
in your jsf page change the attribute readOnly for
the inputText to readOnly=#{bindings.IsReadOnlyFlag.inputValue eq 'Y'}

issues passing dropdown value to java

I have a bunch of select tags in my page where some of them allows the user to use the dropdown and some of them will be disabled at a given time. so I have a select tag in my jsp such as:
<html:select name="myobject" property="myfield" disabled="$(isDisabled ? 'disabled' : '')"/>
I wanted to set as readonly a select tag on my jsp but apparently is not possible so I had to put disable. Since disabled values are not passed back to the application when a user submits the action I created a hidden object of it to pass it as it's suggested everywhere to work around that...
<html:hidden name="myobject" property="myfield" indexed="true"/>
The problem is.. when the form is submited I don't get the new dropdown value selected by the user, I debug into my java code and what I receive is the value that was originally sent to the page instead of what the user picked. It works if I removed the hidden field but if I do so then the disabled selections won't displayed when refreshed cause disabled fields don't pass back the values and i'll receive null at my end... how do I fix this problem?
Thanks,
There may be a duplicate of name or property of the html hidden component.

How to make multiple options selected while using <html:select> in struts?

One thing I learned today is "there is no selected property in
<html:option>
like plain old option" , we can give value in
<html:select>
that matches the value against each option and if match found marks the option selected.
but I want to make multiple options pre-selected on page load(am using
<html:select multiple="true">
How can it be achieved?
Implement the following:
If possible use JavaScript to make the selected entries true for the
multiple entries u had made in that select list
Make it selected by using Java-script first by calling javascript
function before any action OR with that action :
function callSelectAll(selectName)
{
var i;
for(i=0;i<...) {
document.getElementById(selectName).options[i].selected = true;
}
}
And use String[] array name as a property name for that html:select property form bean property. And the name of that array as a property of that html:select in jsp page.
You will ultimatly gate the all selected values un the that string array of form bean.

Implementing dynamic pagesize in pagination struts2 + java

I am trying to implement pagination through display tag in Struts2.
Now my requirement is I have a combo box which has some page size value like 5, 10, 15 ..
So, How can I update that value in page size of display tag in Struts2 ?
You would create an exposed property on your action, named for example selectedPageSize. This property could be set to a default size (in your example 5). You would keep a hidden form field storing the currently selected value. This would then be used in your view with the display tag similar to:
<c:set name="selectedPageSize" value="selectedPageSize" scope="request"/>
<display:table pagesize="${selectedPageSize}" ... >
I'm not sure about struts2 in particular, but with JSF in general, if you bind whatever component you use to paginate into your backing bean, you can set properties such as that through an action.

Categories