JSF components don't render when using JBoss6 runtime instead of Tomcat7 - jsf-2

I have a simple form page as shown below:
<f:view contentType="text/html">
<h:head>
<title>Login Page</title>
</h:head>
<body>
<h1>Java Learning Center</h1><hr id="horizontalLine"/>
<h2><a>Account Login</a></h2>
<h:outputText value="#{userBean.errorMessage}" style="color:red; text-size:20" />
<h:form>
<h:panelGrid>
<h:outputText value="Username" />
<h:inputText value="#{userBean.username}" id="username" required="true" />
<h:message for="username" style="color:red; text-size:18"/>
<h:outputText value="Password" />
<h:inputSecret value="#{userBean.password}" id="password" required="true"/>
<h:message for="password" style="color:red; text-size:18"/>
<h:commandButton value="Login" action="#{userBean.verifyUser}" />
</h:panelGrid>
</h:form>
</body>
</f:view>
</html>
When I am deploying this to Tomcat7 then complete page is displayed. However, when I am deploying the same on JBoss6.1 Runtime, The form elements corresponding to JSF's HTML tag library are not displayed. I'm only seeing content from plain HTML elements like <h1> and <h2>.
Where am I committing the mistake?

Previously, I was having problem with my JSF2.0 page not being rendered completely.
However, I came to figure out my stupidity in my config-faces.xml where i have used:
<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">
...
</faces-config>
instead of :
<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">
...
</faces-config>
The kind of problem which arises when using Copy-Paste mechanism without care.

Related

Spring Security custom form always fails

I am trying to give my website (created using JSF 2) a custom login from using Spring Security. When I use the default login form, the website works fine. However, when I try to use my own custom login form, I am always directed to my authentication-failure-url, even when I type the correct username/password. Does anyone know why this is or how I can fix it? My code is below.
security-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans
xmlns:sec="http://www.springframework.org/schema/security"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.1.xsd">
<sec:http auto-config="true" use-expressions="true">
<sec:intercept-url pattern="/login.jsf" access="isAnonymous()" />
<sec:intercept-url pattern="/pages/secure/**" access="hasRole('ROLE_USER')" />
<sec:intercept-url pattern="/pages/home/**" access="hasRole('ROLE_USER')" />
<sec:intercept-url pattern="/pages/unsecure/**" access="permitAll"/>
<sec:form-login login-page="/login.jsf" default-target-url="/pages/home/home.jsf"
authentication-failure-url="/fail.jsf"/>
</sec:http>
<sec:authentication-manager alias="authenticationManager">
<sec:authentication-provider>
<sec:user-service>
<sec:user authorities="ROLE_USER" name="admin" password="admin" />
</sec:user-service>
</sec:authentication-provider>
</sec:authentication-manager>
</beans:beans>
login.xhtml
<!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:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />
<title>Login</title>
<h:outputStylesheet name="css/styles.css" />
<h:outputScript name="jquery/jquery-plugins.js" library="primefaces" />
</h:head>
<h:body>
<div class="login">
<form method="POST" action="j_spring_security_check">
<h:inputText name="j_username" id="username"></h:inputText>
<p:watermark for="username" value="Username" />
<br />
<h:inputSecret name="j_password" id="password">
</h:inputSecret>
<p:watermark for="password" value="Password" />
<br />
<h:commandButton name="submit" type="submit" value="Submit"></h:commandButton>
</form>
</div>
</h:body>
</html>
Have you looked at the generated HTML output? Rightclick page in browser, do View Source to see it.
The name attribute of
<h:inputText name="j_username" id="username"></h:inputText>
<h:inputSecret name="j_password" id="password"></h:inputSecret>
isn't been generated at all! Instead, the client ID represents the element's name.
Fix it accordingly:
<h:inputText id="j_username" />
<p:watermark for="j_username" value="Username" />
<h:inputSecret id="j_password" />
<p:watermark for="j_password" value="Password" />
You could of course also just use plain vanilla HTML:
<input type="text" name="j_username" placeholder="Username" />
<input type="password" name="j_password" placeholder="Password" />
Try setting the following as action of the form.
action="#{request.contextPath}/j_spring_security_check"

Creating a wizard using ui:include, rich:popupPanel and navigation-rules

