Unable to auto-convert enum in JSF - jsf

According to this answer: https://stackoverflow.com/a/8229982/988145 , JSF should auto-convert enums. For some reason, it doesn't. I'm getting the following error:
"Type of FrequencyConversion Error setting value 'DAY_OF_WEEK' for 'null Converter'."
My enum:
public enum FrequencyType implements Serializable
{
DAY_NUMBER, DAY_OF_WEEK
}
Select markup:
<h:selectOneMenu onchange="toggleFrequencyTypes(this);"
value="#{cellContentsBean.pillSheetProfile.frequency}"
class="form-control" id="frequencyTypeDd">
<f:selectItems value="#{cellContentsBean.frequencyTypes}" />
</h:selectOneMenu>
Frequency types getter in the bean:
public FrequencyType[] getFrequencyTypes() {
return FrequencyType.values();
}
Setters:
private FrequencyType frequencyType;
/**
* #return the frequencyType
*/
public FrequencyType getFrequencyType()
{
return frequencyType;
}
/**
* #param frequencyType the frequencyType to set
*/
public void setFrequencyType(FrequencyType frequencyType)
{
this.frequencyType = frequencyType;
}
I've even added a converter to my faces config as another thread suggests, but it did nothing:
<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="2.2"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_2.xsd">
<application>
<el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
<converter>
<converter-for-class>java.lang.Enum</converter-for-class>
<converter-class>javax.faces.convert.EnumConverter</converter-class>
</converter>
</application>
</faces-config>

While this likely won't solve your problem, I have to note that your faces-config.xml is kind of broken:
The JSF Namespaces you declared do not exist this way.
Wrong nesting of elements: converter element is not a child of application element.
Better try this:
<?xml version='1.0' encoding='UTF-8'?>
<faces-config xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"
version="2.2">
<application>
<el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
</application>
<converter>
<converter-for-class>java.lang.Enum</converter-for-class>
<converter-class>javax.faces.convert.EnumConverter</converter-class>
</converter>
</faces-config>

Related

Unable to use beans with jsf 2.3 in servlet container [duplicate]

