Using <ui:repeat><h:inputText> for varStatus and index error [duplicate] - jsf

This question already has an answer here:
Using <ui:repeat><h:inputText> on a List<String> doesn't update model values
(1 answer)
Closed 5 years ago.
When i use index with outputText, anything is OK.
<ui:repeat id="topTenGrd" var="dream" value="#{dreamModifyBean.topDreams}" varStatus="status">
<h:outputText class="dream-title uppercase" value="#{status.index}" />
</ui:repeat>
But i change outputText -> inputText then when click any button on screen , the error PropertyNoWritableException occured.
<ui:repeat id="topTenGrd" var="dream" value="#{dreamModifyBean.topDreams}" varStatus="status">
<h:inputText class="dream-title uppercase" value="#{status.index}" />
</ui:repeat>
Any idea why?

Try this.
JAVA:
String indexs[] = new String[10]; // Need encaptulation
UI:
<ui:repeat id="topTenGrd" var="dream" value="#{dreamModifyBean.indexs}" varStatus="status">
<h:inputText class="dream-title uppercase" value="#{dream}" />
</ui:repeat>

Related

Concatenation inside a JSF expression [duplicate]

This question already has answers here:
How to concatenate a String in EL?
(5 answers)
Closed 4 years ago.
I'm trying to concatenate a number inside my JSF expression:
<h:dataTable class="seminaire" value = "#{seminaireControl.getList()}" var = "seminaire">
<c:forEach begin="1" end="#{extraControl.getNb()}" var="nb">
<h:column>
<f:facet name="header">seminaire #{nb}</f:facet>
<h:inputText value="#{seminaire.value+#{nb}"/>
</h:column>
</c:forEach>
</h:dataTable>
What I'm trying to have is something like #{seminaire.value1}, #{seminaire.value2}, ...
Concluding the above, to help other users for EL syntax to be used in proper manner.
(The + operator is in EL exclusively a sum operator.)
<h:dataTable class="seminaire" value = "#{seminaireControl.getList()}" var = "seminaire">
<c:forEach begin="1" end="#{extraControl.getNb()}" var="nb">
<h:column>
<f:facet name="header">seminaire #{nb}</f:facet>
<h:inputText value="#{seminaire['value'.concat(nb)]}"/>
</h:column>
</c:forEach>

Datatable with dynamic columns, multiple colums per object

