Using Omnifaces EL functions in composite component with Mojarra 2.2.5 - composite-component

After upgrading to JSF Mojarra 2.2.5, i get the following exception when using Omnifaces's el function formatNumber. This only occurs within a composite component. Normal Facelet is working fine.
javax.el.ELException: Function 'of:formatNumber' not found
this is my composite component:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:jsf="http://xmlns.jcp.org/jsf"
xmlns:cc="http://xmlns.jcp.org/jsf/composite"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:of="http://omnifaces.org/functions">
<cc:interface>
<cc:attribute name="cart" required="true" type="org.ead.eeb.order.ShoppingCart" />
<cc:attribute name="allowCouponRemove" required="true" type="java.lang.Boolean" />
<cc:attribute name="removeCouponBean" type="java.lang.Object" />
<cc:attribute name="removeCouponAction" type="java.lang.String" />
<cc:attribute name="removeCouponProperty" type="java.lang.String" />
</cc:interface>
<cc:implementation>
<h4>Übersicht</h4>
<table class="table">
<tbody>
<c:forEach items="#{cc.attrs.cart.items}" var="item">
<tr>
<td><abbr title="#{item.description}">#{item.name}</abbr></td>
<td class="text-right">#{of:formatNumber(item.totalAmount, '#0.00')} €</td>
</tr>
</c:forEach>
<tr>
<td>Mehrwertsteuer (#{cc.attrs.cart.taxRatePercentage} %)</td>
<td class="text-right">#{of:formatNumber(cc.attrs.cart.totalTax, '#0.00')} €</td>
</tr>
</tbody>
<tfoot>
<tr class="active">
<td><strong>Gesamtbetrag</strong></td>
<td class="text-right"><strong>#{of:formatNumber(cc.attrs.cart.totalOrderAmount, '#0.00')} €</strong></td>
</tr>
</tfoot>
</table>
...
</cc:implementation>
thanks in advance for your help :)
Edit:
the problem occurs, if i use the value from cc.attrs.*. If I use the value directly as an attribute, everthing is working well. Any ideas?
Edit2:
A workaround is possible by the following code
<c:set var="test" value="#{cc.attrs.value}" />
#{of:formatNumber(test, '#0.00')}
but that's pretty ugly. I can't find my mistake.

The issue i created was marked as Wont't Fix, since there is a workaround:
Replacing all convenient inline el calls of type #{foo} with <h:outputText value="#{foo}"/>.
https://java.net/jira/browse/JAVASERVERFACES-3469
Very inconvenient and cumbersome. Many regressions from 2.2.4 -> 2.2.5.

Related

Modify record using Struts2

I have a table with a list of shows, my idea is to have a button that allows modifying each show:
...
<s:iterator value="%{listShow}" var="show">
<tr>
<td><s:property value="showId"></s:property></td>
<td><s:property value="showName"></s:property></td>
<td><s:property value="showDate"></s:property></td>
<td><s:property value="showPrice"></s:property></td>
<td><s:form action="goModify">
<s:submit value="Modify"></s:submit>
<s:hidden name="showId"></s:hidden>
<s:hidden name="showName"></s:hidden>
<s:hidden name="showDate"></s:hidden>
<s:hidden name="showPrice"></s:hidden>
</s:form></td>
</tr>
</s:iterator>
...
The only thing action "goModify" does is redirect to a modify.jsp file where I want to make the data changes:
<s:form action="modifyAction">
<s:textfield label="ID" name="showId" value="%{showId}"></s:textfield>
<s:textfield label="Show Name" name="showName" value="%{showName}></s:textfield>
<s:textfield label="Date" name="showDate" value="%{showDate}></s:textfield>
<s:textfield label="Price" name="showPrice"value="%{showPrice}></s:textfield>
<s:submit value="Modificar"></s:submit>
</s:form>
The problem that the filled fields do not appear to me.
You are only assigning a name to the hidden fields, not a value. You can use the attribute key instead of name. It will automatically generate HTML with the correct name and value.
<s:iterator value="%{listShow}" var="show">
<tr>
<td><s:property value="showId" /></td>
<td><s:property value="showName" /></td>
<td><s:property value="showDate" /></td>
<td><s:property value="showPrice" /></td>
<td>
<s:form action="goModify">
<s:submit value="Modify" />
<s:hidden key="showId" />
<s:hidden key="showName" />
<s:hidden key="showDate" />
<s:hidden key="showPrice" />
</s:form>
</td>
</tr>
</s:iterator>
If the action goModify does not store the parameters in the value stack (e. g. by storing them in attributes), you may have to change the JSP to access the request parameters directly.
<s:form action="modifyAction">
<s:textfield label="ID" name="showId" value="%{#parameters.showId}" />
<s:textfield label="Show Name" name="showName" value="%{#parameters.showName} />
<s:textfield label="Date" name="showDate" value="%{#parameters.showDate} />
<s:textfield label="Price" name="showPrice" value="%{#parameters.showPrice} />
<s:submit value="Modificar"></s:submit>
</s:form>
However, the best solution for the second JSP would also be to use key instead of name and value. But then you have to make sure to have the values on the value stack.

