<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <title>JavaServer Faces portlet does not do command action</title>
  <link rel="self" href="https://uat.liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=122126571" />
  <subtitle>JavaServer Faces portlet does not do command action</subtitle>
  <id>https://uat.liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=122126571</id>
  <updated>2026-10-15T11:16:45Z</updated>
  <dc:date>2026-10-15T11:16:45Z</dc:date>
  <entry>
    <title>JavaServer Faces portlet does not do command action</title>
    <link rel="alternate" href="https://uat.liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=122125970" />
    <author>
      <name>Brian Lavender</name>
    </author>
    <id>https://uat.liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=122125970</id>
    <updated>2023-10-19T16:55:49Z</updated>
    <published>2023-10-17T23:42:07Z</published>
    <summary type="html">&lt;p&gt;I put together a simple java serverfaces application using the Maven
  archetype to build it. It is based upon a texbook example from Cay
  Horstmann's _Core Java Server Faces_ book. The issue that when you
  answer question 1 on the first page, it navigates to
  &amp;quot;/success.xhtml&amp;quot; based upon the rule in
  &lt;em&gt;faces-config.xml.&lt;/em&gt; It does correctly, so I believe. The issue
  comes when I am on &lt;em&gt;/success.xhtml&lt;/em&gt; and it asks me the next
  question. I hit the &lt;em&gt;commandButton &lt;/em&gt;that calls the action
    &lt;em&gt;quizBean.answerAction. &lt;/em&gt;When I look at the debug output, I
  don't see any evidence of this action being called! It's as if bridge
  lost track of itsself and bounces back to &lt;em&gt;/view.xhtml. &lt;/em&gt;I am
  not sure why this happens. Any tips?&lt;br&gt; ​​​​​​​&lt;/p&gt;
&lt;pre&gt;
&lt;code class="language-html"&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot;?&amp;gt;

&amp;lt;faces-config version=&amp;quot;2.2&amp;quot;
	xmlns=&amp;quot;http://xmlns.jcp.org/xml/ns/javaee&amp;quot;
	xmlns:xsi=&amp;quot;http://www.w3.org/2001/XMLSchema-instance&amp;quot;
	xsi:schemaLocation=&amp;quot;http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd&amp;quot;
&amp;gt;
	&amp;lt;lifecycle&amp;gt;
		&amp;lt;phase-listener&amp;gt;com.liferay.faces.util.lifecycle.DebugPhaseListener&amp;lt;/phase-listener&amp;gt;
		&amp;lt;phase-listener&amp;gt;com.liferay.faces.util.lifecycle.ViewScopePhaseListener&amp;lt;/phase-listener&amp;gt;
	&amp;lt;/lifecycle&amp;gt;
	
	&amp;lt;navigation-rule&amp;gt;
	 &amp;lt;from-view-id&amp;gt;/done.xhtml&amp;lt;/from-view-id&amp;gt;
      &amp;lt;navigation-case&amp;gt;
         &amp;lt;from-outcome&amp;gt;startOver&amp;lt;/from-outcome&amp;gt;
         &amp;lt;to-view-id&amp;gt;/view.xhtml&amp;lt;/to-view-id&amp;gt;
      &amp;lt;/navigation-case&amp;gt;
   &amp;lt;/navigation-rule&amp;gt;
   
   &amp;lt;navigation-rule&amp;gt;
      &amp;lt;from-view-id&amp;gt;/again.xhtml&amp;lt;/from-view-id&amp;gt;
      &amp;lt;navigation-case&amp;gt;
         &amp;lt;from-outcome&amp;gt;failure&amp;lt;/from-outcome&amp;gt;
         &amp;lt;to-view-id&amp;gt;/failure.xhtml&amp;lt;/to-view-id&amp;gt;
      &amp;lt;/navigation-case&amp;gt;
       &amp;lt;navigation-case&amp;gt;
         &amp;lt;from-outcome&amp;gt;success&amp;lt;/from-outcome&amp;gt;
         &amp;lt;to-view-id&amp;gt;/success.xhtml&amp;lt;/to-view-id&amp;gt;
      &amp;lt;/navigation-case&amp;gt;
   &amp;lt;/navigation-rule&amp;gt;
   
   &amp;lt;navigation-rule&amp;gt;
      &amp;lt;from-view-id&amp;gt;/success.xhtml&amp;lt;/from-view-id&amp;gt;
      &amp;lt;navigation-case&amp;gt;
         &amp;lt;from-outcome&amp;gt;failure&amp;lt;/from-outcome&amp;gt;
         &amp;lt;to-view-id&amp;gt;/again.xhtml&amp;lt;/to-view-id&amp;gt;
      &amp;lt;/navigation-case&amp;gt;
       &amp;lt;navigation-case&amp;gt;
         &amp;lt;from-outcome&amp;gt;success&amp;lt;/from-outcome&amp;gt;
         &amp;lt;to-view-id&amp;gt;/success.xhtml&amp;lt;/to-view-id&amp;gt;
      &amp;lt;/navigation-case&amp;gt;
   &amp;lt;/navigation-rule&amp;gt;
   
   &amp;lt;navigation-rule&amp;gt;
   		&amp;lt;from-view-id&amp;gt;/view.xhtml&amp;lt;/from-view-id&amp;gt;
      &amp;lt;navigation-case&amp;gt;
         &amp;lt;from-outcome&amp;gt;failure&amp;lt;/from-outcome&amp;gt;
         &amp;lt;to-view-id&amp;gt;/again.xhtml&amp;lt;/to-view-id&amp;gt;
      &amp;lt;/navigation-case&amp;gt;
      &amp;lt;navigation-case&amp;gt;
         &amp;lt;from-outcome&amp;gt;success&amp;lt;/from-outcome&amp;gt;
         &amp;lt;to-view-id&amp;gt;/success.xhtml&amp;lt;/to-view-id&amp;gt;
      &amp;lt;/navigation-case&amp;gt;
   &amp;lt;/navigation-rule&amp;gt;
   


   &amp;lt;application&amp;gt;
      &amp;lt;resource-bundle&amp;gt;
         &amp;lt;base-name&amp;gt;com.corejsf.messages&amp;lt;/base-name&amp;gt;
         &amp;lt;var&amp;gt;msgs&amp;lt;/var&amp;gt;
      &amp;lt;/resource-bundle&amp;gt;
   &amp;lt;/application&amp;gt;
   
