<commit_before>/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.venky.swf.views.model;

import java.lang.reflect.Method;
import java.util.List;

import com.venky.swf.db.Database;
import com.venky.swf.db.model.Model;
import com.venky.swf.routing.Path;
import com.venky.swf.views.controls.page.Body;
import com.venky.swf.views.controls.page.layout.LineBreak;

/**
 *
 * @author venky
 */
public class ModelShowView<M extends Model> extends ModelEditView<M> {

    public ModelShowView(Path path, Class<M> modelClass, String[] includeFields, M record) {
        super(path, modelClass, includeFields, record);
    }

    @Override
    protected boolean isFieldEditable(String fieldName) {
        return false;
    }
    
    @Override
    protected String getFormAction(){
        return "back";
    }
    
    protected void createBody (Body b){
    	super.createBody(b);
        for (Method childGetter: getReflector().getChildGetters()){
        	if (!List.class.isAssignableFrom(childGetter.getReturnType())){
        		continue;
        	}
        	Class childClass = getReflector().getChildModelClass(childGetter);
        	Path childPath = new Path(getPath().getTarget()+"/"+Database.getInstance().getTable(childClass).getTableName().toLowerCase());
        	if (childPath.canAccessControllerAction()){
            	List<Model> children;
    			try {
    				children = (List<Model>)childGetter.invoke(getRecord());
    			} catch (Exception e) {
    				throw new RuntimeException(e);
    			}
            	b.addControl(new LineBreak());<commit_msg>Fixed NPE by setting required variables on Path before checking permission for the path<commit_after>/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.venky.swf.views.model;

import java.lang.reflect.Method;
import java.util.List;

import com.venky.swf.db.Database;
import com.venky.swf.db.model.Model;
import com.venky.swf.routing.Path;
import com.venky.swf.views.controls.page.Body;
import com.venky.swf.views.controls.page.layout.LineBreak;

/**
 *
 * @author venky
 */
public class ModelShowView<M extends Model> extends ModelEditView<M> {

    public ModelShowView(Path path, Class<M> modelClass, String[] includeFields, M record) {
        super(path, modelClass, includeFields, record);
    }

    @Override
    protected boolean isFieldEditable(String fieldName) {
        return false;
    }
    
    @Override
    protected String getFormAction(){
        return "back";
    }
    
    protected void createBody (Body b){
    	super.createBody(b);
        for (Method childGetter: getReflector().getChildGetters()){
        	if (!List.class.isAssignableFrom(childGetter.getReturnType())){
        		continue;
        	}
        	Class childClass = getReflector().getChildModelClass(childGetter);
        	Path childPath = new Path(getPath().getTarget()+"/"+Database.getInstance().getTable(childClass).getTableName().toLowerCase());
        	childPath.setRequest(getPath().getRequest());
        	childPath.setResponse(getPath().getResponse());
        	childPath.setSession(getPath().getSession());
        	if (childPath.canAccessControllerAction()){
            	List<Model> children;
    			try {
    				children = (List<Model>)childGetter.invoke(getRecord());
    			} catch (Exception e) {
    				throw new RuntimeException(e);
    			}
            	b.addControl(new LineBreak());
{'fraction_non_alphanumeric': 0.12050618349151568, 'fraction_numerical': 0.0, 'mean_word_length': 3.2004830917874396, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4890250', 'n_tokens_mistral': 1052, 'n_tokens_neox': 1051, 'n_words': 217}