p:submenu is not expanded - jsf-2

I am trying but figure out how to use p:panelMenu
for some reason I am unable to make a submenu item expanded like the showcase example http://www.primefaces.org/showcase/ui/panelMenu.jsf
This is my jsf example:
<!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:p="http://primefaces.org/ui">
<h:head>
</h:head>
<h:body>
<h:form>
<p:panelMenu style="width:300px">
<p:submenu label="Non-Ajax Menuitem">
<p:menuitem value="Delete" ajax="false" icon="ui-icon-close" />
</p:submenu>
</p:panelMenu>
</h:form>
</h:body>
Any idea what I am missing here ?
Thanks

Related

Images won't display, navigation won't occur (learning? JSF 2)

Here is the JSF code trying to display and navigate.
<!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:f="http://java.sun.com/jsf/core">
<h:head>
<title>A Simple JavaServer Faces 2.0 View</title>
</h:head>
<h:body>
<h:form>
<h1>Images</h1>
<p><h:graphicImage library = "/images" name = "img_jsf.jpg"/>
<h:button value = "Proceed to page 2" outcomr = "gotopage2"/></p>
<p>Above the Main table</p>
<h:dataTable border="1" var="book"
value="#{catalogBean.bookList}">
<h:column>
<h:graphicImage url="#{book.imageLink}" height = "150" width= "150"/>
<h:link outcome="gotopage2">
<h:outputText value = "Proceed to page 2"/>
</h:link>
</h:column>
</h:dataTable>
</h:form>
Here is 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_2_0.xsd"
version="2.0"
>
<!-- Comments here, wow talk about hard to do this right.... -->
<navigation-rule>
<from-view-id>CatProdPage.xhtml</from-view-id>
<navigation-case>
<from-outcome>gotopage2</from-outcome>
<to-view-id>/storePage2.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
</faces-config>
Here is storePage2.xhtml
<!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:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<title>Store Page2</title>
</h:head>
<ui:composition template="./../template/secondaryTemplate.xhtml">
<ui:define name="header">
<ui:include src="/common/header.xhtml" />
</ui:define>
<ui:define name="leftMenu">
<ui:include src="/common/leftMenu.xhtml" />
</ui:define>
<ui:define name="CatProdPage">
<ui:include src="CatProdPage.xhtml" />
</ui:define>
<ui:define name="page2">
<ui:include src="page2.xhtml" />
</ui:define>
</ui:composition>
</html>
This is the result of a snippet from "view source" on the page
<h1>Images</h1>
<p><img src="RES_NOT_FOUND" /><input type="button" onclick="window.location.href='/jsfreg/faces/store/storePage.xhtml'; return false;" value="Proceed to page 2" /></p>
<p>Above the Main table</p><table border="1">
<tbody>
<tr>
<td><img src="/jsfreg/resources/images/img_coreJsf.jpg" height="150" width="150" /><span>: This link is disabled because a navigation case could not be matched.Proceed to page 2</span></td>
</tr>
The core problem is that I can't get images to display and can't get static navigation to work.
I have tried moving the images/*.jpg folder to every possible location I can think of beneath the application root, under WEB-INF, etc.
I am using Glassfish 4 and Maven.

why growl message not dispalying left side of screen using common layout

In my project there is a requirement that when we change language from Engish to Arabic all layout will be displayed in right to left position.
growl message working fine when i didn't use common layout but when i add this thing in common layout of my page then its still showing right side only..
source code:
<!DOCTYPE html>
<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:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Facelet Title</title>
<style type="text/css">
.ui-growl{
#{msg['msg']}:20px;
}
</style>
</h:head>
<body>
<ui:composition template="/home/template/common1/commonLayout.xhtml">
<ui:define name="content">
<h:form id="myform">
<p:growl id="msgs" sticky="true" autoUpdate="true" />
<f:event listener="#{localeControllerBean.islang}" type="preRenderView" />
<p:outputLabel for="sname" value="#{msg['welcome.jsf']}"
styleClass="label" />
<p:inputText id="sname" value="#{sponsorBean.sponsor_name}"
required="true" requiredMessage="#{msg['welcome.jsf']}"
styleClass="input" />
<p:commandButton id="submit" value="Save" ajax="false"
action="#{sponsorBean.save}" style="margin-bottom:50px;"
update="msgs" />
</h:form>
</ui:define>
</ui:composition>
</body>
</html>
Anything outside <ui:composition> is ignored during building the view.
In your commonLayout.xhtml master template you should add a new <ui:insert> inside <h:head>:
<h:head>
...
<ui:insert name="head" />
</h:head>
Then define it inside the <ui:composition> of your template client:
<ui:composition template="...">
<ui:define name="head">
<style>.ui-growl{ #{msg['msg']}: 20px; }</style>
</ui:define>
<ui:define name="content">
...
</ui:define>
</ui:composition>
(by the way #{msg['msg']} is absolutely not self-documenting; I'd myself also rather have used <html dir="#{direction}"> so that you can just use e.g. html[dir='rtl'] .ui.growl selector)
See also:
How to include another XHTML in XHTML using JSF 2.0 Facelets?

JSF2.0 Value is not valid on Submitting form

I am running JSF2.0 with Java 6 code on JBOSS 7.1.0.Final. Here is the code for my page:
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:s="http://jboss.org/schema/seam/taglib"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:rich="http://richfaces.org/rich"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:a4j="http://richfaces.org/a4j"
template="layout/template.xhtml">
<ui:define name="body">
<h:form id="quizform">
<rich:panel>
<f:facet name="header">Quiz Details</f:facet>
<a4j:repeat value="#{quizHome.mcqs}" var="_mcq" rowKeyVar="idx">
<s:decorate template="layout/display.xhtml">
<h:outputText value="#{idx+1}.#{_mcq.questionText}"/>
<h:selectOneRadio id="optionId-#{idx}" immediate="true" value="#{answerBean.optionId}" valueChangeListener="#{answerBean.selectAnswerLsnr}">
<s:selectItems value="#{_mcq.mcqOptions}" var="opt" label="#{opt.optionText}" itemValue="#{opt.id}" />
</h:selectOneRadio>
</s:decorate>
</a4j:repeat>
<div style="clear:both"/>
</rich:panel>
<div class="actionButtons">
<h:commandButton value="Submit Response" action="#{answerBean.findUserAnswer}" />
<h:commandButton value="Reset" type="reset" />
<s:button view="/StartQuiz.xhtml" id="startquiz" value="Restart Quiz"/>
</div>
</h:form>
</ui:define>
</ui:composition>
The page renders with correct values from the database. But, on submitting the form, I get the following message in the browser:
value is not valid.
What am I doing wrong? Thanks for your suggestions.

jsf2 template and adding style sheet

Trying to use the JSF2 templates feature.The base.xhtml page looks like below
<?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"
>
<h:head>
<h:outputStylesheet name="test.css" library="style" target="head"/>
</h:head>
<h:body>
<div id="page">
<div id="header">
<ui:insert name="header" >
<ui:include src="/layout/header.xhtml" />
</ui:insert>
</div>
<div id="content">
<ui:insert name="content" >
???
</ui:insert>
</div>
<div id="footer">
<ui:insert name="footer" >
<ui:include src="/layout/footer.xhtml" />
</ui:insert>
</div>
</div>
</h:body>
</html>
Trying to inherit this template into my page (testpage.xhtml)
<?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"
>
<h:body>
<ui:composition template="/layout/base.xhtml">
<ui:define name="content">
Default Page content!!!!
<h:outputText value="Foo bar" style="green"/>
</ui:define>
</ui:composition>
</h:body>
</html>
The test.css file is available under the folder webcontent/resources/style and the content of the css file is as follows
.green{
color:#0000FF;
}
Now the problem is when I try to run the testpage the stylesheet is adding into the page (with view source able to identify) but it is not reflecting in the UI.
Is anything wrong in the above code? Any help on this appreciated.
You should use styleClass attribute (equivalent to the class attribute of plain HTML)
Replace
<h:outputText value="Foo bar" style="green"/>
With
<h:outputText value="Foo bar" styleClass="green"/>

JSF2 built in ajax support error : f:ajax not found

Tried Mojarra - 2.0.8, 2.1.6 , MyFaces 2.0.11,2.1.5
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="w3.org/1999/xhtml" xmlns:f="java.sun.com/jsf/core" xmlns:h="java.sun.com/jsf/html" xmlns:ui="java.sun.com/jsf/facelets">
<body>
<h:form>
<h:inputText id="name" value="#{helloBean.name}"></h:inputText>
<h:commandButton value="Welcome Me">
<f:ajax execute="name" render="output" />
</h:commandButton>
<h2><h:outputText id="output" value="#{helloBean.sayWelcome}"/></h2>
</h:form>
</body>
</html>
The XML namespaces are invalid. You've removed the http:// prefix from them all. This is not right.
Here's a rewrite:
<!DOCTYPE html>
<html lang="en"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<title>Page title</title>
</h:head>
<h:body>
<h:form>
<h:inputText id="name" value="#{helloBean.name}"></h:inputText>
<h:commandButton value="Welcome Me">
<f:ajax execute="name" render="output" />
</h:commandButton>
<h2><h:outputText id="output" value="#{helloBean.sayWelcome}"/></h2>
</h:form>
</h:body>
</html>
Note that you also forgot the <h:head> component. This generates a HTML <head> element which allows JSF to auto-include the necessary JS and CSS files. In case of <f:ajax>, the JSF-supplied jsf.js file needs to be (auto)included, otherwise you will face a JS error after the page is been loaded.

Resources