&amp;lt;/faces-config&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;/success.xhtml&lt;br&gt;  &lt;/p&gt;
&lt;pre&gt;
&lt;code class="language-html"&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot;?&amp;gt;
&amp;lt;!DOCTYPE html PUBLIC &amp;quot;-//W3C//DTD XHTML 1.0 Transitional//EN&amp;quot;
&amp;quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&amp;quot;&amp;gt;
&amp;lt;f:view
	xmlns=&amp;quot;http://www.w3.org/1999/xhtml&amp;quot;
	xmlns:f=&amp;quot;http://xmlns.jcp.org/jsf/core&amp;quot;
	xmlns:h=&amp;quot;http://xmlns.jcp.org/jsf/html&amp;quot;
&amp;gt;
   &amp;lt;h:head&amp;gt;
     &amp;lt;h:outputStylesheet library=&amp;quot;css&amp;quot; name=&amp;quot;main.css&amp;quot; /&amp;gt;
   &amp;lt;/h:head&amp;gt;
   &amp;lt;h:body&amp;gt;
  	 &amp;lt;h:panelGroup id=&amp;quot;panelId&amp;quot; layout=&amp;quot;block&amp;quot;&amp;gt;
      &amp;lt;h:form&amp;gt;
         &amp;lt;p&amp;gt;
            #{msgs.correct}
            &amp;lt;h:outputFormat value=&amp;quot;#{msgs.score}&amp;quot;&amp;gt;
               &amp;lt;f:param value=&amp;quot;#{quizBean.score}&amp;quot;/&amp;gt;
            &amp;lt;/h:outputFormat&amp;gt;
         &amp;lt;/p&amp;gt;
         &amp;lt;p&amp;gt;#{msgs.nextProblem}&amp;lt;/p&amp;gt;
         &amp;lt;p&amp;gt;#{quizBean.question}&amp;lt;/p&amp;gt;
         &amp;lt;p&amp;gt;&amp;lt;h:inputText value=&amp;quot;#{quizBean.response}&amp;quot;/&amp;gt;&amp;lt;/p&amp;gt;
         &amp;lt;p&amp;gt;
            &amp;lt;h:commandButton value=&amp;quot;#{msgs.checkAnswer}&amp;quot; action=&amp;quot;#{quizBean.answerAction}&amp;quot;&amp;gt;
            	
            &amp;lt;/h:commandButton&amp;gt;
         &amp;lt;/p&amp;gt;
      &amp;lt;/h:form&amp;gt;
      &amp;lt;/h:panelGroup&amp;gt;
   &amp;lt;/h:body&amp;gt;
&amp;lt;/f:view&amp;gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Quiz bean&lt;br&gt; ​​​​​​​&lt;/p&gt;
&lt;pre&gt;
&lt;code class="language-java"&gt;package com.corejsf;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;