I am trying to build a wizard using ui:include in a RichFaces 4 popupPanel and navigation-rules in the faces-config.xml, but on completing the actions in the backing bean, the page does not navigate to the target page. I have checked to ensure that the bean executes as expected and that it provides the expected outcome.
The JSF page and the included page are listed below:
<rich:popupPanel modal="true" id="addSvcAcctPanel" autosized="true">
<rich:messages id="addSvcAcctPanelMessages" globalOnly="false"
styleClass="message" />
<a:outputPanel id="includeAddSvcAcct">
<ui:include src="/layout/addSvcAccPg2.xhtml" />
</a:outputPanel>
<h:form id="closeSvcAcctForm">
<div class="buttons">
<a:commandButton styleClass="save" id="closeAddSvcBtn"
value="close"
onclick="#{rich:component('addSvcAcctPanel')}.hide()"
render="hasAgentsAccItm,svcAccAccordItm,svcAcctsTab,svcAccInfo,agentPanel,ServiceAccts,noticesAccordion">
<rich:tooltip direction="topRight" mode="client" showDelay="300"
styleClass="tooltip" layout="block">
<span style="white-space: wrap">Click on the 'Close'
button to close this panel and return to the main screen. If you
have any unsaved information on this page, it will be lost when
you click close.</span>
</rich:tooltip>
</a:commandButton>
</div>
</h:form>
</rich:popupPanel>
The inserted JSF code for the two panels is as follows:
Pg 1.....
<?xml version="1.0" encoding="UTF-8" ?>
<h:form xmlns="http://www.w3.org/1999/xhtml"
xmlns:s="http://jboss.com/products/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:richext="http://java.sun.com/jsf/composite/richext"
xmlns:a="http://richfaces.org/a4j">
<rich:panel id="addSvcAcctPanelContent" headerClass="head2" style="height:100%;">
<f:facet name="header">
<h:outputText styleClass="med_black_type_bold_facet"
value="Add a Service Account" />
</f:facet>
<h:panelGrid columns="3">
<h:outputText styleClass="med_black_type_bold"
value="Department" id="companyLabel" />
<rich:select styleClass="med_black_type" id="companySelect"
required="true" value="#{main.selected_company}" render="acctWarning, accountLabel1" valueChangeListener="#{main.determineProperAccountName}">
<f:selectItem
itemLabel="Please select an Organisation"
itemValue="" />
<f:selectItems value="#{country_companies}" />
<a:ajax event="selectitem" render="acctWarning, accountLabel1, acctNumberExplain, acctIdHeader, acctIDHelp" execute="#this"/>
</rich:select>
<rich:message for="companySelect" style=" width : 330px;" />
<h:outputText styleClass="med_black_type_bold"
value="Account 'Nickname'" id="nicknameLabel" />
<h:inputText styleClass="med_black_type" id="nickname"
value="#{main.alias}" onfocus="#{rich:component('nickNameHelpPanel')}.show()"
onblur="#{rich:component('nickNameHelpPanel')}.hide()">
<rich:validator />
<!-- <f:ajax event="focus" execute="#this" onevent="#{rich:component('nickNameHelpPanel')}.show()"/>
<f:ajax event="blur" execute="#this" onevent="#{rich:component('nickNameHelpPanel')}.hide()"/> -->
</h:inputText>
<rich:message for="nickname" style=" width : 330px;" />
<richext:spacer width="30" />
<h:outputText id="acctWarning" styleClass="med_blue_type_bold"
value="Enter the #{main.accountProperName} below - numbers and letters only! No dots or dashes." />
<richext:spacer width="30" />
<h:outputText styleClass="med_black_type_bold"
value="#{main.accountProperName}" id="accountLabel1" />
<h:inputText styleClass="med_black_type" id="account"
value="#{main.account_id}" onfocus="#{rich:component('acctIDHelpPanel')}.show()"
onblur="#{rich:component('acctIDHelpPanel')}.hide()">
<rich:validator />
<!-- <f:ajax event="focus" execute="#this" onevent="#{rich:component('acctIDHelpPanel')}.show()"/>
<f:ajax event="blur" execute="#this" onevent="#{rich:component('acctIDHelpPanel')}.hide()"/> -->
</h:inputText>
<rich:message for="account" style=" width : 330px;" />
</h:panelGrid>
<div class="buttons">
<a:commandButton styleClass="save" id="addServiceCompany"
value="save" action="#{main.addAccount}" render="includeAddSvcAcct, includeAddSvcAcct1"/>
</div>
</rich:panel>
</h:form>
Pg 2.....
<?xml version="1.0" encoding="UTF-8" ?>
<h:form xmlns="http://www.w3.org/1999/xhtml"
xmlns:s="http://jboss.com/products/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:richext="http://java.sun.com/jsf/composite/richext"
xmlns:a="http://richfaces.org/a4j">
<rich:panel>
<h:outputText value="The service account has been successfully added." styleClass="med_black_type"/>
</rich:panel>
The relevant excerpt from the faces-config is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<faces-config version="2.1"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xi="http://www.w3.org/2001/XInclude"
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_1.xsd">
<navigation-rule>
<from-view-id>/layout/addSvcAccPg2.seam</from-view-id>
<navigation-case>
<from-action>#{main.outcome}</from-action>
<from-outcome>success</from-outcome>
<to-view-id>/layout/addSvcAccPg3.seam</to-view-id>
</navigation-case>
</navigation-rule>
<application>
<locale-config>
<default-locale>en</default-locale>
<supported-locale>bg</supported-locale>
<supported-locale>de</supported-locale>
<supported-locale>en</supported-locale>
<supported-locale>fr</supported-locale>
<supported-locale>tr</supported-locale>
</locale-config>
</application>
</faces-config>
The method from the backing bean is as follows:
public String addAccount() {
String retVal = "failed";
try {
getSAFctx.addService(getIntUserId(), 1, selected_company,
account_id, alias);
retVal = "success";
} catch (Exception e) {
System.out.println(e.getMessage());
} finally {
return retVal;
}
}
I have tried to this using pages.xml, *.pages.xml and rich:togglePanel (which for some reason, does not permit commandButtons to engage backing beans). Does anyone have any suggestions that can help? Does anyone know how to make this wizard work?
Thanks in advance.
Dave.
From the above code it is clear that once the page /layout/addSvcAccPg2.seam is included inside the rich:popupPanel , then it will lead to situation having same ID's for two different components's in a single page .
You have used ID="addSvcAcctPanel" for rich:popupPanel and rich:panel. This is a common issue with richfaces and creates page navigation problems .
Just make them different and try once again .

