Class Form (globally available)

The form class enables you to easily create forms that change editmode and readmode controlled by session variable called editmode. All input elements have an additional CSS class wfe-input, that can be easily addressed with jQuery to collect all entered data, i.e.

var formValues = [];
$('.wfe-input').each(function(){
   formValues.push(
      {name: $(this).attr("name"), value: $(this).val()}
   );
});
console.log(formValues);

Available fields

input_text( $label, $fieldname, $fieldvalue=””, $editmode=null, $validation=””)

A simple input field of type text

Example:

 {!!Form::input_text('Key', 'profilekey', $profile->profilekey, true)!!}
Result:
<div class="row">
 <div class="col-md-4">
 <label for="profilekey" styleclass="kitc_label">Key</label>
 </div>
 <div class="col-md-8">
 <input id="profilekey" type="text" name="profilekey" value="Hosenbein" data-validation="" class="form-control wfe-input">
 </div>
</div>
Visual:

input_textarea( $label, $fieldname, $fieldvalue=””, $editmode=null, $validation=””)

input_hidden( $fieldname, $fieldvalue )

 {!!Form::input_dropdown('Dropdown', 'dropdownvalue', ["Hase","Igel"], true)!!}
 {!!Form::input_checkbox('Checkbox', 'checkboxvalue', ["Hase","Igel","Baer","Banane"],["Igel","Baer"],4 )!!}

Buttons

button_edit( $model, $model_id, $refresh_panel )

button_save( $model, $model_id, $refresh_panel )

button_saveclose( $model, $model_id, $refresh_panel )

button_cancel( $model, $model_id, $refresh_panel )

buttons($types=”save,saveclose,edit,cancel”)

Form tags

open(open($type=”AJAX”, $actionURL=””, $cancelURL=”/”, $model, $model_id=””, $refresh_panel=””)

the opening tag and form behaviour configuration here. Where possible try to use AJAX as option, as this gives you the option to switch nicely between EditMode and ReadMode.

close()

Closes the form with

</form>

Xpages: PHPs nl2br function for Java and Xpages

Coming from Web development with PHP and MySQL data, I often used the nice function string nl2br(string $string) that converts new lines into HTML <br> tags. It seems that there is no equivalent function in JAVA. In order to get my Lotus Notes database Text fields converted into HTML code, I created the following static function in my HelperClass

public static String nl2br(String rawString){
		
	String breakTag = "<br />";
	String regex = "[\\n]+";
	Pattern pattern = Pattern.compile(regex);
	Matcher matcher = pattern.matcher(rawString);
		
	StringBuilder result = new StringBuilder();
	result.append(rawString);
		
	Integer longerIndex = 0;
	
	while (matcher.find()){
		result.replace(matcher.start()+longerIndex, matcher.end()+longerIndex, breakTag);
		longerIndex = longerIndex + breakTag.length() - matcher.group().length();
	}
	return result.toString();
}

Hope that will help someone.

Average Speed, Distance and Time Calculators

average-speed-calculator
Krause IT Consulting developed the very useful calculators using JavaScript (jQuery) running locally on your computer’s browser to calculate the following:

  • Average Speed = Distance / Time
  • Distance = Average Speed * Time
  • Time = Distance / Average Speed

They were initially developed for athletes to get more information about their work-outs or races, but they can be used for pretty much everything, i.e. If you throw a stone 35 meters and you stop the time between the stone leaving your hand and hitting the floor, you can easily calculate the average speed the stone had during it’s 35m travel.

The calculators are designed to accommodate imperial and metric measurements.

Check it out here!