OmniFaces loading/unloading ViewScopedBean - primefaces

Trying to narrow in on our issue we are upgrading from Jboss 6 EAP (JSF 2.1) to Jboss 7 EAP (JSF 2.2). Our working application now has an issue with OmniFaces ViewScoped beans.
Versions:
Mojarra 2.2.14
OminFaces 2.6.9
PrimeFaces 6.2.5
We have a datatable like this:
<p:dataTable id="tblLegalHolds" widgetVar="tableLegalHolds" var="row"
rowKey="#{row.id}" filterEvent="enter"
lazy="true"
value="#{bean.lazyDataModel}"
rows="15">
NOTE: Our bean is OmniFaces ViewScoped and our table is working fine at this point!
Problem:
Next we add a column that contains a navigation to a new page like this:
<p:column width="60" exportable="false">
<p:button value="Open" outcome="legal-hold-edit">
<f:param name="id" value="#{row.id}" />
</p:button>
</p:column>
Now our bean is getting loaded and unloaded immediately and if we do a View Source of the HTML we see the Omnifaces script added twice like so...
OmniFaces.Unload.init('f1c1ff81-c87f-4406-b98f-a3eaff977e96');
OmniFaces.Unload.init('45e7de9d-53c7-4426-a972-797c48c46733');
We added #PostConstruct to our ViewScoped beans to prove its getting called twice. Our faces-config.xml looks like this for that Navigation.
<navigation-case>
<from-outcome>legal-hold-edit</from-outcome>
<to-view-id>/legal/legal-hold-edit.xhtml</to-view-id>
<redirect include-view-params="true"/>
</navigation-case>
Now what is interesting is if we remove the "include-view-params" in faces-config.xml like the code below everything starts working fine the ViewScoped bean is created only once and only 1 OmniFaces.Unload.init script is added to the page.
<navigation-case>
<from-outcome>legal-hold-edit</from-outcome>
<to-view-id>/legal/legal-hold-edit.xhtml</to-view-id>
<redirect/>
</navigation-case>
As an added note our outcome page is using o:viewparam to receive the param like this:
<f:metadata>
<o:viewParam name="id" value="#{legalHoldForm.legalHold}" required="false" />
<f:event type="preInvokeAction" listener="#{controller.initializeViewLegalHold}" />
</f:metadata>
So my questions are:
Why does removing "include-view-params" make it work?
Is this a bug similar to this recent ViewScoped issue? : https://github.com/omnifaces/omnifaces/issues/463

This appears to be a bug in Mojarra. It's indirectly calling the PreDestroyViewMapEvent when figuring out the view parameters for the other view.
During the render response phase, when the URL for an UIOutcomeTarget component (e.g. <p:button>) is to be generated, and includeViewParams is set to true (as defined in your navigation case), then it needs to consult all <f:viewParam> of the target view. In order to achieve this, it will need to build an UIViewRoot instance of it.
However, it actually temporarily sets that new UIViewRoot as the current view root of the faces context in order to access the <f:viewParam>. It will restore the original view, but this is where it goes wrong in Mojarra. It is restoring context.setProcessingEvents(true) too early. It should actually have done it after restoring the original view.
For now, your best bet is to report this issue against Mojarra and avoid using includeViewParams in combination with OmniFaces #ViewScoped.

Issue reported: https://github.com/eclipse-ee4j/mojarra/issues/4503
PR Provided: https://github.com/eclipse-ee4j/mojarra/pull/4730
This fix will be included in 2.3.15, 3.0.1 and 4.0.0 of Mojarra.

Related

Razor syntax in core class project

I've added a core class project to my solution with a controller and view. The solution runs and loads the controller and view fine.
The problem is I don't have the razor syntax in the view. I'd like to use the #Model and the helpers etc. I've seen information online but none relating to .Net Core class projects.
Help would be good
Convert the class project to a mini Web project. Razor support in non-web projects is not a popular request at this moment.
Edit a csproj file to:
<Project Sdk="Microsoft.NET.Sdk.Web">
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
</ItemGroup>
Add empty Program class with Main method cause compiler will ask for this.