Trouble using a richfaces tabPanel with dynamic tabs

I saw on richfaces showcase that the best way to use rich:tabPanel with dynamic tabs is with a4j:repeat, but this doesn't work in my application.
This is my code:
<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>
<title>Java EE 6 Starter Application</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</h:head>
<h:body>
<h:form>
<div id="topArea">
<ui:insert name="topArea"/>
</div>
<div id="mainArea">
<ui:insert name="mainArea"/>
</div>
<div id="footerArea">
<ui:insert name="footerArea"/>
</div>
</h:form>
</h:body>
</html>
In topArea, I have this menu:
<rich:panelMenu>
<rich:panelMenuItem label="Clienti" name="Clienti" action="#{tabsBean.addTab()}" render="tabsPanel" />
</rich:panelMenu>
in mainArea, I have this tabPanel:
<rich:tabPanel id="tabsPanel" switchType="client" activeItem="#{tabsBean.activeTab}" >
<a4j:repeat value="#{tabsBean.tabs}" var="tab">
<rich:tab name="#{tab.name}">
<f:facet name="header">#{tab.name}</f:facet>
<h:form>
<h:outputText value="Enter Name:" />
<h:inputText id="input" />
<h:outputText value="Enter you interests:" />
<h:inputTextarea cols="17" rows="3" />
<h:outputText value="Choose your favourite color" />
<h:selectOneMenu>
<f:selectItem itemLabel="Red" itemValue="0" />
<f:selectItem itemLabel="Black" itemValue="1" />
<f:selectItem itemLabel="Green" itemValue="2" />
<f:selectItem itemLabel="White" itemValue="3" />
</h:selectOneMenu>
</h:form>
</rich:tab>
</a4j:repeat>
</rich:tabPanel>
My troubles are:
The tabs are not created
Why does the showcase use a nested form? Won't nested forms cause trouble?
Thanks
Dynamic tabs with a4j:repeat are supported since 4.3.0.Final only, refer here for more details:
http://www.bleathem.ca/blog/2013/01/dynamic-panels-with-a4jrepeat.html
For earlier versions c:forEach items="#{tabsBean.tabs}" var="tab" can be used.

Facelet Custom Tag works only for one entity

