Verification value error that occurred in a clustering environment

Validation error occurs in clustering environment

Development environment

Event

There are radio buttons whose choices change depending on the parameters. When I select and post any item, ** "j_idt39: Validation error: Value is not valid" ** occurs. It does not occur in a local or single instance environment.

Cause

The project requirements did not use sticky sessions and were randomly assigned to the server for each communication. As a result, the beans were replicated in the session, and there was a list of radio button choices with no initial value (null) in it. Unfortunately when I posted, I was getting a validation error when the list hit a null bean.

Source of problem

XHTML

<form jsf:id="form" jsf:prependId="false">
            <h:selectOneRadio name="choiceName" value="#{choiceBean.choiceName}" styleClass="radio_list">
                <f:selectItems value="#{choiceBean.choiceList}" var="prize" itemLabel="#{item.labelName}" itemValue="#{item}" />
            </h:selectOneRadio>

        <button jsf:action="#{pageControlBean.toConfirm()}" class="btn_orange">
next
        </button>
    <span jsfc="h:messages" class="form_error_text" />
</form>

Bean

@Named
@SessionScoped
public class ChoiceBean implements Serializable {

	private static final long serialVersionUID = 1L;

	@NotNull
	@Getter @Setter
	private ChoiceType choiceName;

	@Getter @Setter
	private List<ChoiceType> choiceList;
}

Enum

public enum ChoiceType {
	TYPE1("Type 1", 0),
	TYPE2("Type 2", 1),
	TYPE3("Type 3", 2);

	@Getter
	private final String labelName;

	@Getter
	private final int index;

	private ChoiceType(String labelName, int index) {
		this.labelName = labelName;
		this.index = index;
	}
}

Solution

Set the initial value in the constructor.

Bean

@Named
@SessionScoped
public class ChoiceBean implements Serializable {
	private static final long serialVersionUID = 1L;

	@NotNull
	@Getter
	@Setter
	private PrizeType choiceName;

	@Getter
	@Setter
	private List<ChoiceType> choiceList;

	/**
	 * Constructor
	 *Not Null variable initial value setting
	 */
	public ChoiceBean() {
		choiceList = new ArrayList<>();
		choiceList.add(ChoiceType.TYPE1);
		choiceList.add(ChoiceType.TYPE2);
		choiceList.add(ChoiceType.TYPE3);
	}
}

Survey tips

Finally, I investigated with an IDE (such as the paid version Intellij) that can see the contents of the session and found a copy of the bean. It seems that you can see it in NetBeans with JavaEE.

Recommended Posts

Verification value error that occurred in a clustering environment
Error memorandum that occurred when creating a CI / CD environment [Rails + CircleCI + Capistrano + AWS]
About the solution of the error that occurred when trying to create a Japanese file of devise in the Docker development environment
Determine that the value is a multiple of 〇 in Ruby
Resolve CreateProcess error = 206 when running Java in a Windows environment
[Docker] The story that an error occurred in docker-compose up
[Rails] Error that occurred in automatic deployment by Capistrano (fatal: not a valid object name: master)
The story that Tomcat suffered from a timeout error in Eclipse
Resolved the error that occurred when trying to use Spark in an environment where Java 8 and Java 11 coexist.
[Rails] About the error that the image is not displayed in the production environment
Sample program that returns the hash value of a file in Java
Building a Lambda development environment in Eclipse
Creating a Servlet in the Liberty environment
Take a thread dump in a JRE environment
A CSRF countermeasure error occurred in a request via ELB, so debugging and resolution
(Capistrano) After deploying, I get a We're sorry… error in the production environment.
Define a new buy method that receives Vehicle type value in Person.java argument.
A bat file that uses Java in windows
500 Internal Server Error occurs in Rails production environment
Ruby on Rails Incorrect string value error resolution when posting a form in Japanese
A story that got stuck with an error during migration in docker PHP laravel
How to deal with Selenium :: WebDriver :: Error :: UnknownError that occurs in Dokcer environment etc.