I have dynamic number of Tests (measurements) for each item (Apple, Banana) and every Test has 2 Properties (mandatory, visible). What I need is table that shows these Tests as columns (colspan=2) and its Properties (colspan=1), like in example below. I can do it for table header (using Primefaces' p:columnGroup) but I don't know how to fill two columns for every Property while iterating through properties list.
Only idea I have is to make new List where every item will exist twice (Diameter, Diameter, Length, Length), iterate over it and use some modulo condition to choose correct property.
My current solution is:
xhtml
<p:dataTable var="scenario">
...
<p:columns var="property" value="#{view.getXTimesProperties()}"
columnIndexVar="index">
<c:set var="test" value="#{view.getTest(scenario, property)}"/>
<c:choose>
<c:when test="${index % 2 == 0}">
<h:outputText value="#{test.mandatory}"/>
</c:when>
<c:when test="${index % 2 == 1}">
<h:outputText value="#{test.visible}"/>
</c:when>
</c:choose>
</p:columns>
</p:dataTable>
and View method is
public List<Property> getXTimesProperties() {
List<Property> list = new ArrayList<>(properties.size() * 2);
for (Property property : properties) {
list.add(property);
list.add(property);
}
return list;
}
Is there a better way? Thanks in advance for better idea!
Yes, better way (credits to Kukeltje):
<p:dataTable var="scenario">
...
<c:forEach var="property" items="#{view.properties}">
<c:set var="test" value="#{view.getTest(scenario, property)}"/>
<p:column>
<h:outputText value="#{test.mandatory}"/>
</p:column>
<p:column>
<h:outputText value="#{test.visible}"/>
</p:column>
</c:forEach>
</p:dataTable>

How to iterate over a list in a textarea using JSF? [duplicate]

This question already has answers here:
How iterate over List<T> and render each item in JSF Facelets
(2 answers)
Closed 6 years ago.
I am new to JSF2 and having very less idea about front end developement.Currently i am trying to iterate over a list in a text area using JSF2? we have a list of datas like aList[bean1,bean2,bean3,....] and we have to print datas
<h:inputTextarea var ="list" value="#{Bean.value}">
row1-> datas of bean1
row2-> datas of bean2
like all the datas in the list
</h:inputTextarea>
I vahe searched a lot but did not get proper information, please help me.
If you want to display different textArea for different rows you can write as:
<h:form id="test">
<h:panelGrid value="#{testController.myRows}" var="myVar">
<h:inputTextarea value="#{myVar}"/>
</h:panelGrid>
</h:form>
Although instead of panelGrid you can use datalist also
<ace:panel id="jPanel5" style="text-align:left;border:0;width:100%;">
<h:outputLabel id="message" value="#{msgs['css.Label.message']}" styleClass="css-lebel">
</h:outputLabel>
<ice:panelSeries var="item" value="#{Bean.searchResultArea}" style="border:1px solid black;width:1150px;height:400px;overflow-y:scroll;overflow-x:scroll;">
<h:outputText value="#{item}<br/><br/>" style="white-space: nowrap;" escape="false" />
</ice:panelSeries>
</ace:panel>
I did like this and get proper output.

If else condition in jsf [duplicate]

This question already has answers here:
Correct syntax to compare values in JSTL <c:if test="${values.type}=='object'"> [duplicate]
(1 answer)
The representation of if-elseif-else in EL using JSF
(4 answers)
Closed 7 years ago.
I have to display a list of element in groups. I am expecting out like in the image.
If I remove if condition its printing all option in all groups.
<p:accordionPanel value="#{menuView.menunames}" var="name">
<p:tab title="#{name}">
<c:forEach items="#{menuView.menu}" var="entry">
<h:outputText value="(#{entry.key} == #{name})"></h:outputText>
<c:if test='#{entry.key} == #{name}'>
<h:dataTable value="#{entry.value}" var="submenu">
<h:column>
<h:outputText value="#{submenu}" />
</h:column>
</h:dataTable>
</c:if>
</c:forEach>
</p:tab>
</p:accordionPanel>
private Map<String, List<String>> menu;
private List<String> menunames;
The EL expression should be like this:
<h:outputText value="#{entry.key == name}">
<c:if test="#{entry.key eq name}">
I use a c:choose for this, with the c:when for the if part and c:otherwise for the else part.

update datatable footer primefaces (facet or columnGroup)

I want to make a footer in dataTable and I need to update when the values inside the DT changes.
The problem is that ajax update simply don't occurs.
I've tried two ways:
<p:dataTable
id="dataTableAvaliacao" var="aluno"
value="#{alunoAvaliacaoMB.alunos}">
<p:column>
<p:inputText id="inputNota"
value="#{aluno.getNota(avaliacao.property).vlNotaString}">
<p:ajax event="change"
update=":form:dataTableAvaliacao:mediaAluno, :form:dataTableAvaliacao:mediaAvaliacao" />
</p:inputText>
</p:column>
<p:columnGroup type="footer" id="mediaAvaliacao">
<p:row>
<p:column
footerText="Nota média da avaliação" />
</p:row>
<p:row>
<ui:repeat value="#{alunoAvaliacaoMB.colunasAvaliacoes}"
var="avaliacao">
<p:column id="colunaMedia"
footerText="#{alunoAvaliacaoMB.getMediaAvaliacao(avaliacao.property)}"/>
</ui:repeat>
</p:row>
</p:columnGroup>
<p:dataTable>
The update doesn't occurs...
second way (based on this answer on SO: How to ajax update an item in the footer of a PrimeFaces dataTable?):
<p:remoteCommand name="refreshFooter" update=":form:dataTableAvaliacao:outputMediaAvaliacao"/>
<p:dataTable
id="dataTableAvaliacao" var="aluno"
value="#{alunoAvaliacaoMB.alunos}">
<p:column>
<p:inputText id="inputNota"
value="#{aluno.getNota(avaliacao.property).vlNotaString}">
<p:ajax event="change"
update=":form:dataTableAvaliacao:mediaAluno" oncomplete="refreshFooter();" />
</p:inputText>
</p:column>
<p:dataTable>
<f:facet name="footer">
<h:outputText colspan="1" value="Nota média da avaliação:"/>
<ui:repeat value="#{alunoAvaliacaoMB.colunasAvaliacoes}"
var="avaliacao">
<h:outputText id="outputMediaAvaliacao"
value="#{alunoAvaliacaoMB.getMediaAvaliacao(avaliacao.property)}"
</ui:repeat>
</f:facet>
I've also tried
<p:remoteCommand name="refreshFooter" update=":form:outputMediaAvaliacao"/>
If I put
<p:ajax event="change"
update=":form:dataTableAvaliacao:mediaAluno, :form:dataTableAvaliacao" />
in the first way, it works, but I don't wanna update all dataTable every time.
What I'm doing wrong? is it a bug?
Referring on 2nd way from your question that you based on this answer...
actually it is possible to update p:dataTable footer (even from within table itself)...but with one modification of your code.
Reason why your implementation does not work is that you did not take into account that <h:outputText id="outputMediaAvaliacao"../> is wrapped with ui:repeat.
In that case, p:remoteCommand is not able to find h:outputText component ID defined in update attribute because that ID does not exist in DOM:
ui:repeat is actually copying h:outputText as many times as list from value attribute is long and appending all parent IDs to newly created native HTML components
<span id="form:dataTableAvaliacao:avaliacao:0:outputMediaAvaliacao">...</span>
<span id="form:dataTableAvaliacao:avaliacao:1:outputMediaAvaliacao">...</span>
<span id="form:dataTableAvaliacao:avaliacao:2:outputMediaAvaliacao">...</span>
...
(you can see the same using DOM inspector of your favorite browser)
SOLUTION
After you learn and understand all facts stated above (like I did :) ), solution is quite simple:
wrap ui:repeat with some parent element and assign ID to parent element. For example like this
<f:facet name="footer">
<h:outputText value="Nota média da avaliação:"/>
<h:panelGroup id="footerPanel">
<ui:repeat value="#{alunoAvaliacaoMB.colunasAvaliacoes}"
var="avaliacao" id="avaliacao">
<h:outputText id="outputMediaAvaliacao" value="#{alunoAvaliacaoMB.getMediaAvaliacao(avaliacao.property)}" />
</ui:repeat>
</h:panelGroup>
</f:facet>
and modify p:ajax of p:inputText to update newly created element after text is changed
<p:ajax event="change" update=":form:dataTableAvaliacao:footerPanel" />
On this way all children elements of h:panelGroup will be updated (meaning only footer will be updated and not entire table).
And now, after you solved updating, you can focus on designing of all UI elements under h:panelGroup to make them fit your requirements.

Resources