import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Named;
import javax.portlet.PortletRequest;
import javax.portlet.annotations.PortletSessionScoped;

import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.model.User;
import com.liferay.portal.kernel.theme.ThemeDisplay;
import com.liferay.portal.kernel.util.WebKeys;



@Named // or @ManagedBean
@PortletSessionScoped
public class QuizBean implements Serializable {
	   private static final long serialVersionUID = -4712268339879239065L;
	   private int currentProblem;
	   private int tries;
	   private int score;
	   private String response = &amp;quot;&amp;quot;;
	   private String correctAnswer;
	   
	   	private Greeting greeting = new Greeting();

	public Greeting getGreeting() {
		_log.debug(&amp;quot;REturning greeting for bean&amp;quot;);
		return greeting;
	}
	
	@PostConstruct
	public void postConstruct() {
		_log.info(&amp;quot;post construct&amp;quot;);
	}

	   // Here, we hardwire the problems. In a real application,
	   // they would come from a database
	   
	   private ArrayList&amp;lt;Problem&amp;gt; problems = new ArrayList&amp;lt;Problem&amp;gt;(Arrays.asList(
	      new Problem(
	         &amp;quot;What trademarked slogan describes Java development? Write once, ...&amp;quot;,
	         &amp;quot;run anywhere&amp;quot;),
	      new Problem(
	         &amp;quot;What are the first 4 bytes of every class file (in hexadecimal)?&amp;quot;,
	         &amp;quot;CAFEBABE&amp;quot;),
	      new Problem(
	         &amp;quot;What does this statement print? System.out.println(1+\&amp;quot;2\&amp;quot;);&amp;quot;,
	         &amp;quot;12&amp;quot;),
	      new Problem(
	         &amp;quot;Which Java keyword is used to define a subclass?&amp;quot;,
	         &amp;quot;extends&amp;quot;),
	      new Problem(
	         &amp;quot;What was the original name of the Java programming language?&amp;quot;,
	         &amp;quot;Oak&amp;quot;),
	      new Problem(
	         &amp;quot;Which java.util class describes a point in time?&amp;quot;,
	         &amp;quot;Date&amp;quot;)));

	   public String getQuestion() { 
		   _log.info(&amp;quot;Question number is &amp;quot; + currentProblem);
		   _log.info(&amp;quot;Calling get question &amp;quot; + problems.get(currentProblem).getQuestion());
		   return problems.get(currentProblem).getQuestion(); 
	   }

	   public String getAnswer() { 
		   _log.info(&amp;quot;get correct answer is &amp;quot; + correctAnswer);
		   return correctAnswer; 
	   }

	   public int getScore() { 
		return score; 
		}

	   public String getResponse() { 
		return response; 
		}
	   public void setResponse(String newValue) { 
		response = newValue; 
		}

	   public String answerAction() {
		   _log.info(&amp;quot;answer Action called&amp;quot;);
	      tries++;
	      _log.info(&amp;quot;answerAction. tries is &amp;quot; + tries);
	      if (problems.get(currentProblem).isCorrect(response)) {
	         score++;
	         nextProblem();
	         if (currentProblem == problems.size()) 
	        	 return &amp;quot;done&amp;quot;;
	         else 
	        	 return &amp;quot;success&amp;quot;;
	      }
	      else if (tries == 1) 
	    	  return &amp;quot;again&amp;quot;;
	      else {
	         nextProblem();
	         if (currentProblem == problems.size()) 
	        	 return &amp;quot;done&amp;quot;;
	         else 
	        	 return &amp;quot;failure&amp;quot;;
	      }
	   }

	   public String startOverAction() {
	      Collections.shuffle(problems);
	      currentProblem = 0;
	      score = 0;
	      tries = 0;
	      response = &amp;quot;&amp;quot;;
	      return &amp;quot;startOver&amp;quot;;
	   }

	   private void nextProblem() {
		   _log.info(&amp;quot;CAlling next problem&amp;quot;);
	      correctAnswer = problems.get(currentProblem).getAnswer();
	      currentProblem++;
	      tries = 0;
	      response = &amp;quot;&amp;quot;;
	   }
	   
	   
		@Inject
		private PortletRequest portletRequest;

		public String getName() {

			ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);
			User user = themeDisplay.getUser();

			return user.getFirstName() + &amp;quot; &amp;quot; + user.getLastName();
		}
	   
		// Logger
		private static final Log _log = LogFactoryUtil.getLog(QuizBean.class);
	}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt; &lt;/p&gt;</summary>
    <dc:creator>Brian Lavender</dc:creator>
    <dc:date>2023-10-17T23:42:07Z</dc:date>
  </entry>
</feed>
