I'm trying to integrate Spring Security inside ui:composition.
I'm getting help from this helpful link : https://raichand-java.blogspot.in/2016/12/springsecurity4primefaces5springdatajpa.html
It works as well.
But, after integrating the code inside ui:composition, I got an exception.
Knowing that I added the file springsecurity.taglib.xml:
<?xml version="1.0"?>
<!DOCTYPE facelet-taglib PUBLIC
"-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN"
"http://java.sun.com/dtd/facelet-taglib_1_0.dtd">
<facelet-taglib>
<namespace>http://www.springframework.org/security/tags</namespace>
<tag>
<tag-name>authorize</tag-name>
<handler-class>org.springframework.faces.security.FaceletsAuthorizeTagHandler</handler-class>
</tag>
<function>
<function-name>areAllGranted</function-name>
<function-class>org.springframework.faces.security.FaceletsAuthorizeTagUtils</function-class>
<function-signature>boolean areAllGranted(java.lang.String)</function-signature>
</function>
<function>
<function-name>areAnyGranted</function-name>
<function-class>org.springframework.faces.security.FaceletsAuthorizeTagUtils</function-class>
<function-signature>boolean areAnyGranted(java.lang.String)</function-signature>
</function>
<function>
<function-name>areNotGranted</function-name>
<function-class>org.springframework.faces.security.FaceletsAuthorizeTagUtils</function-class>
<function-signature>boolean areNotGranted(java.lang.String)</function-signature>
</function>
<function>
<function-name>isAllowed</function-name>
<function-class>org.springframework.faces.security.FaceletsAuthorizeTagUtils</function-class>
<function-signature>boolean isAllowed(java.lang.String, java.lang.String)</function-signature>
</function>
</facelet-taglib>
I added to the file web.xml:
<context-param>
<param-name>javax.faces.FACELETS_LIBRARIES</param-name>
<param-value>/WEB-INF/springsecurity.taglib.xml</param-value>
</context-param>
After running this page:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<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:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Login</title>
<h:outputScript library="primefaces" name="jquery/jquery.js"
target="head" />
<h:outputScript library="primefaces" name="jquery/jquery-plugins.js"
target="head" />
</h:head>
<h:body>
<ui:composition template="/templates/homeTemplate.xhtml"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:sec="http://www.springframework.org/security/tags"
xmlns:p="http://primefaces.org/ui">
<ui:define name="content">
<center><h2>Login</h2></center>
<c:if test="${'fail' eq param.auth}">
<div style="color:red">
Login Failed!!!<br/>
Reason : Bad Credentials!Please Try Again.
</div>
</c:if>
<center>
<h:form prependId="false" id="form">
<p:panelGrid columns="2" style="border-bottom-width: 0px;">
<h:outputText value="UserName:"/>
<p:inputText value="#{loginController.username}" id="username" required="true" requiredMessage="UserName is required"/>
<h:outputText value="Password:"/>
<p:password value="#{loginController.password}" id="password" required="true" requiredMessage="Password is required"/>
</p:panelGrid>
<p:spacer height="20px" width="10px"> </p:spacer>
<p:row>
<p:selectBooleanCheckbox label="Remember Me" id="remember-me" >Remember Me </p:selectBooleanCheckbox>
<h:outputText value=" " />
</p:row>
<br/>
<p:row>
<p:commandButton action="#{loginController.login()}" value="Login" ajax="false"/>
</p:row>
</h:form>
</center>
</ui:define>
</ui:composition>
</h:body>
</html>
I got this exception:
SEVERE [javax.enterprise.resource.webcontainer.jsf.config] (ServerService Thread Pool -- 175) Critical error during deployment: : com.sun.faces.config.ConfigurationException: CONFIGURATION FAILED! org.springframework.faces.security.FaceletsAuthorizeTagHandler from [Module "deployment.mission-man-ear.ear.mission-man-web.war:main" from Service Module Loader]
at com.sun.faces.config.ConfigManager.initialize(ConfigManager.java:453)
at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:227)
at io.undertow.servlet.core.ApplicationListeners.contextInitialized(ApplicationListeners.java:187)
at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:198)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.startContext(UndertowDeploymentService.java:100)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentService$1.run(UndertowDeploymentService.java:82)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:748)
at org.jboss.threads.JBossThread.run(JBossThread.java:320)
After googling, I found this thread java.lang.ClassNotFoundException: org.springframework.faces.security.FaceletsAuthorizeTagHandler, but didn't help me!. I think that there's a problem of version of spring-security-taglibs dependency version. Have you please any idea about solving this. Any help is appreciated. Thanks a lot.
I's no need to make the new changes.
Try Run As> Maven Clean, Run As> Maven Install then Maven> Update Project.
That's all.
HTH
Related
This question already has answers here:
Conversion Error setting value for 'null Converter' - Why do I need a Converter in JSF?
(2 answers)
Closed 6 years ago.
I have a problem with the JSF selectOneMenu.
Here is my menu:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">
<ui:composition template="./../WEB-INF/templates/templateLC.xhtml">
<ui:define name="headtags">
<title>Title</title>
</ui:define>
<ui:define name="left">
<ui:include src="./../WEB-INF/templates/userCenterNavigation_left.xhtml"/>
</ui:define>
<ui:define name="content">
<h:form>
<table>
<tr>
<td>Kategorie:</td>
<td><h:selectOneMenu value="#{zbnEditController.zbnCategory}">
<f:selectItems value="#zbnEditController.zbnCategoryMap}"/>
</h:selectOneMenu>
</td>
</tr>
</table>
<br />
<h:commandButton value="Hinzufügen" action="#{zbnEditController.doSave()}" />
<h:commandButton value="Abbrechen" action="index.xhtml?faces-redirect=true" />
</h:form>
This is a part of my template:
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<h:outputStylesheet name="/css/newCssLayout.css"/>
<ui:insert name="headtags" />
</h:head>
This is my Bean with the Map property:
#Named
#SessionScoped
public class ZbnEditController implements Serializable {
#Inject
private ZbnCategoryService zbnCategoryService;
.
.
.
private Map<String,ZbnCategory> zbnCategoryMap = new HashMap<>();
//Getter & Setters...
public void doSave(){
//persist Entity Code
}
public void loadZbnCategoryMap(){
getZbnCategoryMap().clear();
List<ZbnCategory> zbnCategoryList = zbnCategoryService.getAllZbnCategorys();
for(ZbnCategory zbnCategoryInList : zbnCategoryList){
zbnCategoryMap.put(zbnCategoryInList.getZbnCategoryName(), zbnCategoryInList);
}
}
}
Before the page is rendered, a Controller, calls loadZbnCategoryMap() and fills the map with the String and the object.
There are no nested forms, no ui component has a rendered=false attribute and I included the "h:head" tag instead of "head".
If I use the code above and click the commandButton, the doSave() method IS NOT called. If I remove the h:selectOneMenu, everything works fine.
I don´t know how I can solve this problem. Can someone help please?
I somehow "solved" the problem. It seems, that h:selectOneMenu has problems with saving objects to a bean.
Found a workaround that I save a String to the bean and just before persisting the Object, I use that String to load the entity from the database.
I created a tagfile for a confirm dialog with a command button:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:aym="http://aym.com/facelets"
xmlns:rich="http://richfaces.org/rich"
>
<h:body>
<ui:composition>
<p:growl id="messages" />
<h:panelGrid columns="1" cellpadding="5">
<p:commandButton value="#{label}" onclick="#{pupupId}.show()" type="button" ajax="false"/>
</h:panelGrid>
<p:confirmDialog message="#{message}"
showEffect="bounce" hideEffect="explode"
header="İşlem Onay" severity="alert" widgetVar="#{pupupId}">
<p:commandButton value="Evet" update="messages" oncomplete="#{pupupId}.hide()" ajax="false"
action="#{actionMethod}" />
<p:commandButton value="Hayır" onclick="#{pupupId}.hide()" type="button" />
</p:confirmDialog>
</ui:composition>
</h:body>
</html>
Here's how I'm using it:
<aym:onayButon id="onay2" label="#{lbl.kaydet}"
actionMethod="#{userMB.addUser}" pupupId="onaylaPopup"
message="#{msg.onay_sonuc}" />
I am passing the action method that I am going to call when I click the button. However, when I do that, then I am getting a PropertyNotFoundException:
WARNING: #{actionMethod}: javax.el.PropertyNotFoundException: /WEB-INF/tags/com/components/onayButton.xhtml #29,33 action="#{actionMethod}": /pages/index.xhtml #33,48 actionMethod="#{userMB.addUser}": Property 'addUser' not found on type com.otv.managed.bean.UserManagedBean
javax.faces.FacesException: #{actionMethod}: javax.el.PropertyNotFoundException: /WEB-INF/tags/com/components/onayButton.xhtml #29,33 action="#{actionMethod}": /pages/index.xhtml #33,48 actionMethod="#{userMB.addUser}": Property 'addUser' not found on type com.otv.managed.bean.UserManagedBean
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:118)
It works fine when I hardcode the action method in the tagfile like so:
<p:commandButton ... action="#{userMB.addUser}" />
How is this caused and how can I solve it?
Try as a workaround to give action bean and action method as two separate parameters:
Template
<p:commandButton value="Evet"
update="messages" oncomplete="#{pupupId}.hide()" ajax="false"
action="#{actionBean[actionMethod]}" />
call
<aym:onayButon id="onay2" label="#{lbl.kaydet}"
actionBean="#{userMB}" actionMethod="addUser" pupupId="onaylaPopup"
message="#{msg.onay_sonuc}" />
On the call, the bean needs to be in curly brackets, the method name is only given as string. See also Solution on a similar topic .
Maybe it helps...
Am trying to create a composite component that will display the values as overlaypanel. But it returns the below error;
Cannot find component 'j_idt58:reviewDataTable:0:overrideCol' in view
overrideVersionDetails.xhtml:(composite component)
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:cc="http://java.sun.com/jsf/composite"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:fn="http://java.sun.com/jsp/jstl/functions"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<cc:interface>
<cc:attribute name="forId" type="java.lang.String" required="true" />
<cc:attribute name="forValue" type="java.lang.Object" />
</cc:interface>
<cc:implementation>
<p:overlayPanel for="#{cc.attrs.forId}" my="left bottom">
#{cc.attrs.forValue}
</p:overlayPanel>
</cc:implementation>
</ui:composition>
Its used in another page:
<h:form>
....
...
<p:dataTable .....>
....
<p:column sortBy="#{dto.isSameCycleOverride}" width="100">
<f:facet name="header">
Override
</f:facet>
<h:commandLink id="overrideCol" binding="#{overrideCol}"
value="#{(dto.isSameCycleOverride) ? 'Yes' : 'No'}" />
<comp:overrideVersionDetails forId="#{overrideCol.clientId}"
forValue="#{dto.message}" />
</p:column>
....
</p:dataTable>
</h:form>
Any help is really appreciated.
I don't work with Primefaces, but with RichFaces I would use :
<comp:overrideVersionDetails forId="#{rich:clientId('overrideCol')}"
forValue="#{dto.message}" />
to do what you want.
With a little Help from SO :
Rich Faces rich:clientId in Primefaces?
it seems you can do this :
...
<h:commandLink id="overrideCol" value="#{(dto.isSameCycleOverride) ? 'Yes' : 'No'}" />
<comp:overrideVersionDetails forId="#{p:component('overrideCol')}"
forValue="#{dto.message}" />
...
Now to see if this works better than the use of binding in a dataTable...
I am trying to submit a form, when I am keeping managed bean scope as view or request the action method is not getting invoked and it is showing me blank page. Where as when I am keeping the managed bean's scope as "session" action method is getting invoked and can see the desired result.
I am using jsf 2.1, primefaces 3.5, EL 2.2, tomcat 7
Below is my xhtml code:
<ui:composition
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:c="http://java.sun.com/jsp/jstl/core"
template="globalTemplate.xhtml">
<h:messages />
<ui:define name="title">UserForm</ui:define>
<ui:define name="content">
<h:form id="userForm">
<ui:repeat value="#{loginBean.userMap.keySet().toArray()}" var="entry">
<h:inputText id="usrId#{entry.key}" value="#{loginBean.userMap.get(entry)}" />
<ui:repeat value="#{loginBean.userMap.get(entry)}" var="item" varStatus="loop">
<h:outputText id="msgDesc" value="#{item.userDesc}" />
<br/>
</ui:repeat>
<p:inputTextarea rows="6" cols="33" id="replyId#{entry.key}" value="#{loginBean.userInput}"
onkeypress="if (event.keyCode == 13) {submitUsr(); return false; }"/>
<p:commandButton id="submitInput#{entry.key}" value="Click" action="#{loginBean.submitUser}" />
</ui:repeat>
</h:form>
</ui:define>
I am not getting what is not allowing me to call the action method when I am submitting the page keeping managed bean's scope as view/request.
Thanks for your help in advance.
This is the Facelet:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns ="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<title>Title</title>
</h:head>
<h:body>
<h:form>
<h:commandButton value ="Converter" action ="#{conversorMonetarioBean.converte}"/>
<h:inputText value ="#{conversorMonetarioBean.valor}"/>
<h:outputLabel value ="de" for ="de"/>
<h:selectOneMenu value ="#{conversorMonetarioBean.de}" id="de">
<f:selectItems
value ="#{conversorMonetarioBean.taxas.keySet()}"
var ="moeda"
itemValue ="#{moeda}"
itemLabel ="#{moeda}" />
</h:selectOneMenu>
<h:outputLabel value ="para" for ="para"/>
<h:selectOneMenu value ="#{conversorMonetarioBean.para}" id="para">
<f:selectItems
value ="#{conversorMonetarioBean.taxas.keySet()}"
var ="moeda"
itemValue ="#{moeda}"
itemLabel ="#{moeda}" />
</h:selectOneMenu>
</h:form>
<h:outputFormat value ="{0} em {1} equivale a {2} em {3}" rendered ="#{conversorMonetarioBean.resultado != null}">
<f:param value ="#{conversorMonetarioBean.valor}"/>
<f:param value ="#{conversorMonetarioBean.de}"/>
<f:param value ="#{conversorMonetarioBean.resultado}"/>
<f:param value ="#{conversorMonetarioBean.para}"/>
</h:outputFormat>
</h:body>
</html>
It's saying that f:selectItems is an unknown tag.
What could be wrong ? I'm using JSF2, GlassFish 3.1.2, Eclipse. I tried to ctrl+space and only have h:something tags.
You forgot to import f namespace in your html declaration, xmlns:f="http://java.sun.com/jsf/core", so that the top section will be like:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
Also, your IDE is possibly showing you a hint that f namespace is missing, so following its instructions to do the import will solve your problem.