I defined a custom tag like:
<?xml version="1.0" encoding="UTF-8"?>
<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"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich"
xmlns:composite="http://java.sun.com/jsf/composite">
<!-- INTERFACE -->
<composite:interface>
<composite:attribute name="terminal" />
<composite:attribute name="prefix" />
</composite:interface>
<!-- IMPLEMENTATION -->
<composite:implementation>
<h:panelGrid columns="3" columnClasses="titleCell">
<h:outputLabel for="#{prefix}nodeId" value="Node Id" />
<h:selectOneMenu id="#{prefix}nodeId"
value="#{cc.attrs.terminal.nodeId}"
converter="javax.faces.Integer">
<f:selectItems
value="#{terminalController.availableNodeIds}" />
<rich:validator />
</h:selectOneMenu>
<rich:message for="#{prefix}nodeId" id="cnodeIdMsg" />
<h:outputLabel for="#{prefix}maxcon" value="Max Connections" />
<h:inputText id="#{prefix}maxcon"
value="#{cc.attrs.terminal.maxConnections}">
<rich:validator />
</h:inputText>
<rich:message for="#{prefix}maxcon" />
</h:panelGrid>
</composite:implementation>
</html>
When I use it within a rich:popupPanel
<my:terminalForm prefix="c" terminal="#{newTerminal}"/>
everything works fine.
At another place in the same file (also rich:popupPanel)
<my:terminalForm prefix="e" terminal="#{terminalController.editTerminal}"/>
all values in my form don't get the initialized. I suspected the expression #terminalController.editTerminal} to not get expanded correctly. But when I write the tags from the custom tag explicit
<h:inputText id="#{prefix}maxcon"
value="#{terminalController.editTerminal.maxConnections}">
<rich:validator />
</h:inputText>
everything would work also, but using the custom tag for only one expansion would be pointless.
What could be wrong?
Does anyone more experienced have an idea how I could debug this issue?
The cc.attrs is missing in front of prefix ?!

trying to display a map with gmap object in JSF

I'm working with JSF2 and I want to display a map with the object gmap. As I saw, gmap object doesn't exist anymore with richfaces 4.x, so I tried to import the gmap4jsf.jar to render my map...
To have an exemple I took a part of my code from the Richfaces demo here : Richfaces live demo
The map is displayed well, but if I want to control it (change the type, zoom,...) with the jsf elements from the rich:panel, I get an error in Firebug : "map is undefined"...
Can somebody help me to find out the problem please because I didn't find the answer in other thread...
Here is my code:
<!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:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:rich="http://richfaces.org/rich"
xmlns:m="http://code.google.com/p/gmaps4jsf/"><h:head><title>JSF 2.0: Ajax Support</title><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="../css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="http://maps.google.com/maps?file=api&v=2&key=myPersonnalKeyIsWrittenHere"></script>
<script type="text/javascript"
src="http://code.jquery.com/jquery-1.7.1.js"></script>
<style>.optionList {height: 30px;}</style></h:head><h:body>
<div id="container">
<ui:include src="tpl/menu.xhtml" />
<h1>Gmap4Jsf</h1>
<div align="center">
<f:view contentType="text/html">
<h:panelGrid columns="2">
<h:form id="mapform" prependId="false">
<m:map var="map" mapVar="map" gmapKey="#{gmapBean.gmapkey}" id="map" />
</h:form>
<h:panelGroup>
<h:form>
<rich:tabPanel switchType="ajax" width="350" height="400">
<rich:tab label="Using Google Map API">
<h:panelGrid columns="2" columnClasses="optionList">
<h:outputText value="Controls:" />
<h:panelGroup>
Hide
Show
<br />
</h:panelGroup>
<h:outputText value="Zoom:" />
<rich:inputNumberSlider id="zoom" showInput="false"
minValue="1" maxValue="18" value="#{gmapBean.zoom}"
onchange="map.setZoom(this.value)" />
<h:outputText value="Map Type:" />
<h:panelGroup>
<a href="javascript: void 0"
onclick="map.setMapType(G_NORMAL_MAP)">Normal</a>
<a href="javascript: void 0"
onclick="map.setMapType(G_SATELLITE_MAP)">Satellite</a>
<a href="javascript: void 0"
onclick="map.setMapType(G_HYBRID_MAP)">Hybrid</a>
<br />
</h:panelGroup>
</h:panelGrid>
</rich:tab>
<rich:tab label="Using Ajax with JSON">
<rich:dataGrid var="place" value="#{gmapBean.point}"
columns="2">
<h:graphicImage onclick="showPlace('#{place.id}')"
style="cursor:pointer" value="resource://#{place.pic}" />
</rich:dataGrid>
</rich:tab>
</rich:tabPanel>
</h:form>
</h:panelGroup>
</h:panelGrid>
</f:view>
</div>
</div>
Ok I found it out...
I had to define the name of the Javascript variable generated by JSF.
So, I just added the attribut "jsVariable" to my gmap element.
<m:map jsVariable="map" var="map" mapVar="map" gmapKey="#{gmapBean.gmapkey}" id="map" />
Bye

Resources