datatable returns a null selected object if it is filtered primefaces 5.0

Hope somebody may give me a hint on this case, searched a lot before posting this question with no luck.
I have a datatable that allows only a single row selection (it may include 200 rows at a time), after one is selected, a commandButton redirects the user to a new form to display some information.
The problem rises when user first applies a filter in the datatable on any given column, selects a row and clicks the commandButton, my backing bean (#ViewScoped) receives no selected object (null)
Since the form is big, here i post just part of it to display the Datatable structure:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:fn="http://java.sun.com/jsp/jstl/functions">
<h:body >
<h:form id="Form1">
<p:outputPanel id="ID1">
.
.
.
<table cellpadding="4" cellspacing="4" border="0" style="width: 100%;">
<tr>
<td><b><big><big><font face="Arial" >#{beanD.MenuTitle} > List of records </font></big></big></b></td>
<td>
<b><big><font face="Arial"><p:outputLabel value="|" /></font></big></b>
</td>
<td style="width: 150px;">
<p:commandButton style="font-family:Arial;font-size: 13px;" icon="ui-icon-check" value="Open Record" ajax="false"
actionListener="#{MBR.Method1(2,MBR.var1.cod,MBR.var1.codS)}" action="#{beanD2.url_Menu('FormRedirected')}"/>
</td>
</tr>
</table>
<table cellpadding="4" cellspacing="4" border="0">
<tr>
<td>
<p:dataTable var="Rad" selectionMode="single" value="#{MBSg.list}"
id="RSTable" widgetVar="RS" selection="#{MBR.var1}" rowKey="#{Rad.codS}"
style="font-family: Arial;font-size: 12px; height: 320px;" emptyMessage="No Records"
scrollable="true" scrollHeight="100%;" frozenColumns="1" styleClass="FirstCol" >
<p:column headerText="Header1" filterStyle="font-family:Arial;font-size: 12px;width:60px;" filterBy="#{Rad.field1}" filterMatchMode="contains" style="font-family:Arial;font-size: 12px;width: 60px;">
<h:outputText value="#{Rad.field1}" />
</p:column>
<p:column headerText="Header2" filterBy="#{Rad.field2}" filterMatchMode="contains" style="font-family:Arial;font-size: 12px;width: 250px;">
<h:outputText value="#{Rad.field2}" />
</p:column>
<p:column headerText="Header3" filterBy="#{Rad.field3}#{Rad.entidades}" filterMatchMode="contains" style="font-family:Arial;font-size: 12px;width: 900px;">
<h:outputText value="#{Rad.field3}" />
</p:column>
<p:column headerText="Header4" filterBy="#{Rad.field4}" filterMatchMode="contains" style="font-family:Arial;font-size: 12px;width: 100px;">
<h:outputText value="#{Rad.field4}" />
<p:column headerText="Header5" filterStyle="font-family:Arial;font-size: 12px;width:70px;" filterBy="#{Rad.field5}" filterMatchMode="contains" style="font-family:Arial;font-size: 12px;width: 120px;">
<h:outputText value="#{Rad.field5}" />
</p:column>
</p:dataTable>
</td>
</tr>
</table>
</p:outputPanel>
</h:form>
</h:body>
</html>
This is the method in my backing bean (MBR) that evaluates selection made by user (stored in variable var1 )
#ManagedBean(name = "MBR")
#ViewScoped
public class BeanR {
.
.
public void Method1(int proc, int num, int num_s) {
try {
if (var1 == null) {
mbT.setMens("No item Selected");
mbT.warn();
mbT.resetTable("Form1:RSTable");
..."some other operations performed"
} else {
Method2(proc, num, num_s);
}
} catch (ParseException e) {
mbT.setMens("Error in MBR : '" + this.getClass() + ".Method1()' caused by: " + e.getMessage());
mbT.error();
}
}
}
As mentioned before, if selection is made after filtering ( then commandButton clicked) this message is launched in my bean: mbT.setMens("No item Selected");
By the way, filtering works fine, not problems at all.
Application is developed using Primefaces 5.0 with no chance to upgrade right now
Any work around will be appreciated, i have googled and read PrimeFaces showcases but have not found any answer,
Best regards.
Last Update:
After lots of tests i figured out that DataTable's Attribute frozenColumns was the one causing this strange behaviour when table was filtered. Hopefully any expert in StackOverflow may give us a deeper insight on the reasons behind it.
As per my problem, after removing the attribute the datatable worked fine. Hope anyone finds this usefull in future.
I have encountered similar issue and finally figure out that I have missed the filteredValue attribute in the dataTable tag.
Add a rowKey as a property on p:dataTable component.
<p:dataTable value="#{myBean.cars}" var="car" rowKey="#{car.id}">
...
<p:dataTable>

How Can i Update a Table (not datatable) with a Primefaces CommandButton

<h:form id="tableForm">
<table id="myTable">
<tr>
<th>HeaderOne</th>
<th>HeaderTwo</th>
<th>HeaderThree</th>
</tr>
<ui:repeat value="#{myBean.List}" var="row">
<tr class="myRows">
<td><input type="text" value="#{row.fieldOne} required="required" /></td>
<td><input type="text" value="#{row.fieldTwo} /></td>
<td><input type="text" value="#{row.fieldThree} /></td>
</tr>
</ui:repeat>
</table>
<p:commandButton id="myButton" value="Load" action="#{myBean.load}" process="#this" update="myTable" />
</h:form>
i want to load some stuff into my inputFields from my bean, but have one field that is required when i press save. So i have to set process to #this.
Afterwards i want my table to be updated. But i doesn't work.
What am i doing wrong?
try updating the form instead
<p:commandButton ... action="#{myBean.load}" process="#this" update="tableForm" />
since the table is not a jsf element but "pure" html, you can't use it's id in jsf elements
Schäbo answer is right (+1) but Primefaces also provides a p:fragment component so you may update only the region you want to:
<p:fragment id="myFragmentReloaded">
<table>
...
</table>
</p:fragment>
and then
<p:commandButton ... action="#{myBean.load}" process="#this" update="myFragmentReloaded" />

convert html table to PrimeFaces datatable

I want to convert html table to primeface datatable, I have converted some more table in my project but below code is bit complex so I need your help, here columns are created using different list and rows are from different list.
<table >
<thead>
<tr >
<th style="width:45px;">Id</th>
<th>#{msg['manage.relationship.type.name']}</th>
<c:forEach items="#{manageRelationBean.languageList}" var="languageName" >
<th>#{languageName}</th>
</c:forEach>
<th style="width:75px;">#{msg['manage.relationship.action']}</th>
</tr>
</thead>
<tbody>
<c:forEach items="#{manageRelationBean.languageRelList}" var="languageRelDTO">
<tr>
<td>#{languageRelDTO.relationId}</td>
<td>#{languageRelDTO.relationName}</td>
<c:forEach items="#{languageRelDTO.languageList}" var="relationValues">
<td>#{relationValues.relationValue}</td>
</c:forEach>
</tr>
</c:forEach>
</tbody>
</html>
Have you looked at the Showcase example? http://www.primefaces.org/showcase/ui/datatableBasic.jsf
Here is something like your example, for the first few columns. Notice the ForEach within the datatable- This will allow dynamic columns like you have.
<h:form>
<p:dataTable var="languageRelDTO" value="#{manageRelationBean.languageRelList}">
<p:column headerText="Id">
<h:outputText value="#{languageRelDTO.relationId}" />
</p:column>
<p:column headerText="#{msg['manage.relationship.type.name']}">
<h:outputText value="#{languageRelDTO.relationName}" />
</p:column>
<c:forEach items="#{manageRelationBean.languageList}" var="languageName">
<p:column headerText="#{languageName}" />
<h:outputText value="#{languageRelDTO.languageList[languageName.index]}" />
</p:column>
</c:forEach>
</p:dataTable>
</h:form>
Didn't test it, but you should get the idea.

xml data island doesn't work

I've got a simple xml document main.xml
<?xml version="1.0"?>
<students>
<student>
<name>Name1</name>
<surname>Surname1</surname>
</student>
<student>
<name>Name2</name>
<surname>Surname2</surname>
</student>
<student>
<name>Name3</name>
<surname>Surname3</surname>
</student>
</students>
Also I've got a html page main.html where I want to show data from xml file.
<html>
<head>
<title>Test XML</title>
</head>
<body>
<xml id="students" src="main.xml"></xml>
<table id="table" datasrc="#students" border="1">
<thead>
<th>Student name</th>
<th>Student surname</th>
</thead>
<tbody>
<td><span datafld="name"></span></td>
<td><span datafld="surname"></span></td>
</tbody>
</table>
</body>
</html>
But it doesn't work - It shows only head of the table. Also both files are in the same folder. Why?
I'm using Windows 7 and IE8
The case is solved: I forgot tag tr before tds.