I have a button, when i click a modal panel opened - it's work fine. Now i tried to add a button to hide the panel - it's work also, but the problem is when i tried to show a text "panel closed" after button click it doesn't work. I use Jsf 1.2 and richfaces 3.3.3.
I have the following error message:
org.apache.jasper.el.JspELException: /index.jsp(35,7) 'javascript:Richfaces.hideModalPanel('myModalPanel');#{welcomeBean.showText(true)}' Method not found: class com.firstjsf.backingbeans.WelcomeBean.showText(java.lang.Boolean) at org.apache.jasper.el.JspValueExpression.getValue(JspValueExpression.java:123)
above the code:
index.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"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<f:view>
<h:form>
<rich:panel>
<f:facet name="header">
<h:outputText value="Product"></h:outputText>
</f:facet>
<h:form>
<a4j:commandButton
id="newWid"
value="New Widget..."
immediate="true" ajaxSingle="true"
reRender="text"
oncomplete="javascript:Richfaces.showModalPanel('myModalPanel');"
styleClass="verboseButton noprint" />
</h:form>
<rich:modalPanel id="myModalPanel">
<f:facet name="header">
<h:outputLabel value="123" />
</f:facet>
From Modal Panel
<a4j:commandButton value="Hide" id="btn_hide"
oncomplete="javascript:Richfaces.hideModalPanel('myModalPanel');#{welcomeBean.setShowText(true)}" />
</rich:modalPanel>
<h:outputText id="text"
value="Panel closed"
rendered="#{helloMessage.showText eq true}">
</h:outputText>
</rich:panel>
</h:form>
</f:view>
</html>
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>welcomeBean</managed-bean-name>
<managed-bean-class>com.firstjsf.backingbeans.WelcomeBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<managed-bean>
<managed-bean-name>helloMessageBean</managed-bean-name>
<managed-bean-class>com.firstjsf.backingbeans.HelloMessageBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<navigation-rule>
<description>Welcome page to message page</description>
<from-view-id>/index.jsp</from-view-id>
<navigation-case>
<from-outcome>helloMessage</from-outcome>
<to-view-id>/message.jsp</to-view-id>
</navigation-case>
</navigation-rule>
<navigation-rule>
<description>Welcome page to message page</description>
<from-view-id>/message.jsp</from-view-id>
<navigation-case>
<from-outcome>back</from-outcome>
<to-view-id>/index.jsp</to-view-id>
</navigation-case>
</navigation-rule>
</faces-config>
BeanAction
public class WelcomeBean {
private boolean showText =false;
public String sayHello(){
return "helloMessage";
}
public boolean isShowText() {
return showText;
}
public void setShowText(boolean showText) {
this.showText = showText;
}
}
You're mixing JavaScript and EL expressions, #oncomplete is for executing JavaScript, if you want to do something on the server use #action or #actionListener. Otherwise the expression will be evaluated and the browser will try to execute the return value as if it was JavaScript.
By the way, your code shows you're using setShowText(true) (which is correct), but the exception says you're using just showText(true), which is it then?
Related
I have a problem with faces message rendering in portlet, deployed on HCL portal 9.5, which is on top of Websphere Application Server 9.0.5.7. Portlet has two pages and when I made first page navigation, faces message stops rendering.
First page html:
<div xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:portlet="http://java.sun.com/portlet_2_0"
xmlns:p="http://primefaces.org/ui">
<f:view>
<f:metadata>
<f:event listener="#{pc_TestJSF22View.init}" type="preRenderView"></f:event>
</f:metadata>
<h:head>
<h:outputScript library="primefaces" name="jquery/jquery.js" />
</h:head>
<h:body>
<h:form id="formMain" styleClass="form">
<p:commandButton id="btnTest" value="Test"
action="#{pc_TestJSF22View.doBtnTest}" />
<p:commandButton id="btnSecondPage" value="Second page"
action="#{pc_TestJSF22View.doBtnSecondPage}" ajax="false" />
<p:messages id="msgGlobal" globalOnly="true" showIcon="false">
<p:autoUpdate />
</p:messages>
</h:form>
</h:body>
</f:view>
First page request bean:
public class TestJSF22View extends PageCodeBase {
private TestSess testSess;
public void init() {
if (PrimeFaces.current().isAjaxRequest()) {
return;
}
try {
System.out.println("INIT method");
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
// button action
public String doBtnSecondPage() {
return "testView2";
}
public String doBtnTest() {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("page 1 msg updated"));
return null;
}
protected TestSess getTestSess() {
if (testSess == null) {
testSess = (TestSess) getManagedBean("testSess");
}
return testSess;
}
}
Second page html:
<div xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:portlet="http://java.sun.com/portlet_2_0"
xmlns:p="http://primefaces.org/ui">
<f:view>
<f:metadata>
<f:event listener="#{pc_TestJSF22View2.init}" type="preRenderView"></f:event>
</f:metadata>
<h:head>
<h:outputScript library="primefaces" name="jquery/jquery.js" />
</h:head>
<h:body>
<h:form id="formMain" styleClass="form">
<p:commandButton id="btnFirstPage" value="First page"
action="#{pc_TestJSF22View2.doBtnFirstPage}" ajax="false" />
<p:commandButton id="btnMsg" value="Show message"
action="#{pc_TestJSF22View2.doBtnMsg}" />
<p:messages id="msgGlobal2" globalOnly="true" showIcon="false">
<p:autoUpdate />
</p:messages>
</h:form>
</h:body>
</f:view>
Second page request bean:
public class TestJSF22View2 extends PageCodeBase {
private TestSess2 testSess2;
public void init() {
if (PrimeFaces.current().isAjaxRequest()) {
return;
}
try {
System.out.println("INIT2 method");
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
// button action
public String doBtnFirstPage() {
System.out.println("doBtnFirstPage method");
return "testView";
}
public String doBtnMsg() {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("page 2 msg updated"));
return null;
}
protected TestSess2 getTestSess2() {
if (testSess2 == null) {
testSess2 = (TestSess2) getManagedBean("testSess2");
}
return testSess2;
}
}
faces-config :
<?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>
<view-handler>com.ibm.faces20.portlet.FaceletPortletViewHandler</view-handler>
<el-resolver>com.ibm.faces20.portlet.PortletELResolver</el-resolver>
<resource-handler>com.ibm.faces20.portlet.httpbridge.PortletResourceHandler</resource-handler>
</application>
<factory>
<exception-handler-factory>org.primefaces.application.exceptionhandler.PrimeExceptionHandlerFactory</exception-handler-factory>
</factory>
<component>
<component-type>com.ibm.faces20.portlet.component.PortletActionURL</component-type>
<component-class>com.ibm.faces20.portlet.component.PortletActionURL</component-class>
</component>
<component>
<component-type>com.ibm.faces20.portlet.component.PortletResourceURL</component-type>
<component-class>com.ibm.faces20.portlet.component.PortletResourceURL</component-class>
</component>
<component>
<component-type>com.ibm.faces20.portlet.component.PortletRenderURL</component-type>
<component-class>com.ibm.faces20.portlet.component.PortletRenderURL</component-class>
</component>
<component>
<component-type>com.ibm.faces20.portlet.component.PortletParam</component-type>
<component-class>com.ibm.faces20.portlet.component.PortletParam</component-class>
</component>
<component>
<component-type>com.ibm.faces20.portlet.component.PortletProperty</component-type>
<component-class>com.ibm.faces20.portlet.component.PortletProperty</component-class>
</component>
<component>
<component-type>com.ibm.faces20.portlet.component.PortletNameSpace</component-type>
<component-class>com.ibm.faces20.portlet.component.PortletNameSpace</component-class>
</component>
<managed-bean>
<managed-bean-name>pc_TestJSF22View</managed-bean-name>
<managed-bean-class>pagecode.TestJSF22View</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<managed-bean>
<managed-bean-name>testSess</managed-bean-name>
<managed-bean-class>beans.TestSess</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
<managed-bean>
<managed-bean-name>pc_TestJSF22View2</managed-bean-name>
<managed-bean-class>pagecode.TestJSF22View2</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<managed-bean>
<managed-bean-name>testSess2</managed-bean-name>
<managed-bean-class>beans.TestSess2</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
<render-kit>
<renderer>
<component-family>javax.faces.Output</component-family>
<renderer-type>com.ibm.faces20.portlet.tag.render.ActionURLTagRender</renderer-type>
<renderer-class>com.ibm.faces20.portlet.tag.render.ActionURLTagRender</renderer-class>
</renderer>
</render-kit>
<render-kit>
<renderer>
<component-family>javax.faces.Output</component-family>
<renderer-type>com.ibm.faces20.portlet.tag.render.ResourceURLTagRender</renderer-type>
<renderer-class>com.ibm.faces20.portlet.tag.render.ResourceURLTagRender</renderer-class>
</renderer>
</render-kit>
<render-kit>
<renderer>
<component-family>javax.faces.Output</component-family>
<renderer-type>com.ibm.faces20.portlet.tag.render.RenderURLTagRender</renderer-type>
<renderer-class>com.ibm.faces20.portlet.tag.render.RenderURLTagRender</renderer-class>
</renderer>
</render-kit>
<render-kit>
<renderer>
<component-family>javax.faces.Output</component-family>
<renderer-type>com.ibm.faces20.portlet.tag.render.PortletNameSpaceTagRender</renderer-type>
<renderer-class>com.ibm.faces20.portlet.tag.render.PortletNameSpaceTagRender</renderer-class>
</renderer>
</render-kit>
<navigation-rule>
<from-view-id>/*</from-view-id>
<navigation-case>
<from-outcome>testView</from-outcome>
<to-view-id>/TestJSF22View.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
<navigation-rule>
<from-view-id>/*</from-view-id>
<navigation-case>
<from-outcome>testView2</from-outcome>
<to-view-id>/TestJSF22View2.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
</faces-config>
So, if I illustrate my problem: When I first open portlet and first page is displayed, I click "Test" button, that displays faces message. Next, I navigate to second page and I click "Show message" button, which should display another message on second page, but it doesn't. I get the following warning:
There are some unhandled FacesMessages, this means not every FacesMessage had a chance to be rendered.
These unhandled FacesMessages are:
- page 2 msg updated
Even if I go back to the first page again and hit "Test" button one more time, message is not displayed and the same warning is what I get.
I never had problems with faces messages when I deployed portlets on IBM Websphere Portal Server 7 with JSF 2.0, but now when I run it on HCL portal 9.5 (JSF 2.2), I noticed this strange behavior.
Did I miss something while migrating to HCL portal?
Primefaces version is 7.0, p:messages usage seems ok to me. Could HCL portlet bridge cause that problem? Does anyone have experience with deploying JSF portlets on HCL Portal?
EDIT1:
I've just tried to deploy web application with identical code on Websphere Application Server 9 and it works like a charm. Based on that I believe there's some problem with HCL Portal.
I am using JSF 2.0 in a simple application. I have three beans 1st which is login is in request scope while other 2 in view scope. I have configured in faces-config.xml.
<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">
<navigation-rule>
<from-view-id>*</from-view-id>
<navigation-case>
<from-outcome>loginSuccess</from-outcome>
<to-view-id>/pages/ReportSubmit.jsp</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>reportStatus</from-outcome>
<to-view-id>/pages/ReportStatus.jsp</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>logout</from-outcome>
<to-view-id>/pages/logout.jsp</to-view-id>
</navigation-case>
</navigation-rule>
<managed-bean>
<managed-bean-name>UserBean</managed-bean-name>
<managed-bean-class>com.cognizant.reportgen.LoginBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<managed-bean>
<managed-bean-name>ReportBean</managed-bean-name>
<managed-bean-class>com.cognizant.reportgen.ReportGeneratorBean</managed-bean-class>
<managed-bean-scope>view</managed-bean-scope>
</managed-bean>
<managed-bean>
<managed-bean-name>ReportStatus</managed-bean-name>
<managed-bean-class>com.cognizant.reportgen.ReportStatusBean</managed-bean-class>
<managed-bean-scope>view</managed-bean-scope>
</managed-bean>
</faces-config>
I have a menu.jsp which has below code
menu item1 <h:commandLink action="loginSuccess" value="Generate Reports"></h:commandLink>
menu item 2<h:commandLink action="reportStatus" value="Report Status"></h:commandLink>
In 2 beans, I have methods whose return type is void.
On Login request, I am creating session and setting user detail in session attribute.
Now The problem which I am facing is that
I login with user1, select menu item 1, so corresponding data is displayed.
I login with user2 in next browser window, select menu item 1, so corresponding data is displayed.
I go back to browser window1 (user1), select menu item 1 again, but now in header it displays the user2 name., Also it displays data corresponding to user2.
Please help me with this issue.
//ReportStatusBean.java
public class ReportStatusBean {
private List<ReportAttrDO> reportList;
private HtmlDataTable reportStatusTable;
// getters and setter for above included....
public void checkReportStatus(ActionEvent event) {
ReportGenService reportGenObj = new ReportGenServiceImpl();
HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
UserDetail user = (UserDetail)session.getAttribute("user");
List<ReportAttrDO> reportList = reportGenObj.getReportStatusList(user.getUserId());
setReportList(reportList);
if(reportList.isEmpty())
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "No Records to display.", null));
}
public void viewReport(ActionEvent event) {
ReportAttrDO reportAttrDO = (ReportAttrDO)getReportStatusTable().getRowData();
System.out.println(reportAttrDO.getRequestHeaderId());
}
}
// ReportStatus.jsp
<%#taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%# taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%# taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<f:view>
<html>
<head>
....some script functions..
</head>
<body onload="noBack();" onpageshow="if (event.persisted) noBack();" onunload="">
<center>
<div class="wrapper">
<%#include file="../include/pageheader.jsp"%>
<%#include file="../include/menu.jsp"%>
<h:form id="form2">
<table border="0">
<tr>
<td colspan="2"><h:messages style="color:red;margin:8px;" /></td>
</tr>
<tr>
<td colspan="2"><h:commandButton value="Check Status" actionListener="#{ReportStatus.checkReportStatus}" /></td>
</tr>
</table>
<c:if test="${not empty ReportStatus.reportList}" >
<div style="height:200px;width:600px;overflow:auto;">
<h:dataTable id="table" border="1"
var="row" value="#{ReportStatus.reportList}" cellpadding="5" cellspacing="5"
binding="#{ReportStatus.reportStatusTable}">
<h:column>
<f:facet name="header">
<f:verbatim>
<h:outputText value="Application Name" />
</f:verbatim>
</f:facet>
<h:outputText id="applName" value="#{row.applicationName}" ></h:outputText>
</h:column>
<h:column>
<f:facet name="header">
<f:verbatim>
<h:outputText value="Report Name" />
</f:verbatim>
</f:facet>
<h:outputText id="reportReqName" value="#{row.reportRequestName}"></h:outputText>
</h:column>
<h:column>
<f:facet name="header">
<f:verbatim>
<h:outputText value="Generated Report" />
</f:verbatim>
</f:facet>
<h:commandLink id="viewReport" value="View" rendered="#{row.status == 'Completed'}" actionListener="#{ReportStatus.viewReport}"></h:commandLink>
</h:column>
</h:dataTable>
</div>
</c:if>
</h:form>
</div>
</center>
</body>
</html>
</f:view>
HTTP session is shared among browser's tabs, so what you're experiencing is an expected behaviour. When you did login in a next tab you most probably replaced the existing session attribute.
You can as well try it in different browsers, but not different tabs of the same browser, to see it work as you expect it to work. In the end, session is a per user construct and should be viewed as such. You must define the proper scopes for your beans for the application to run in accordance with your expectations and for good user experience.
Unrelated to your concrete problem, using command links that use POST requests for plain page-to-page navigation is considered to be a bad practice: you should use <h:link> instead. For details see the third reference below.
Also, using faces-config.xml to solely configure navigation rules and declare managed beans in a JSF 2.0 application is somewhat old-school, in my opinion. The last but not the least, JSP is a deprecated view technology nowadays, that was superseded by facelets, so developing new application using JSP as a view technology should be carefully rethought.
See also:
How to choose the right bean scope?;
Communication in JSF 2.0, section on bean scopes;
When should I use h:outputLink instead of h:commandLink?.
You need to render your menu conditionnaly of your session user and not your login result, for example :
<h:form>
<h:panelGroup rendered="#{not userbean.isLogged}">
<h:inputText value="#{userBean.username}" />
<h:inputText value="#{userBean.password}" />
<h:commandButton actionListener="#{userBean.login}" />
</h:panelGroup>
<h:panelGroup rendered="#{userBean.isLogged}">
<h:commandLink rendered="#{userBean.user eq "user1"}" action="loginSuccess" value="Generate Reports"></h:commandLink>
<h:commandLink rendered="#{userBean.user eq "user2"}" action="reportStatus" value="Report Status"></h:commandLink>
</h:panelGroup>
</h:form>
Of course it will require some function inside userBean to get the username for example.
Also you mean that you have configured your bean using ViewScoped, they are all RequestScoped in the code provided.
I suggest you to use .xhtml file name extensions, which is the standard in JavaServer Faces views.
I've a problem with JSF 1.1 (dinosaur, I know)
So there are two pages - index.jsp and test.jsp
I want to be redirected from index.jsp to test.jsp after clicking "Create" button
But nothing happens:/
p.s. and, in general, how do I log the things there, right know there is even no log of the clicking event! it's horrible
index.jsp
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%-- jsf:pagecode language="java" location="/src/pagecode/Index.java" --%><%-- /jsf:pagecode --%>
<%#page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%# taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%# taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<html>
<head>
<title>index</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="GENERATOR" content="IBM WebSphere Integration Developer 6.2">
<link rel="stylesheet" type="text/css" title="Style"
href="theme/stylesheet.css">
</head>
<f:view>
<body>
<h:panelGrid columns="1" width="12%" cellpadding="10" rendered="true">
<h:commandButton value="Create" action="#{Controller.create}" />
</h:panelGrid>
</body>
</f:view>
</html>
Controller.java
public class Controller extends PageCodeBase {
public String create() {
return "success";
}
}
faces-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE faces-config PUBLIC
"-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN"
"http://java.sun.com/dtd/web-facesconfig_1_1.dtd">
<faces-config>
<managed-bean>
<managed-bean-name>Controller</managed-bean-name>
<managed-bean-class>pagecode.Controller</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<navigation-rule>
<display-name>index</display-name>
<from-view-id>/index.jsp</from-view-id>
<navigation-case>
<from-outcome>success</from-outcome>
<to-view-id>/test.jsp</to-view-id>
<redirect />
</navigation-case>
</navigation-rule>
</faces-config>
web.xml
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
<welcome-file>test.jsp</welcome-file>
</welcome-file-list>
The JSF <h:commandButton> generates a HTML <input type="submit"> element which works only when nested in a HTML <form> element whose JSF equivalent is <h:form>.
However, you don't have a <h:form> anywhere in your view. Add it accordingly:
<h:form>
<h:commandButton value="Create" action="#{Controller.create}" />
</h:form>
By the way, if all your create method does is returning a fixed outcome, then you can also just specify the outcome directly in the action attribute:
<h:form>
<h:commandButton value="Create" action="success" />
</h:form>
By the way #2, using POST for page-to-page navigation is a bad practice, you should prefer output links for this.
See also:
commandButton/commandLink/ajax action/listener method not invoked or input value not updated - point 1
The create method should return a string. This string is the path to the page where you want to redirect.
Replace:
return "success";
For:
return "yourpage"
I have made a Login.xhtml by using Apache Myfaces 2.1 (using JSF 1.x)
When I have given my username and password on login.xhtml and one submit button is there.
When I click on goodbye button, the control goes to wsListing.xhtml but the URL in the browser remain as
http://hostid:8080/TestClient/faces/login.xhtml
I want it to be changed as
http://hostid:8080/TestClient/faces/wsListing.xhtml
I have attached the code for the same, please suggest me some solution, I am new to JSF.
Login.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:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui" xmlns:lang="en">
<f:view>
<head>
<title>Test Client Login</title>
</head>
<h:form id="loginForm">
<table>
<tr>
<h:outputLabel for="username">
<h:outputText id="usernameLabel" value="Enter Username:" />
</h:outputLabel>
<h:inputText id="username" value="#{loginBean.username}"
required="true">
<f:validateLongRange minimum="1" maximum="500" />
</h:inputText>
</tr>
<tr>
<h:outputLabel for="password">
<h:outputText id="passwordLabel" value="Enter Password:" />
</h:outputLabel>
<h:inputText id="password" value="#{loginBean.password}"
required="true">
<f:validateLongRange minimum="1" maximum="500" />
</h:inputText>
</tr>
<tr>
<h:commandButton id="goodbyeCommand" type="submit" value="Goodbye"
action="#{loginBean.goodbye}" immediate="true" />
</tr>
</table>
</h:form>
</f:view>
</html>
LoginBean.java
package com.example;
/**
* Managed Bean for Login
*
*/
public class LoginBean {
private String username;
private String password;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String goodbye() {
return "success";
}
}
faces-config.xml
<?xml version="1.0"?>
<faces-config version="1.2" 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_1_2.xsd">
<managed-bean>
<description>Login Bean</description>
<managed-bean-name>loginBean</managed-bean-name>
<managed-bean-class>com.example.LoginBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
<navigation-rule>
<description>Navigation from the hello page.</description>
<from-view-id>/login.xhtml</from-view-id>
<navigation-case>
<from-outcome>success</from-outcome>
<to-view-id>/wsListing.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
</faces-config>
You need to send a redirect. Add <redirect /> to the <navigation-case />.
<navigation-case>
<from-outcome>success</from-outcome>
<to-view-id>/wsListing.xhtml</to-view-id>
<redirect />
</navigation-case>
Unrelated to the concrete problem, MyFaces 2.1 is a JSF 2.1 implementation. Why are you forcing the webapp to run in JSF 1.2 modus? You miss so many JSF 2.x advantages.
I have what I thought was simple JSF navigation setup but when I hit the h:commandButton the page reloads, not the page I want to load. The faces-config snippet is here:
<navigation-rule>
<from-view-id>/index.jsf</from-view-id>
<navigation-case>
<from-outcome>hello</from-outcome>
<to-view-id>/next.jsf</to-view-id>
</navigation-case>
</navigation-rule>
the index.xhtml file contains this:
<f:view>
<a4j:region id="topRegion">
<rich:page pageTitle="myapp" markupType="xhtml" id="top">
<f:facet name="header">
<h:form>
<rich:toolBar height="45" itemSeparator="disc">
<rich:toolBarGroup location="left">
<h:form name="selectForm">
<h:panelGrid columns="5" style="padding: 2px;">
<h:outputText style="text-align: center" value="Node Select " />
<h:selectOneMenu id="nodes" value="#{MyBacking.chosenNode}">
<f:selectItems value="#{MyBacking.nodes}" />
</h:selectOneMenu>
<h:commandButton value="Retrieve" styleClass="ctrlBtn"
id="retrieveBtn" style="margin-bottom: 2px;"
action="hello"
image="/img/btnRetrieve26.png" />
</h:panelGrid>
</h:form>
</rich:toolBarGroup>
</rich:toolBar>
</h:form>
It's as simple as that. Can anyone tell me why it's not working?
As far as I'm aware, the from-outcome of hello should be used by the h:commandbutton and load next.xhtml file.
Your files are .xhtml not .jsf
have you tried:
<navigation-rule>
<from-view-id>/index.xhtml</from-view-id>
<navigation-case>
<from-outcome>hello</from-outcome>
<to-view-id>/next.xhtml</to-view-id>
</navigation-case>
</navigation-rule>