This question already has answers here:
How to install and use CDI on Tomcat?
(2 answers)
Closed 4 years ago.
I started to test JSF 2.3 a short time ago. But I can't get one of the most important features to work. The use of ManagedBeans. I tried a lot, using different servlet containers (Tomcat 8&9, Jetty 9.2).But nothing helped. Hope somebody can see my failure in the resources. It's frustrating. I debugged but the bean is never reached. The primefaces component works fine(the primefaces lib is not the reason). But I never get bean data. PS. I'm using myfaces but with mojarra I've got the same problem.
my bean:
import javax.enterprise.context.RequestScoped;
import javax.faces.annotation.FacesConfig;
import javax.faces.context.FacesContext;
import javax.inject.Named;
import java.io.Serializable;
#Named(value = "sampleBean")
#RequestScoped
#FacesConfig(version = FacesConfig.Version.JSF_2_3)
public class SampleBean implements Serializable {
private String specTitle;
private String specVersion;
private String implTitle;
private String implVersion;
public SampleBean() {
Package facesPackage = FacesContext.class.getPackage();
specVersion = facesPackage.getSpecificationVersion();
specTitle = facesPackage.getSpecificationTitle();
implTitle = facesPackage.getImplementationTitle();
implVersion = facesPackage.getImplementationVersion();
}
public String info() {
return "hello from sampleBean!";
}
public String getSpecTitle() {
return specTitle;
}
public String getSpecVersion() {
return specVersion;
}
public String getImplTitle() {
return implTitle;
}
public String getImplVersion() {
return implVersion;
}
}
my configuration bean:
import javax.faces.annotation.FacesConfig;
#FacesConfig(version = FacesConfig.Version.JSF_2_3)
public class ConfigurationBean {
}
my facelet:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Hello JSF 2.3</title>
<style>
.col-1 { text-align: right; }
.col-2 { font-weight: bold; }
</style>
</h:head>
<h:body>
<div style="border-style: dashed" class="ui-g">
<p:calendar mode="inline"/>
</div>
<div style="border-style: double">
<h3>Hello from JSF 2.3!</h3>
<h:panelGrid columns="2" columnClasses="col-1, col-2">
<h:outputText value="Specification:"/>
<h:outputText value="#{sampleBean.specTitle}"/>
<h:outputText value="Specification version:"/>
<h:outputText value="#{sampleBean.specVersion}"/>
<h:outputText value="Implementation:"/>
<h:outputText value="#{sampleBean.implTitle}"/>
<h:outputText value="Implementation version:"/>
<h:outputText value="#{sampleBean.implVersion}"/>
</h:panelGrid>
<p>CDI injection support: <b>#{sampleBean.facesContextValue}</b></p>
<p>Running on: <b>#{application.serverInfo}</b></p>
</div>
my web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1"><!-- Use web-app_4_0.xsd, version=4.0 after update to Java EE 8 -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<context-param>
<param-name>javax.faces.ENABLE_CDI_RESOLVER_CHAIN</param-name>
<param-value>truet</param-value>
</context-param>
<context-param>
<param-name>javax.faces.ENABLE_WEBSOCKET_ENDPOINT</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>javax.faces.validator.ENABLE_VALIDATE_WHOLE_BEAN</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>javax.faces.FACELETS_REFRESH_PERIOD</param-name>
<param-value>0</param-value> <!-- No Cache -->
</context-param>
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
</web-app>
my build.gradle:
plugins {
id 'war'
id 'org.gretty' version '2.2.0'
}
group 'de.danri'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
jcenter()
}
gretty{
//servletContainer="tomcat8"
//servletContainer="tomcat9"
}
dependencies {
// https://mvnrepository.com/artifact/org.apache.myfaces.core/myfaces-impl
compile group: 'org.apache.myfaces.core', name: 'myfaces-impl', version: '2.3.1'
// https://mvnrepository.com/artifact/org.apache.myfaces.core/myfaces-api
compile group: 'org.apache.myfaces.core', name: 'myfaces-api', version: '2.3.1'
// https://mvnrepository.com/artifact/org.primefaces/primefaces
compile group: 'org.primefaces', name: 'primefaces', version: '6.2'
// https://mvnrepository.com/artifact/javax.servlet.jsp/jsp-api
compile group: 'javax.servlet.jsp', name: 'jsp-api', version: '2.2.1-b03'
// https://mvnrepository.com/artifact/javax.enterprise/cdi-api
compile group: 'javax.enterprise', name: 'cdi-api', version: '2.0.SP1'
// https://mvnrepository.com/artifact/javax.websocket/javax.websocket-api
compile group: 'javax.websocket', name: 'javax.websocket-api', version: '1.1'
// https://mvnrepository.com/artifact/javax.servlet/jstl
compile group: 'javax.servlet', name: 'jstl', version: '1.2'
// https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api
compile group: 'javax.servlet', name: 'javax.servlet-api', version: '4.0.1'
// https://mvnrepository.com/artifact/javax.validation/validation-api
compile group: 'javax.validation', name: 'validation-api', version: '2.0.1.Final'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
beans.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
version="1.1" bean-discovery-mode="all">
</beans>
faces-config.xml:
<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="2.3"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_3.xsd">
</faces-config>
Thank your maress. Good adress! Solution:
I added the /META-INF/context.xml
<Context>
<Resource name="BeanManager"
auth="Container"
type="javax.enterprise.inject.spi.BeanManager"
factory="org.jboss.weld.resources.ManagerObjectFactory" />
</Context>
I added weld-servlet shaded to my dependencies:
...
compile group: 'org.jboss.weld.servlet', name: 'weld-servlet-shaded', version: '3.0.5.Final'
...
Finally I used a local tomcat to run the artifact and not the gradle 'gretty' plugin.
It seems the plugin has problems with cdi.

jsf2-javax.el.PropertyNotFoundException: /index.xhtml except

I am new to JSF.
I have done everything right as far as I know but still getting this exception
javax.el.PropertyNotFoundException: /index.xhtml #22,55 value="#{navigator.pages}": Property 'pages' not found on type Navigator
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:111)
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182)
at javax.faces.component.UIOutput.getValue(UIOutput.java:174)
at javax.faces.component.UIInput.getValue(UIInput.java:291)
at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getValue(HtmlBasicInputRenderer.java:205)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getCurrentValue(HtmlBasicRenderer.java:355)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeEnd(HtmlBasicRenderer.java:164)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:919)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1863)
at javax.faces.render.Renderer.encodeChildren(Renderer.java:176)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:889)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1856)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:456)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:133)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Caused by: javax.el.PropertyNotFoundException: Property 'pages' not found on type Navigator
at javax.el.BeanELResolver$BeanProperties.get(BeanELResolver.java:266)
at javax.el.BeanELResolver$BeanProperties.access$300(BeanELResolver.java:243)
at javax.el.BeanELResolver.property(BeanELResolver.java:353)
at javax.el.BeanELResolver.getValue(BeanELResolver.java:97)
at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
at org.apache.el.parser.AstValue.getValue(AstValue.java:183)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184)
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
... 40 more
I have gone through lots of post regarding this exception and they all have mentioned about bean properties and their getters/setters which I have done correctly .
Here is my code:
1) Index.html
<!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://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<!-- When you make your own projects, copy and rename sample-file-with-form.xhtml
or sample-file-no-form.xhtml. Don't copy and rename THIS file, because
this file has too many extraneous things in it. -->
<h:head>
<title>JSF 2.2: Initial Learning Project</title>
<link href="./css/styles.css" rel="stylesheet" type="text/css"/>
</h:head>
<h:body>
<h1 class="title">JSF 2.2: Initial Learning Project</h1>
<div align="center">
<fieldset>
<legend>Selected Results Page</legend>
<h:form>
Please enter the page you want to see.
<br/>
<h:inputText id="pages" value="#{navigator.pages}" /><br />
<h:commandButton value="Go to Selected Page"
action="#{navigator.choosePage}"/>
</h:form>
</fieldset>
</div>
</h:body></html>
2) My bean class - Navigator.java
import javax.faces.bean.*;
#ManagedBean
public class Navigator {
private String pages;
public String getPages() {
return pages;
}
public void setPages(String pages) {
this.pages = pages;
}
public String choosePage() {
if(pages == "page1"){
return "page1";
} else if(pages == "page2"){
return "page2";
} else {
return "page3";
}
}
3) web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<context-param>
<description>State saving method: 'client' or 'server' (default). See JSF Specification section 2.5.2</description>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<!-- If you go to http://host/project/ (with no file name), it will
try index.jsf first, welcome.jsf next, and so forth.
-->
<welcome-file-list>
<welcome-file>index.jsf</welcome-file>
<welcome-file>welcome.jsf</welcome-file>
<welcome-file>index.html</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
4)faces-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<faces-config
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"
version="2.2">
<!-- Empty for now. There are many uses for faces-config.xml, but
the most common are navigation rules (instead of having
the return value of the "action" method be the base filename),
bean declarations (instead of using #ManagedBean), and
properties files (aka resource bundles).
If you are not using faces-config.xml, it is perfectly legal
to omit the file entirely. But, most people prefer to have
a blank one already in their project for later use.
From JSF 2 and PrimeFaces tutorial
at http://www.coreservlets.com/JSF-Tutorial/jsf2/ -->
</faces-config>
Please help me out on this.
try equals for String
public String choosePage()
{
if(pages.equals("page1")){
return "page1";
} else if(pages.equals("page2")){
return "page2";
} else {
return "page3";
}
}
Try with the below changes.
Change filename from index.html to index.xhtml and update the same file name as mentioned below.
<welcome-file>index.html</welcome-file>
Happy coding!

<rich:tree> Example reRender not working Richfaces 3.3.4 final

i'm using Richfaces 3.3.4 final with JSF 1.2 on a SAP NetWeaver AS 7.31.
Now im facing some Issues with dynamically showing selected Nodes from a rich:tree in a h:outputText. The selectedNodeListener is invoked correctly and the Name of the Node is saved in a String, but my h:outputText only refreshes on Page Refresh and not on Selection like in the Example from the Showcases(http://showcase-rf3.richfaces.org/richfaces/tree.jsf?tab=model&cid=26981).
Does anyone know if this is a common Issue with the above Setup or am I just missing something? As far as I know SAP NetWeaver isnt in the List of supported Servers but its JEE5 compliant. Could this be the Reason?
I simplified the Example from the Richfaces Showcases to reproduce the Problem in a small Environment. Here is some Code:
SimpleTreeBean.java
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.richfaces.component.html.HtmlTree;
import org.richfaces.event.NodeSelectedEvent;
import org.richfaces.model.TreeNode;
import org.richfaces.model.TreeNodeImpl;
public class SimpleTreeBean {
private TreeNode rootNode = null;
private List<String> selectedNodeChildren = new ArrayList<String>();
private String nodeTitle;
private void loadTree() {
rootNode = new TreeNodeImpl();
TreeNodeImpl rt = new TreeNodeImpl();
rt.setData("Root");
rootNode.addChild(1, rt);
for(int i = 1; i <= 5; i++){
TreeNodeImpl child = new TreeNodeImpl();
child.setData("Child "+i);
rt.addChild(i, child);
}
}
public void processSelection(NodeSelectedEvent event) {
HtmlTree tree = (HtmlTree) event.getComponent();
nodeTitle = (String) tree.getRowData();
selectedNodeChildren.clear();
TreeNode currentNode = tree.getModelTreeNode(tree.getRowKey());
if (currentNode.isLeaf()) {
selectedNodeChildren.add((String) currentNode.getData());
} else {
Iterator<Map.Entry<Object, TreeNode>> it = currentNode
.getChildren();
while (it != null && it.hasNext()) {
Map.Entry<Object, TreeNode> entry = it.next();
selectedNodeChildren.add(entry.getValue().getData().toString());
}
}
}
public TreeNode getTreeNode() {
if (rootNode == null) {
loadTree();
}
return rootNode;
}
public String getNodeTitle() {
return nodeTitle;
}
public void setNodeTitle(String nodeTitle) {
this.nodeTitle = nodeTitle;
}
}
test.jsp:
<%#taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%#taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%#taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
<%#taglib uri="http://richfaces.org/rich" prefix="rich"%>
<html>
<head>
<title>TestTree</title>
</head>
<body>
<f:view>
<h:form>
<h:panelGrid columns="2" width="100%" columnClasses="col1,col2">
<rich:tree style="width:300px" nodeSelectListener="#{simpleTreeBean.processSelection}"
reRender="selectedNode" ajaxSubmitSelection="true" switchType="client"
value="#{simpleTreeBean.treeNode}" var="item" ajaxKeys="#{null}">
</rich:tree>
<h:outputText escape="false" value="Selected Node: #{simpleTreeBean.nodeTitle}" id="selectedNode" />
</h:panelGrid>
</h:form>
</f:view>
</body>
</html>
Important Part of faces-config.xml:
<?xml version="1.0" encoding="UTF-8"?>
<faces-config
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"
version="1.2">
<managed-bean>
<managed-bean-name>simpleTreeBean</managed-bean-name>
<managed-bean-class>
com.realcore.web.beans.SimpleTreeBean
</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
</faces-config>
<</faces-config>/faces-config>
Additionally there are some Validators and Converters in my faces-config too. But I think this isnt important for this Problem.
And here is the web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>SstSapWEB</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>login.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<!-- Making the RichFaces skin spread to standard HTML controls -->
<context-param>
<param-name>org.richfaces.CONTROL_SKINNING</param-name>
<param-value>enable</param-value>
</context-param>
<!-- Defining and mapping the RichFaces filter -->
<filter>
<display-name>RichFaces Filter</display-name>
<filter-name>richfaces</filter-name>
<filter-class>org.ajax4jsf.Filter</filter-class>
</filter>
<filter-mapping>
<filter-name>richfaces</filter-name>
<servlet-name>Faces Servlet</servlet-name>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
</web-app>
This simple Example isnt working too.
I don't know how to fix or workaround this Issue. Any help is greatly appreciated.
Regards,
Daniel
just in fact somebody else has similar Problems: After working on other things in the mean time I now figured out how to solve this Issue.
It was rather easy and all work is done in the JSP:
Use Rich Tree Node inside the Rich Tree Tag
Use the ajaxSubmitSelection and reRender Attributes of the TreeNode
Wrap the Part of the Page, which should be rerendered in a <a4j:outputPanel/> and set its Attribute ajaxRendered to "true"
Ensure that the values of the id-Attribute of the <a4j:outputPanel/> and the reRender-attribute of the TreeNode are the same.
Hope this helps others with similar Problems,
Daniel

JSF rendered only when value is numeric

<h:inputText rendered="#{bean.myStringVariable [is numeric]}"
id="myID"
value="#{bean.myStringVariable}"/>
Is it possible to have an expression in the rendered element that says render only if the contents myStringVariable is a numeric? I've had a look through http://developers.sun.com/docs/jscreator/help/jsp-jsfel/jsf_expression_language_intro.html but nothing jumps out.
Rgds, Kevin.
Create a custom EL function so that you can use it as follows:
<h:inputText rendered="#{util:matches(bean.myStringVariable, '\\d+')}">
First create some utility class.
package com.example.
public final class Util {
private Util() {
//
}
public static boolean matches(String value, String regex) {
return value.matches(regex);
}
}
If you're using JSP, define it as follows in /WEB-INF/util.tld:
<?xml version="1.0" encoding="UTF-8" ?>
<taglib
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd"
version="2.1">
<display-name>Utility Functions</display-name>
<tlib-version>1.0</tlib-version>
<uri>http://example.com/util</uri>
<function>
<name>matches</name>
<function-class>com.example.Util</function-class>
<function-signature>boolean matches(java.lang.String, java.lang.String)</function-signature>
</function>
</taglib>
And declare it as follows:
<%#taglib uri="http://example.com/util" prefix="util" %>
Or if you're using Facelets, define it as follows in /META-INF/util.taglib.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!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://example.com/util</namespace>
<function>
<function-name>matches</function-name>
<function-class>com.example.Util</function-class>
<function-signature>boolean matches(java.lang.String, java.lang.String)</function-signature>
</function>
</facelet-taglib>
Add it to the web.xml as follows:
<context-param>
<param-name>facelets.LIBRARIES</param-name>
<param-value>/META-INF/util.taglib.xml</param-value>
</context-param>
(when you're on JSF 2.0, use javax.faces.FACELETS_LIBRARIES as name instead)
And declare it as follows:
<html xmlns:util="http://example.com/util">

Deploying simple Spring MVC Portlet to Liferay 5.2.3

I try to deploy a simple spring portlet in ext (I can't use Plugins SDK...) on Liferay 5.2.3
My portlet:
ext-impl/src:
package: com.ext.portlet.springmvc
HelloWorldController.java
package com.ext.portlet.springmvc;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
public class HelloWorldController implements Controller {
public ModelAndView handleRequest(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
String aMessage = "Hello World MVC!";
ModelAndView modelAndView = new ModelAndView("hello_world");
modelAndView.addObject("message", aMessage);
return modelAndView;
}
}
ext-lib:
jstr.jar
spring-webmvc.jar
spring-webmvc-portlet.jar
spring.jar
standard.jar
ext-web/docroot/html/portlet/ext/springmvc/hello_world.jsp
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<body>
<p>This is my message: ${message}</p>
</body>
</html>
ext-web/docroot/html/portlet/ext/springmvc/index.jsp
<html>
<body>
<p>Hi</p>
</body>
</html>
ext-web/docroot/WEB-INF/springmvc-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean name="/hello_world.html" class="com.ext.portlet.springmvc.HelloWorldController"/>
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="prefix" value="/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>
ext-web/docroot/WEB-INF/portlet-ext.xml
<portlet>
<portlet-name>springmvc</portlet-name>
<portlet-class>org.springframework.web.portlet.DispatcherPortlet</portlet-class>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>view</portlet-mode>
</supports>
<portlet-info>
<title>Simple JSP Portlet</title>
</portlet-info>
<security-role-ref>
<role-name>power-user</role-name>
</security-role-ref>
<security-role-ref>
<role-name>user</role-name>
</security-role-ref>
</portlet>
ext-web/docroot/WEB-INF/web.xml
<?xml version="1.0"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>
jsp/index.jsp
</welcome-file>
</welcome-file-list>
</web-app>
Are there some mistakes?
I get this error, when I try to deploy:
Website OC4J 10g (10.1.3) Default Web Site definiert ist. Error creating bean w
ith name 'com.liferay.portal.kernel.captcha.CaptchaUtil' defined in class path r
esource [META-INF/util-spring.xml]: Cannot create inner bean 'com.liferay.portal
.captcha.CaptchaImpl#1424b7b' of type [com.liferay.portal.captcha.CaptchaImpl] w
hile setting bean property 'captcha'; nested exception is org.springframework.be
ans.factory.BeanCreationException: Error creating bean with name 'com.liferay.po
rtal.captcha.CaptchaImpl#1424b7b' defined in class path resource [META-INF/util-
spring.xml]: Instantiation of bean failed; nested exception is org.springframewo
rk.beans.BeanInstantiationException: Could not instantiate bean class [com.lifer
ay.portal.captcha.CaptchaImpl]: Constructor threw exception; nested exception is
java.lang.NullPointerException
Hope anybody can help me...
You are using the wrong flavour of Spring mvc here. You are talking to the servlet API in your code, but you should be talking to the Portlet API. Luckily, spring has a specialized version of spring mvc, called spring portlet mvc.
To get a feel for it, read this: http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/portlet.html
Checkout this blog- How to setup Liferay+SpringMVC?
You will find how to setup a Liferay+SpringMVC portlet.

Resources