How can I use an appSetting parameter (located in web.config) in my .master template

appSetting parameters
I have a value within app settings that I would like to use in my master page file but I think I am using the wrong syntax. Please bear with me because I am very new to Umbraco
My Web.config code is
<appSettings>
<add key="myKey" value="7829e" />
</appSettings>
The code within my master page is
<umbraco:Macro runat="server" language="cshtml">
#AppSetting.myKey
</umbraco:Macro>
It's not Umbraco related at all, you should be able to do
ConfigurationManager.AppSettings["key"]
Just like you would in standard ASP.NET.

Fileupload of PrimeFaces is not working in my liferay portlet?

I am using primefaces 3.3.1 and liferay 6.
In my portlet I want to add fileUpload for primefaces. But each time whenever my page loads this primefaces component is not visible through firebug. I need to make its display to block.
Also, any components below the fileUpload which consists of javascript method or ajax is not working.
I have noticed that in firebug whenever my page loads it shows me one error such as
this.form.fileUpload is not a function
I guess due to this error my fileUpload is not working. But I am not able to to fix it.
<p:fileUpload fileUploadListener="#{fileUploadController.handleFileUpload}" mode="advanced" fileLimit="3"/>
Upgrade your primefaces to version 3.5 and add commons-fileupload to your project
I think it caused by you didn't add the commons-fileupload and commons-io in your project lib. Also, don't forget do define FileUploadFilter in your web.xml.
Let me show you how i did file upload in my primefaces before, hope this example can solve your problem.
My xhtml page :
<p:fileUpload allowTypes="/(\.|\/)(csv)$/" fileUploadListener="#{fileBean.handleFileUpload}"/>
My FileBean.java :
public class FileBean {
private UploadedFile file;
public void handleFileUpload(FileUploadEvent event) throws Exception {
file = event.getFile();
InputStream input = file.getInputstream();
OutputStream output = new FileOutputStream(new File("D:/UploadedFile/", file.getFileName()));
IOUtils.copy(input, output);
}
Add this to your web.xml :
<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>
org.primefaces.webapp.filter.FileUploadFilter
</filter-class>
</filter>
And as I said before, add commons-fileupload and commons-io to your project lib.
Fixed this issue in Liferay Portal 6.0.x.
Can you add this code to web.xml and try it?
<!-- Workaround for PrimeFaces 3.2: -->
<context-param>
<param-name>com.liferay.faces.bridge.primeFileUploadForceResourceURL</param-name>
<param-value>true</param-value>
</context-param>
Here is link for more information.
After trying everything else concerning web.xml,pom.xml,... I came back to the obvious things :-)
Maybe you are just forgetting to wrap an form around your upload elements:
<h:form enctype="multipart/form-data">
<p:fileUpload mode="simple" value="#{mgr.file}"/>
<p:commandButton value="Hochladen" ajax="false" onclick="start();"
action="#{mgr.uploadBescheid(bescheidTyp)}" update="growl"/>
</h:form>
Without that point it won't work...

Primefaces Data Exporter with Primefaces Editor

