Artem Moskalev
Artem Moskalev

Reputation: 5818

JSF button is not shown

I have the following code and whatever I do my web browser does not render any submit button.

I am using eclipse with Glassfish.

The problem is also that somehow when I try my examples fast , the server sometimes hangs around and browser is in the waiting mode for minutes without any error or anything.

Sometimes it does give the page away and it works perfect.

Why is the button not shown and my server is so unstable?

<h:head><title>JSF 2: Using @ManagedBean</title>
<link href="./css/styles.css" 
      rel="stylesheet" type="text/css"/> 
</h:head>
<h:body>
<div align="center">
<table class="title">
  <tr><th>JSF 2: Using @ManagedBean</th></tr>
</table>
<p/>
<fieldset>
<legend>Random Results Page</legend>
<h:form>
  Press button to get one of three possible results pages.
  <br/>
  <h:commandButton value="Go to Random Page" action="#{navigator.choosePage}" />
</h:form>
</fieldset>
</div>




 package coreservlets;
import javax.faces.bean.*;

@ManagedBean
@ApplicationScoped 
public class Navigator {
  private String[] resultPages =
    { "page1", "page2", "page3" };

  public String choosePage() {
    return(RandomUtils.randomElement(resultPages));
  }
}

Upvotes: 0

Views: 1513

Answers (1)

BalusC
BalusC

Reputation: 1108742

That can happen if you either forgot to declare the h: XML namespace, causing the <h:xxx> tags being unrecognized. This can be confirmed by just looking at the JSF source code and the generated HTML output (rightclick - View Source in browser).

<html ... xmlns:h="http://java.sun.com/jsf/html">

Or the request URL as you see in browser's address bar didn't match the <url-pattern> of the FacesServlet as mapped in web.xml, causing the <h:xxx> tags being unparsed. This can be confirmed by just looking at the request URL, the web.xml and the generated HTML output.

<url-pattern>*.xhtml</url-pattern>

Or the CSS in styles.css has hidden it in some way. This can be confirmed by checking the CSS file, and/or using the browser's developer toolset and/or checking the generated HTML output.

input[type=submit] {
    display: none; 
}

See also:


Unrelated to the concrete problem, using an application scoped bean for the particular use case is quite strange. It's been shared among all users in all sessions. So if the action is invoked by webapp user X elsewhere in the world, all other webapp users over the world would see it being reflected. Wouldn't you rather use a request or view scoped bean?

See also:

Upvotes: 2

Related Questions