Running primefaces on java spring - spring

I used JSF with PrimeFaces very long time ago for class purposes.
Right now I want to get into spring and build a website for myself where I dont get any support for.
Usually what I want to do should be straight forward but somehow I dont really get what I done wrong, as - if im not mistaken - It should be just 1 dependency and the .html itself.
I added into the pom.xml
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>11.0.0</version>
</dependency>
I created a test2.html file:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
</h:head>
<h:body>
<p:spinner />
</h:body>
</html>
The outcome looks like this:
So my question is: Why dont the spinner gets shown on the test2.html site itself?

Related

Spring Boot Failed to load resource: the server responded with a status of 404

I am facing this error:
Failed to load resource: the server responded with a status of 404
Here is how I am loading css. Note that I am not using WebMvcConfigurer.
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>Material Design Bootstrap</title>
<!-- Font Awesome -->
<link rel="stylesheet" th:href="#{https://maxcdn.bootstrapcdn.com/font-awesome/4.6.0/css/font-awesome.min.css}">
<!-- Bootstrap core CSS -->
<link rel="stylesheet" th:href="#{/css/bootstrap.min.css}">
<!-- Material Design Bootstrap -->
<link rel="stylesheet" th:href="#{/css/mdb.min.css}">
<!-- Your custom styles (optional) -->
<link rel="stylesheet" th:href="#{/css/style.css}">
</head>
And I am loading js files at the end of the page (body).
<body>
......
<!-- SCRIPTS -->
<!-- JQuery -->
<script type="text/javascript" src="/static/js/jquery-3.1.1.min.js" th:src="#{/js/jquery-3.1.1.min.js}"></script>
<!-- Bootstrap tooltips -->
<script type="text/javascript" src="/static/js/popper.min.js" th:src="#{/js/popper.min.js}"></script>
<!-- Bootstrap core JavaScript -->
<script type="text/javascript" src="/static/js/bootstrap.min.js" th:src="#{/js/bootstrap.min.js}"></script>
<!-- MDB core JavaScript -->
<script type="text/javascript" src="/static/js/mdb.min.js" th:src="#{/js/mdb.min.js}"></script>
</body>
What could be the reason?
EDIT:
Here is my directory structure
Seems you are doing mistake while you are loading jquery. Your jquery is jquery-3.3.1.min.js but you are loading jquery-3.1.1.min.js
<script type="text/javascript" src="/static/js/jquery-3.1.1.min.js" th:src="#{/js/jquery-3.1.1.min.js}"></script>
So check jquery version.
this worked for me.
this is how my files are like in the static folder:
this is how i include the files from the static folder into my html pages:
i get rid of the static folder in the path since the server i guess knows to look for static content in the static folder. so the path for my all.min.css will be.
http://127.0.0.1:8080/js/demo/all.min.css
it will search for in the static folder.
if you add static i.e
{link href="/static/vendor/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css"}
the server will look for
http://127.0.0.1:8080/static/static/js/demo/all.min.css
and it won't get that path
remember to allow the routes in antmatchers if you're using spring security. see attached image
allow the routes to the folders in static folder if using spring security:
Load css
<link href="../static/assets/css/materialize.min.css" type="text/css"
rel="stylesheet" th:href="#{/assets/css/materialize.min.css}"
media="screen,projection">
Load js
<script type="text/javascript" src="../static/assets/js/materialize.min.js"
th:src="#{/assets/js/materialize.min.js}"></script>

How to develop single page application using JSP?

I want to develop an application using spring boot, jsp, bootstrap and hibernate. Where my each jsp page have the header, footer and left pane same but only the middle section get change based on the functionality. And i dont want to create each page with copying the same all over and even dont want impact application performance by adding all the UI dependencies in each and every JSP.
So can someone please suggest me the best approach to deal with it.
I searched and find the Angular JS an react JS options, but I already have one application built in Spring 4, JSP, Hibernate technology stack and one which i have to develop is going to integrate with old one, so I think technology stack may impact the integration. For integration i am thinking about maven multimodule project.
Hence I need suggestion as i am in initial stages of development .
You make use of jsp:include; Here is one tutorial but I'm sure there's many others. https://www.roseindia.net/jsp/include-tag-jsp.shtml
Example:
<jsp:include page="includes/header.jsp" flush="true">
<jsp:param name="title" value="Example" />
</jsp:include>
header.jsp:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>${ param.title }</title>
<link rel="stylesheet" type="text/css" href="<c:url
value="/bootstrap/3.3.6/css/bootstrap.min.css"/>" />
</head>

Spring Boot Security JSP tags

I have a Spring Boot webapp and Spring Security configured.
If I login as ADMIN I am not able to see the menu link configured like this:
<sec:authorize access="hasRole('ADMIN')">
<li>
<a href="references">References
</a>
</li>
</sec:authorize>
Any idea?
Thanks
R.
Be sure to add taglib in your jsp page.
<%# taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
And see that you have the dependency for it.
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-taglibs</artifactId>
<version>X.X.X</version>
</dependency>
The solution for my problem was the security authorized tag :
'
DISPLAY CONTENT
'

