/
Java Condition

Java Condition

The Java Condition

The Java Condition can be used to check the value of a static field in a java class.

Example accessing a static field:

 <condition type="java" id="myStaticFieldIsTrue">
  <java>
    <class>my.package.MyClass</class>
    <field>myStaticField</field>
  </java>
  <returnvalue type="boolean">true</returnvalue>
</condition>


Example accessing a static method (as from izPack 5.2.0):

 <condition type="java" id="myStaticFieldIsTrue">
  <java>
    <class>my.package.MyClass</class>
    <method>processCondition</method>
  </java>
  <returnvalue type="boolean">true</returnvalue>
</condition>

Nested Elements

The Java condition must have a ava element and a returnvalue element.

java

The java element contains two mandatory elements, class and field. <class> contains the fully qualified name of the class and either a <field> contains the name of the static field or a <method> containing the static method to inspect.

returnvalue

This element defines what is the expected value. Currently, only type="boolean" and "string" (as of izPack 5.2.0) are supported.


Complicated condition checks - example

In order to check for complicated conditions with java you can do the following. Assume that we use the same condition as above.


package my.package
 
public class MyClass {
	public static boolean myStaticField = processCondition();
 
	public static boolean processCondition() {
		boolean conditionTrue = false;	
		//call other classes, conditionals, do processing, etc.
		return conditionTrue;
	}
} 

  


Note that for logging you will need to use log4j or similar. I use groovy in conjunction with an AntListener to log condition logs to temp. An easier way to accomplish this is to use process panels but if you absolutely must have a condition determined by java methods then this is the best way


Related content

Predefined Conditions
Predefined Conditions
Read with this
Dynamic Conditions
Dynamic Conditions
More like this
Panels
Read with this
Conditions
Conditions
More like this
Panel Actions
Panel Actions
Read with this
Field Validators
Field Validators
More like this