Varstatus Index not working for adf iterator - jsf

I have an iterator loop for whose children I'm using varStatus for id. When I run the below code, it does not show any value and the id becomes "lkextres_" with no index value appended.
<af:iterator value="#{sessionScope.appBB.resourceList}" var="resourceDef" id="itrResourceList" varStatus="vs">
<af:link id="lkextres_#{vs.index}" useWindow="true" immediate="true" />
</af:iterator>
Please help with how do I get index values to put in id. My purpose is to have different id for each child element so i am using varstatus in af:iterator

Related

Not able to see the label of the Api names

SelectedFields is the list of the fields having API Name and itr the iterative variable and similarly rec is the iterator variable for the records So whenever I am using {!itr}
in the facet then it will print API name and If do not use facet then it will print label of the fields how to fix this??
<apex:repeat value="{!selectedFields}" var="itr">
<apex:column value="{!rec[itr]}">
<apex:facet name="header">
<apex:commandLink action="{!sortByColumn}" reRender="recPage">{!itr}
<apex:param name="Names" value="{!itr}" assignTo="{!sortingValues}"/>
</apex:commandLink>
</apex:facet>
</apex:column>
Can you use $SobjectType to get the field label, something like {!$ObjectType.Account.fields[itr].label}?
Alternatively in apex build a Map<String, String> where key is the api name and value is the label. Or you can even iterate over list of field tokens, not strings. sObject class supports a dynamic get with field token as param so same trick should work in VF and you can get label out of a token too.
Yeah! {!$ObjectType.Account.fields[itr].label} It is the way to get the Label from the API name of Objects and For the dynamic objects. We can use this {!$ObjectType[sObject].fields[itr].label} as it will take out the label from the API names.

ie getelementsbyID with same ID

i have a script that works with internet explorder (ie) and i need to loop the select fields, that it zelf is no ploblem bu the 4 elements got the same ID (on the same page).
How do i let it loop through the 4 fields?
Can i make them more spesified?
the code i use is the following:
ie.document.getElementByID("DownloadImage").Click
The ie code is the following:
field 1
<a id="DownloadButton" href="javascript:__doPostBack('ctl00$ctl00$MainContent$MainContent$ctl00$declaratiebestandView$RetourInformatieGrid$ctl03$DownloadButton','')">CZ_Specificatie_150005697.pdf</a>
field 2
<a id="DownloadButton" href="javascript:__doPostBack('ctl00$ctl00$MainContent$MainContent$ctl00$declaratiebestandView$RetourInformatieGrid$ctl03$DownloadButton','')">CZ_Specificatie_150005697.pdf</a><input name="ctl00$ctl00$MainContent$MainContent$ctl00$declaratiebestandView$RetourInformatieGrid$ctl03$DownloadImage" class="inlineButton" id="DownloadImage" type="image" src="../images/download.png" text="CZ_Specificatie_150005697.pdf">
then it opens the download screen, and then my code continue's (and works :) )
You can loop them by using querySelectorAll to gather all the elements with an id attribute whose values match what you are after. You can distinguish between them by index. This method will allow you to gather them even though the ids are repeating. However, the HTML you have shared downloads the same document so a loop doesn't seem necessary.
Dim nodeList As Object, i As Long
Set nodeList = ie.document.querySelectorAll("[id=DownloadButton]")
For i = 0 to nodeList.Length-1
nodeList.item(i).Click
Next
That loops all of the matching elements and clicks
By index will be specific but if you familiarize yourself with CSS selectors there are a vast number of possibilities for specifying an element.
The id in HTLM must be unique. If it is not unique it is no valid HTML and should be fixed.
HTML4:
http://www.w3.org/TR/html4/struct/global.html
Section 7.5.2:
id = name [CS]
This attribute assigns a name to an element. This name must be unique in a document.
HTML5:
http://www.w3.org/TR/html5/dom.html#the-id-attribute
The id attribute specifies its element's unique identifier (ID). The
value must be unique amongst all the IDs in the element's home subtree
and must contain at least one character. The value must not contain
any space characters.

accessing native query list using ui:repeat

lets say i have a table test with columns id and name
on my bean i got this query
public List getTestList(){
Query q = em.createNativeQuery("select * from test");
List list = q.getResultList();
return list;
}
and on my jsf page i have:
<ul>
<ui:repeat id="resulta" value="#{testController.testList}" var="item">
<li>#{item.id}</li>
</ui:repeat>
</ul>
why do i get a SEVERE: javax.el.ELException: /test.xhtml: For input string: "id"
why do i get a SEVERE: javax.el.ELException: /test.xhtml: For input string: "id"
Because a native query returns a List<Object[]>, not a List<Test>. You're basically attempting to access an Object[] array using a string such as "id" as index instead of an integer such as 0. If you look closer to the stack trace, then you should have noticed the presence of ArrayELResolver a little further in the stack after the exception, which should already have hinted that #{item} is actually been interpreted as an array.
So, if you absolutely can't obtain it as a fullworthy List<Test> (you can easily do inner joins using #ManyToOne and so on), then this should do to obtain the first column from the SELECT query:
<li>#{item[0]}</li>
The SELECT clause queries more than one column or entity, the results
are aggregated in an object array (Object[]) in the java.util.List
returned by getResultList().
In the first place, native query isn't required in your case. The result of native query returns a list of object array. You have to create JPQL query instead of native query.
Query q = em.createQuery("select t from Test t", Test.class);
List<Test> list = q.getResultList();

