I want to use ui:repeat to fill values of an integer array which is originally empty, from inputText. I followed the explanation in here, but it did't work for me. My UI is:
<ui:repeat value="#{controllerBean.schedule.scheduleTimes}" var="v" varStatus="loop">
<h:outputText value="Shedulte Time #{loop.index + 1}">
</h:outputText>
<p:inputText value="#{controllerBean.schedule.scheduleTimes[loop.index]}">
</p:inputText>
</ui:repeat>
contollerBean is the managed bean, schedule is model and scheduleTimes is Integer[] array in my model with setter and getter. After providing some values on ui, the values of the array at each index is still null.
You need a converter to Integer because in JSF all values are by default treated as String.
<ui:repeat value="#{controllerBean.schedule.scheduleTimes}" var="v" varStatus="loop">
<h:outputText value="Shedulte Time #{loop.index + 1}">
</h:outputText>
<p:inputText value="#{controllerBean.schedule.scheduleTimes[loop.index]}" converter="javax.faces.Integer">
</p:inputText>
</ui:repeat>
Now the example works for me like a charm.
My previous answer is incorrect because JSF automatically converts primitive types. A converter is however required for Collections because expected type cannot be determined at runtime.
Nevertheless the example works with a converter or without. Therefore please make sure that controllerBean has scope other than non-scoped (without scope annotation). Otherwise the bean is recreated each time you access it.
Well, also with request scope my code works fine. Please check the
example I'm using
I replaced primefaces p:inputText with pure JSF h:inputText but I don't think it matters. I also added some html table tags to do a formatting.
As you can see in server logs values are set properly.
Related
My question lies in the following code. Though the code is not working now. I wan't to rewrite it in proper way so that it works.
<span ng-if="community = vm.getCommunity(invite.community_id)!=null" grv-icon-comm-type="vm.communityViewHelper.getTypeIcon(community)" ng-class="vm.communityViewHelper.getColorClass(community)"></span>
In the above code vm.getCommunity(invite.community_id) returns either null or community object. If community object is returned then I wish to call two more function in the same element where I wish to use the recently receivedcommunity value on those two function.
It's just killing my time. Please help.
Alternatively, you could use a watcher on "invite.community_id" to set community inside a controller function. Could look a bit cleaner depending on the rest of the code.
This function could even set all three values if you like.
I'm creating a custom directive that I want to use to display the value of a field and an optional suffix (expected for units and such). Note that my example is shortened to stay concise.
My template looks something like
<div class="my-value">{{boundValue}}{{boundSuffix}}</div>
For the value, I'm using a two-way binding (=) and for the suffix, I'm using a string binding (&).
It worked great when I bound ° into the suffix to display a temperature, but when I tried to bind in meters (note, there's a leading space - I don't want it pushed up against the number) the leading space seems to get trimmed and my result ends up looking like 123meters.
Using the chrome developer tools, I added a link function and inspected the directive's scope. By the time it reaches the link function, boundSuffix has already been trimmed. It seems like Angular is pulling some shenanigans on my behind the hood. Is there any way for me to avoid this trimming?
It's better to use angular filters to solve your problem. Filters allow to format your output as currency or as UPPERCASE (for example). Try to look here for more info. And here is working example
I don't want to use any Javascript code or $scope variable.
Just want to print 1,2,3,4,5 values in Drop Down using ng-options.
This is what I have tried:
<select ng-name="priority" ng-options="priority for priority in Range(1, 5)"></select>
Working solution, within your requirements:
<select ng-model="priority" ng-options="priority for priority in [1,2,3,4,5]"></select>
Just in case, here's the plnkr to experiment with. If you have a quick look at the angular source code, you will see that ng-options requires select element as well as ng-model. Not sure what is the Range implementation mentioned in your example, but here is a very creative thread on this topic. Though, if your array is always the same and you really don't want to use scope (but why?), you're better off with the solution above.
For instance, is it possible to define:
#FindBy(By.id("id1") OR By.id("form1:id1"))
public WebElement button
So that button having either "id1" or "form1:id1" should work fine?
You can use the #FindBys annotation, the syntax is:
#FindBys({#FindBy(id = "foo"),
#FindBy(className = "bar")})
The JavaDoc describes it here:
http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/support/FindBys.html
Well,
use whathever you want, as long as it works
Personally I would use #FindBy(By.id("id1")) but it is just point of choice.
Also, there is no value added in referring same element twice with two different methods. It will only cause mess in your code
EDIT
As I understood your comment, there is element on the page which constantly changes its ID. If you need to refer to such elements, try using xPath See for example this xpath tutorial
The idea is that you will point to some place in the DOM rather than to specific ID
Use Xpath or CSS selector to do that. Or Java to store the ID name in String and then you can fill it to your Id.
so I am trying to assign a number to a variable that is dynically generated from a binded array...when i try and assign it and trace it out nothing happens, which means I am obviously doing something wrong but I am not sure? just for fun i decided to bind the data to a label like so...
<s:Label text="{this.dd.selectedViews.length}"/>
and that work and updated properly, but when running in debug mode i got this warning...
warning: unable to bind to property 'length' on class 'Array' (class is not an IEventDispatcher)
so what would be the best method of assigning the array to a variable to use throughout my application
thanks in advance for any help
I'm not really sure what you are asking here, but maybe this will help you out. As your error message says, the Array class is not an IEventDispatcher. What that means is that if you try to use a plain old Array as the source of a data-binding expression, it generally is not going to work.
If you need to bind to an array, you can try using a different class such as ArrayCollection, which supports data binding.