Razor syntax in core class project - razor

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.

Related

OmniFaces loading/unloading ViewScopedBean

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.

ASP.NET Core Razor precompiled views in a class library

Is this possible? Adding the following two lines to a csproj for a web application enables precompilation and produces a Project.PrecompiledViews.dll:
<MvcRazorCompileOnPublish>true</MvcRazorCompileOnPublish>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.ViewCompilation" Version="1.1.0" />
Adding the same two lines to a class library which contains views does not produce a Library.PrecompiledViews.dll. Is this not currently supported, or does a class library require a little more coaxing?

What's the difference between Properties/DisplayName element and VisualElements#DisplayName attribute in .appxmanifest file

In following appxmanifest, what is the difference between
Package/Properties/DisplayName element
and
Package/Applications/Application/VisualElements#DisplayName
<?xml version="1.0" encoding="utf-8"?>
<Package xmlns="http://schemas.microsoft.com/appx/2010/manifest">
<Identity Name=""
Version=""
Publisher="" />
<Properties>
<DisplayName></DisplayName> <!-- this -->
<PublisherDisplayName></PublisherDisplayName>
<Logo></Logo>
</Properties>
<Prerequisites>
<OSMinVersion></OSMinVersion>
<OSMaxVersionTested></OSMaxVersionTested>
</Prerequisites>
<Resources>
<Resource Language="" />
</Resources>
<Applications>
<Application Id="" StartPage="">
<!-- and this -->
<VisualElements DisplayName=""
Description=""
Logo="" SmallLogo=""
ForegroundText="" BackgroundColor="">
<SplashScreen Image="" />
</VisualElements>
</Application>
</Applications>
</Package>
https://msdn.microsoft.com/en-us/library/windows/apps/br211475.aspx
Package/Properties/DisplayName
The DisplayName is the name of your app that you reserve in the store, for apps which are uploaded to the store.
This is the actual reserved name in the developer portal (= store). When you package your app for upload to the store, this will be automatically set when going through the wizard in Visual Studio.
The root element Visual Elements is how the Windows Store app is visualized on the user's pc/phone.
Package/Applications/Application/VisualElements
Describes the visual aspects of the Windows Store app: its default tile, logo images, text and background colors, initial screen orientation, splash screen, and lock screen tile appearance.
So the DisplayName property under the Visual Elements element is how the app's name is shown on the user's pc. This can be different from the name in the store (e.g. localized).
A friendly name for the app that can be displayed to users. This string is localizable; see Remarks for details.
There are two explicitly reserved words that may not be used as the DisplayName for apps uploaded to the Windows Store: "NoUIEntryPoints" and "NoUIEntryPoints-DesignMode". These identifiers are reserved for use by development tools and test suites.
Source: https://msdn.microsoft.com/en-us/library/windows/apps/br211471.aspx
I have an app in the Store that may explain this issue.
Package/Properties/Display Name element refers to the app name in the Store which is the same as what's in Dashboard. While if you change the Display Name distribute in Visual Elements, your app will be different from itself in the Store after user installs it from the Store.

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...