Concatenation inside a JSF expression [duplicate] - jsf

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>

Related

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

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>

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.

How to get multiple h:selectOneMenu values inside h:dataTable [duplicate]

This question already has answers here:
Input field in <h:dataTable> always receives value of last item in list
(3 answers)
Closed 7 years ago.
I'm using h selectOneMenu in a datatable and when user press the Set Fixture button i'm saving the value changed in the dropdown, for now i'm using a String variable to get the selected value but the issue is it have the selected value from only the last dropdown. My question is how to get list of all the dropdowns ?
<h:form id="chooseAlmFixtureForm">
<p:panel style="width:80%" header="Set Fixture for Alarms">
<p:dataTable id="tbsetFixtureTable" value="#{setAlmFixtures.alarms}" var="alarmvar" dynamic="false">
<p:column>
<p:commandLink value="View" update=":viewUnknownAlarm" immediate="true" oncomplete="viewDialog.show()">
<f:setPropertyActionListener target="#{currentalarms.viewAlarm}" value="#{alarmvar}"/>
</p:commandLink>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Alarm Time"/>
</f:facet>
<h:outputText value="#{alarmvar.recvTime}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Alarm Type"/>
</f:facet>
<h:outputText value="#{alarmvar.alarmType}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Controller Name"/>
</f:facet>
<h:outputText value="#{alarmvar.controllerName}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Controller Type"/>
</f:facet>
<h:outputText value="#{alarmvar.controllerType}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Choose Fixture"/>
</f:facet>
<h:selectOneMenu id="selectAlarmSite" value="#{setAlmFixtures.selectedFixture}">
<f:selectItems value="#{setAlmFixtures.fixtures}" />
</h:selectOneMenu>
</p:column>
</p:dataTable>
<p:commandButton value="Set Fixtures" actionListener="#{setAlmFixtures.setAlarmsFixtures}" action="#{horizontalmenu.actionCallAlarmsPage}" styleClass="dialogButton"/>
</td><td>
<p:commandButton value="Cancel" actionListener="#{setAlmFixtures.releaseAlarms}" action="#{horizontalmenu.actionCallAlarmsPage}" styleClass="dialogButton"/>
</p:panel>
</h:form>
Currently, your dropdown-value refers to a single variable in your bean (which seems to be selectedFixture of class SetAlmFixtures). How would a single variable represent a state (value) for multiple row (here: alarms)?
You need to link the selected value to the row (alarm) it refers to. To do so, you have several options, two approaches following:
Use the variable of your alarm-object, just the same way as you used them as outputvalues inside the other columns. This way, the alarm's fixture is set directly on value (form) processing. Currently, both of your buttons submit the form (type="submit" is default), depending on what your actionlisteners do, you might consider changing the Cancel-button's type to button.
Map the fixtures and alarms. You could use something like Map<Long, Fixture> fixturemap; mapping alarm-id's to their selected fixture, assuming all alarms have a non-null id. The map's value can be referred by setAlmFixtures.fixturemap['alarmvar.id']. Make sure you provide a getter for the map and the id. Also, you need to initialize the map with the initial fixture values for each alarm.

Display formatted decimal numbers in Primefaces 4 [duplicate]

This question already has an answer here:
Displaying a number in 2 point decimal format in jsf
(1 answer)
Closed 5 years ago.
I have a database table with a float field and I want to display it through Primefaces.
I want to display the numbers formatted as (one thousand, for example): 1.000,00
I tried:
<p:column sortBy="#{item.value}" filterBy="#{item.value}">
<f:facet name="header">
<h:outputText value="#{epoBundle.ListUpbTitle_value}"/>
</f:facet>
<h:outputText value="#{item.value}"/>
<f:convertNumber pattern="#0.000" locale="pt_BR"/>
</p:column>
But got:
/WEB-INF/include/entity/upb/List.xhtml #80,55 Parent not an instance of ValueHolder: org.primefaces.component.column.Column#13ec99d0
Can someone help me?
Thanks in advance.
f:convertNumber must be inside h:outputText.
<h:outputText value="#{item.value}">
<f:convertNumber pattern="#0.000" locale="pt_BR"/>
</h:outputText>

<rich:extendedDataTable> <c:forEach> Displaying a table via a "Map of maps"

I have a data model with structure : TreeMap < String, TreeMap< String, Double>> resultMap;
This is stored in a SessionScoped ManagedBean.
I am trying to output this via a dynamic < rich:extendedDataTable> where;
Key of first map is the row label
Value of first map is a second map ( corresponds to the columns on the row
Key of second map is the columns header
Value of second map is the columns value
Source Code:
<rich:extendedDataTable
value="#{queryBean.resultMap.keySet().toArray()}" var="key"
frozenColumns="1" styleClass="rich-extdt">
<rich:column width="75px">
<f:facet name="header">
<h:outputText value="Mediation" />
</f:facet>
<h:outputText value="#{key}" />
</rich:column>
<rich:column width="75px">
<f:facet name="header">
<h:outputText value="Test" />
</f:facet>
<h:outputText value="#{queryBean.resultMap[key]}" />
</rich:column>
<c:forEach items="#{queryBean.resultMap[key]}" var="map">
<rich:column width="75px">
<f:facet name="header">
<h:outputText value="#{map.key}" />
</f:facet>
<h:outputText value="#{map.value}" />
</rich:column>
</c:forEach>
</rich:extendedDataTable>
Output:
The first column is correctly outputting the keys of the first map.
The second column (used for debugging) is correctly outputting the map structure ( when I apply .keySet() to the structure I do get all the correct keys ).
Using: jstl 1.2.0, jsf 2.1 - mojarra, richfaces 4.x, tomcat 7.
Update:
As stated here, the < c:forEach> has no access to the < rich:dataTable> attributes, hence unable to use key. Is there any simple workaround to this?

Resources