Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6810789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:14:54+00:00 2026-05-26T20:14:54+00:00

I have a commandButton in JSF 2.0 with a actionvalue that I want to

  • 0

I have a commandButton in JSF 2.0 with a actionvalue that I want to call a method in a bean and otherwise do nothing. However when I click on it, it redirects to the previous page.

This was programmed in java 1.7 in eclipse using glassfish 3.1.1.

Here is the code for the welcome.xhtml file where the commandButton is (showDetails) but there are many other files, so I have included a link to a WAR file so it is possible to check everything out. If i change the action attribute to point to a method that does not exist I will not get an error, I will again be redirected to the frontpage.

The program is started from the index.html file. After importing remember to leftclick on the project, go to properties>project facets and tick of JavaServerFaces 2.0

The relevant code:

welcome.xhtml

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!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>Insert title here</title>
</h:head>

<h:body>
<h3>#{userBean.user.name}</h3>
<hr />
<form>
    <h:commandButton value="Back" action="index" />
</form>
<form>
    <h:commandButton value="Show details" action="#{userBean.changeRenderDetails}" />

    <h:panelGrid rendered="#{userBean.renderDetails}" columns="2">
        <h:outputText value="Brugernavn:" /> #{userBean.user.name}
        <h:outputText value="Password:" /> #{userBean.user.password}
    </h:panelGrid>

</form>
</h:body>
</html>

userBean

package model;

import java.io.Serializable;

import javax.enterprise.context.SessionScoped;
import javax.inject.Inject;
import javax.inject.Named;

@Named("userBean")
// or @ManagedBean(name="user")
@SessionScoped
public class UserBean implements Serializable {

// Oprettes når en bean oprettes
private User user = new User("", "");

@Inject
// Det nuværende service objekt initialiseres automatisk
private Service service;

public String validateUser() {
    return service.validateUser(user);
}

public User getUser() {
    return user;
}

public void setUser(User user) {
    this.user = user;
}


//Lektion 10 - opg1

private boolean renderDetails;

public void changeRenderDetails(){
    setRenderDetails(!isRenderDetails());
}

public boolean isRenderDetails() {
    return renderDetails;
}

public void setRenderDetails(boolean renderDetails) {
    this.renderDetails = renderDetails;
}



}

and the user class

package model;

public class User {

private String name;
private String password;

public User(String name, String password) {
    super();
    this.name = name;
    this.password = password;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public String getPassword() {
    return password;
}

public void setPassword(String password) {
    this.password = password;
}

}

navigation rules, none of which should have anything to do with the button which redirects to index.html:

<?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">
<navigation-rule>
    <from-view-id>/index.xhtml</from-view-id>
    <navigation-case>
        <from-outcome>success</from-outcome>
        <to-view-id>/welcome.xhtml</to-view-id>
    </navigation-case>
    <navigation-case>
        <from-outcome>failure</from-outcome>
        <to-view-id>/error.xhtml</to-view-id>
    </navigation-case>
</navigation-rule>
</faces-config>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T20:14:54+00:00Added an answer on May 26, 2026 at 8:14 pm

    As shown in every decent JSF book/tutorial, you should be using <h:form> instead of <form>.

    <h:form>
        <h:commandButton value="Back" action="index" />
    </h:form>
    <h:form>
        <h:commandButton value="Show details" action="#{userBean.changeRenderDetails}" />
        <h:panelGrid rendered="#{userBean.renderDetails}" columns="2">
            <h:outputText value="Brugernavn:" /> #{userBean.user.name}
            <h:outputText value="Password:" /> #{userBean.user.password}
        </h:panelGrid>
    </h:form>
    

    See also

    • commandButton/commandLink/ajax action/listener method not invoked or input value not set/updated #1
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JSF 2.0 page that I want to allow a GET parameter
In my JSF 1.2 webapp I have a page with a <h:commandButton> that invokes
I have the following code inside a method invoked by a jsf <h:commandButton>. It
I have a bean with a field called 'name', and a JSF form that
Is it possible to have the JSF update a component that's placed outside the
Richfaces 3.3.3, Jsf 1.2: I have a a4j:form that uses some simple validation, mainly
I have a JSF 1.2 application (Sun RI, Facelets, Richfaces) that was used only
I have a JSF page that includes a tree form tag which is rendered
I have a form in my jsf page(a popup) that I used to upload
I use JSF 1.2. I have a view in which I have a h:commandButton

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.