How to use Spring Webflow popup="true" with Primefaces?

Until now we were using Spring Webflow 2.3, which brought the "sf" namespace and Spring.js, which could be used to display view-states in a popup.
Webflow 2.4 deprecated Spring.js and removed the taglib with the following statement:
Previous releases of Spring Web Flow shipped with a component library which provided Ajax and client-side validation capabilities for JSF 1.2 environments. Applications using these components will need to switch to a 3rd party JSF component library such as PrimeFaces or RichFaces.
See: http://docs.spring.io/spring-webflow/docs/current/reference/htmlsingle/#spring-faces-upgrade-from-swf23-components
Now i have added a dependency to Primefaces 5.2 to my pom.xml and everything seems to work fine, except for SWF Popups, which simply redirect to the new view-state.
First page:
<ui:composition template="#{templatePath}"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<ui:define name="content">
<h:form id="formDashboard">
<p:commandButton id="addWidget" value="Hinzufügen" action="add-widget"/>
</h:form>
</ui:define>
</ui:composition>
Second page (should be rendered in a popup):
<ui:composition
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<ui:fragment id="popupFragment">
abc
</ui:fragment>
</ui:composition>
Flow definition:
<flow xmlns="http://www.springframework.org/schema/webflow"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/webflow http://www.springframework.org/schema/webflow/spring-webflow.xsd">
<view-state id="start" view="dashboard.xhtml">
<transition on="add-widget" to="popup-addWidget"/>
</view-state>
<view-state id="popup-addWidget" view="popup-addWidget.xhtml" popup="true">
<on-render>
<render fragments="popupFragment"/>
</on-render>
</view-state>
</flow>
Spring configuration:
<bean class="org.springframework.faces.webflow.JsfFlowHandlerAdapter">
<property name="flowExecutor" ref="flowExecutor"/>
</bean>
<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping">
<property name="flowRegistry" ref="flowRegistry"/>
</bean>
<webflow:flow-executor id="flowExecutor" flow-registry="flowRegistry">
<webflow:flow-execution-listeners>
<webflow:listener ref="facesContextListener"/>
</webflow:flow-execution-listeners>
</webflow:flow-executor>
<webflow:flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices"/>
<!-- Populates the flowRegistry on startup. Removing this and manually adding all flows changes nothing. -->
<bean class="config.FlowRegisteringBeanPostProcessor"/>
<faces:flow-builder-services id="flowBuilderServices"/>
<faces:resources/>
<bean id="facesContextListener" class="org.springframework.faces.webflow.FlowFacesContextLifecycleListener"/>
I'm not including the web.xml, since there is nothing special.
Using Mojarra 2.2, Primefaces 5.2, Spring 4.2 and Webflow 2.4.1.
Using Firebug i can see that the server POST response issues to redirect, which JSF/Primefaces honors and does a full redirect to the new view-state instead of showing a popup:
<?xml version='1.0' encoding='UTF-8'?>
<partial-response id="j_id1"><redirect url="/Demo/spr/dashboard?execution=e1s2"></redirect></partial-response>
If anybody managed to get popup="true" working with these versions, with or without Spring.js, i'd be happy to hear about it.
We ended up using Primefaces' p:dialog and p:confirmDialog, instead of Webflow popups.
This doesn't really answer my question, but i can't see an answer to this seeing that Webflow sends the same response no matter if popup is set to true or false.

Java Web: How use JSP with JSF and Ajax?

i'm working in a project with jsp, i need to start to use ajax too.
i'm enjoying jsf , is possible work with these together (JSP, JSF and AJAX) ?
I'm asking this cause i could run jsf with ajax
<h:commandButton id="bt_save" value="Save" title="Save" action="#personMBean.clickSave()}">
<f:ajax execute="#form" render="lblMessage" />
</h:commandButton>
<br/>
<h:outputLabel id="lblMessage" value="#{personMBean.message}" />
But when i try input this code in my jsp page it doesn't work, even if i insert on my jsp page:
<%#page contentType="text/html"%>
<%#page pageEncoding="UTF-8"%>
<%#taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%#taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
Any ideas ?
Ensure that you're using JSF 2.x (the <f:ajax> doesn't exist in JSF 1.x) and that you've a <h:head> instead of <head> in the master template (so that JSF can auto-include necessary Ajax JavaScripts).
Said that, you should really consider Facelets as replacement of JSP. JSP is an outdated view technology and ill suited for templating and has been replaced by Facelets as per JSF 2.0 / Java EE 6.
Yes - try richfaces or primefaces
I don't see why you couldn't do this but certainly not on the same page.
To do this you need to map the *.jsp extension to the JSP servlet while mapping the *.jsf or *.xhtml to FacesServlet.

Resources