Bind the value of an input component to a list item by index

here is an example :
<h:outputLabel for="category1" value="Cateogry"/>
<h:selectOneMenu id ="category1" value="#{articleManageBean.categoryId1}"
converter="categoryConverter">
<f:selectItems value="#{articleManageBean.categories}" var="category"
itemValue="#{category.id}" itemLabel="#{category.name}" />
</h:selectOneMenu>
and here is the managed bean that I have
#ManagedBean
#SessionScoped
public class ArticleManageBean {
private Long categoryId1;
private List<Category> categories;
//...
}
The categories list gets populated from db, and selectOneMenu gets populated with this list using a converter.
My First question:
If I want to create another selectOneMenu in my jsf page I would have to copy paste the entire thing and just change the value of selectOneMenu to say categoryId2 thus putting another attribute to managed bean called categoryId2. That is not practical. I want to map these values of selectMenu to list items, for instance to an attribute
List<Long> categoryIds;
if I use
<h:selectOneMenu id ="category1" value="#{articleManageBean.categoryIds.[0]}" >
I get an error
javax.el.PropertyNotFoundException: /createArticle.xhtml #47,68 value="#{articleManageBean.categoriesId[0]}": Target Unreachable, 'null' returned null
If I nitialize the Araylist then I get this exception
javax.el.PropertyNotFoundException: /createArticle.xhtml #47,68 value="#{articleManageBean.categoriesId[0]}": null
My second question:
Is there a way to dinamicly write selectOneMenu tags, by that I mean not to copy paste the entire tag, just somehow create a function that take the categoryId parameter and writes automaticaly the tag (somekind of custom tag maybe ?)
Hope you understood my questions
thanks in advance
Use the brace notation instead to specify the index.
<h:selectOneMenu id="category1" value="#{articleManageBean.categoryIds[0]}">
You only need to make sure that you have already prepared the values behind #{articleManageBean.categoryIds}. JSF won't do that for you. E.g.
private List<Long> categoryIds = new ArrayList<Long>();
public ArticleManageBean() {
categoryIds.add(null);
categoryIds.add(null);
categoryIds.add(null);
// So, now there are 3 items preserved.
}
an alternative is to use Long[] instead, this doesn't need to be prefilled.
private Long[] categoryIds = new Long[3]; // So, now there are 3 items preserved.

Facelets repeat Tag Index

Does anyone know a way to get the index of the element in a ui:repeat facelets tag?
<ui:repeat id="topTenGrd" var="dream" value="#{dreamModifyBean.topDreams}">
<h:outputText class="dream-title uppercase" value="#{dream.number}. #{dream.title}" />
</ui:repeat>
Specify a value for the "varStatus" attribute:
<ui:repeat id="..." var="..." value="..." varStatus="myVarStatus">
You can then access the loop index via EL:
#{myVarStatus.index}
Additionally, the following properties are available to the varStatus:
begin of type Integer
end of type Integer
index of type int
step of type Integer
even of type boolean
odd of type boolean
first of type boolean
last of type boolean
For more details, see:
https://docs.oracle.com/javaee/7/javaserver-faces-2-2/vdldocs-facelets/ui/repeat.html
The answer by Brian is good but I think it could be a bit more descriptive for information.
We create UI:Repeat
<ui:repeat id="repeatOne" var="listofValues" varStatus="myVarStatus"> </ui:repeat>
Using UI Repeat we can access the values from the variable we associated with the list 'listofValues'.
Using varStatus we can create another variable that holds different type of information. For example using #{myVarStatus.index} in our list to create a table we can use this information for our index on our list.
1.
2.
3.
Of course if you specify your array to start at 0 then so will your list unless you add 1 to each. #{myVarStatus.index + 1}
These are also very useful in 2D arrays that need to use 2 UI:Repeat that are nested.
Property ___Getter_________Description
current getCurrent() The item (from the collection) for the current round of iteration
index getIndex() The zero-based index for the current round of iteration
count getCount() The one-based count for the current round of iteration
first isFirst() Flag indicating whether the current round is the first pass through the iteration
last isLast() Flag indicating whether the current round is the last pass through the iteration
begin getBegin() The value of the begin attribute
end getEnd() The value of the end attribute
step getStep() The value of the step attribute
Additional Documentation with links:
Attributes for the UI:Repeat can be found here.

Resources