/* 
 * Qlue Web Application Framework
 * Copyright 2009 Ivan Ristic <ivanr@webkreator.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.webkreator.qlue.example.pages;

import java.io.PrintWriter;

import com.webkreator.qlue.Page;
import com.webkreator.qlue.QlueParameter;
import com.webkreator.qlue.view.View;

/**
 * An example page that has one parameter and produces output
 * by writing directly to the client.
 */
public class helloStranger extends Page {

	@QlueParameter(mandatory = true, maxSize = 10, pattern = "^[a-zA-Z]+$")
	public String name;

	@Override
	public View onGet() throws Exception {
		PrintWriter out = context.response.getWriter();
		
		context.response.setContentType("text/plain");
		
		if (errors.hasErrors()) {
			for (com.webkreator.qlue.Error e : errors.getAllErrors()) {
				out.print(e.getMessage());
				if (e.getField() != null) {
					out.print(" [" + e.getField() + "]");
					out.println();
				}
			}
			
			return null;
		}

		if (name == null) {
			out.println("Hello Stranger!");
		} else {
			out.println("Hello " + name + "!");
		}
		
		throw new Exception("test");

		//return null;
	}
}

/* 
 * Qlue Web Application Framework
 * Copyright 2009 Ivan Ristic <ivanr@webkreator.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.webkreator.qlue.example.pages;

import java.io.PrintWriter;

import com.webkreator.qlue.Page;
import com.webkreator.qlue.QlueParameter;
import com.webkreator.qlue.view.View;

/**
 * An example page that has one parameter and produces output
 * by writing directly to the client.
 */
public class helloStranger extends Page {

	@QlueParameter(mandatory = false, maxSize = 10, pattern = "^[a-zA-Z]+$")
	public String name;

	@Override
	public View onGet() throws Exception {
		PrintWriter out = context.response.getWriter();		

		if (name == null) {
			out.println("Hello Stranger!");
		} else {
			out.println("Hello " + name + "!");
		}		

		return null;
	}
}

Tidy up.