Is it possible to export the editor data to pdf using Data exporter of primefaces.
I tried with following code but it didnt worked.
<p:editor value="#{mailBean.mail}" id="editor">
</p:editor>
<p:commandLink>
<p:graphicImage value="/images/pdf.gif" />
<p:dataExporter type="pdf" target="editor" fileName="files" pageOnly="true"/>
</p:commandLink>
No its not
from the user guide:
DataExporter is handy for exporting data listed using a Primefaces Datatable to various formats
such as excel, pdf, csv and xml.
more from the user guide
Target must
point to a PrimeFaces Datatable
Edit
What you could try is : Integrate TinyMCE editor in your project and take a look at this thread HTML to PDF demo , here is a direct link WYSIWYG Editor Export to PDF
Data exporter publisher button must not ajax, and target value should refer to an datatable, also you need itext 2.1.7 Optional DataExporter (PDF) *apache poi 3.7 Optional DataExporter* libraries (Excel)..
Even if they are all right, data exporter not stable yet, it depends your datatable. For example it can not export data when you use dynamic column with column group.
I prefer export your own documents using itext libraries, its also more flexible.
Good Luck!
if the Target must point to a PrimeFaces Datatable , then how the below code is possible
this is from primeface site .(http://www.primefaces.org/showcase/ui/chartExport.jsf)
<p:lineChart value="#{chartBean.linearModel}" legendPosition="e" zoom="true"
title="Linear Chart" minY="0" maxY="10" style="width:500px;height:300px" widgetVar="chart"/>
<p:commandButton type="button" value="Export" icon="ui-icon-extlink" onclick="exportChart()"/>
<p:dialog widgetVar="dlg" showEffect="fade" modal="true" header="Chart as an Image">
<p:outputPanel id="output" layout="block" style="width:500px;height:300px"/>
</p:dialog>
function exportChart() {
//export image
$('#output').empty().append(PF('chart').exportAsImage());
//show the dialog
PF('dlg').show();
}
here the source file is a chart and using the function exportChart() get the exported data as image.that means we can export any data not only the primeface datatable.

How to display a detailed map and highlevel map in different classes/tabs?

I have two activities, ListViewActivity and MapViewActivity which both run within a TabHost; everything is working fine and I am able to view my list, add POIs to the map, change between tabs etc.
What I have also done is to 'extend' my ListViewActivity so that when an item in the List is clicked, the view is switched (via ViewSwitcher) to show more detail (note: this happens within the same tab); again this all works okay and I am able to flip between the list view and the detailed view which contains text elements, buttons etc.
But, since I've only been programming in Android/JAVA for a few weeks, I've hit a brick wall... and need some pointers/high level examples to get me going again.
<com.google.android.maps.MapView
android:id="#+id/mapView"
android:layout_width="150dp"
android:layout_height="150dp"
android:apiKey="0sQLOXF5j7iM03sd-IyVldoGjh0voa5-qqFRRlw"
android:clickable="false"
android:enabled="true" />
Specifically, I want the 'extended/detailed' view within the ListViewActivity to include a detailed/zoomed map. However, when I try to include the map definition in my XML code (see above), it causes the application to crash - I am assuming because there is already a map defined in MapViewActivity (i.e. this code appears in both my ListViewActivity.xml and my MapViewActivity.xml files)?
I've read found other pages such as this, which recommend using the android:process attribute in the manifest to assign acitivites, for example:
activity android:name=".activity.directory.MapView1" android:process=":MapView1"
activity android:name=".activity.directory.MapView2" android:process=":MapView2"
However, I am uncertain how to implement this - i.e. how do I call the process from either the ListViewActivity or MapViewActivity class such that either a detailed or high-level map is displayed?
Currrently my AndroidManifest.XML file is as shown below; I know this is incorrect, but like I said, I'm stuck in figuring out how to have a map both in my ListViewActivity and in my MapViewActivity:
<application
android:icon="#drawable/launcher"
android:label="#string/app_name" >
<activity
android:label="#string/app_name"
android:name=".DummyAppName" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ListViewActivity"/>
<activity android:name=".MapViewActivity"/>
<activity android:name=".FavouritesActivity"/>
<activity android:name=".SettingsActivity"/>
<activity android:name=".activity.directory.MapView1" android:process=":MapView1"/>
<activity android:name=".activity.directory.MapView2" android:process=":MapView2"/>
Sorry for the long post. I hope it makes sense and I hope someone is able to offer some ideas/suggestions on how to fix my problem (is it even possible?).
Thank you!