Friday 11 December 2009

Accessing the symfony development environment

No later than this morning was I trying to use my symfony dev environment from a different PC on the network, and came across the following error:

You are not allowed to access this file. Check xxxxx_dev.php for more information.

Well, to every simple problem it seems there is a simple solution :).

Just open xxxxx_dev.php and add the relevant IP address to the array as follows:


if (!in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', '192.168.254.102', '::1')))
{
die('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}


Obviously you probably wouldn't want to do this on a public server but it's neat for LAN use all the same and I am just literally more and more impressed with all the inbuilt mechanisms that symfony has to offer!

Thoughts?

Saturday 5 December 2009

JTable in JScrollPane showing default column names

Well, back to the basics of Java...

Just in case anybody (that's including me ;-)) gets this problem (again) here is the solution.

Basic scenario: building a JTable with a non default model class extending AbstractTableModel as follows. I have omitted necessary includes and actually removed method bodies for simplification purposes.

Spot the error...


public class SyncOperationTableModel extends AbstractTableModel
{
// attributes

public SyncOperationTableModel(ArrayList syncOperations)
{
super();
// initialize attributes
}

public int getRowCount()
{
// return the row count based on attributes (for instance)
}

public int getColumnCount()
{
// return column count base on attributes (for instance)
}

public String getColumName(int column)
{
// return column name
}

public Object getValueAt(int row, int column)
{
// return the value,
// by default setValueAt is not necessary
// (AbstractTableModel returns false to isCellEditable method)
}

}



Symptom? The column names (getColumName(int column)) never get returned and are replaced with default names: A, B, C... At first sight this is strange, since I purposefully add the table to a JScrollPane (which should handle the table header automatically).

Solution? In the above code the getColumnName(int column) does not get called simply because I have created a new method named getColumName (i.e. with a missing 'n' to the 'column' part of the name). Stu-pid!

New method:


@Override
public String getColumnName(int column)
{
// code
}


Reaaaaally hopeless... no wonder this was impossible to find despite GIYF. Now getting on to cell rendering - it's been a while... other silly mistakes ahead I am sure.

More news soon.

Thoughts in the meantime?
Online Marketing
Add blog to our blog directory blog search directory Blog Directory Blogarama - The Blog Directory