Showing posts from January, 2010

Using a NavigiationHandler to do HTTP/HTTPS switching

In a project I was working on, we wanted the log in page and anything to do with payment to be secure using HTTPS, whilst the majority of the site would be unsecure using HTTP. JSF 1.2 doesn't really give you anyway of doing this other than manually specifying the full url for every single link and button on the site. This removes a lot of the flexibility and simplicity of JSF. I came up with a pretty good solution. For any link or action that you know will switch between secure and unsecure, which isn't that hard to know (if you design the site with that in mind), then you configure it to be a redirect. Then you create your own navigation handler which applies rules you create yourself, to determine which parts should be secure or not.

This is a very simple solution that when a redirect occurs, it checks the path of the destination page (its viewId). If it starts with "/secure" it gives a full HTTPS url and for all others, it gives a full HTTP url. To activate it, h…

Updating the nextval of all sequences in PostgreSQL

If you've been doing SQL level inserts for testing purposes, then when you go to use the sequences then they will have a nextval that already exists in your table.

So below is a script which updates the nextval for all fields that were created using bigserial/serial:
/* Updates all the sequences to have a next value of max+1 excluding the list passed */ CREATE OR REPLACE FUNCTION fn_fixsequences(excludes text) RETURNS integer AS $BODY$ DECLARE themax BIGINT; mytables RECORD; num integer; BEGIN num := 0; FOR mytables IN select relname, ns.nspname, a.attname, pg_get_serial_sequence(c.relname, a.attname) as seq FROM pg_catalog.pg_attribute a INNER JOIN pg_catalog.pg_class c ON c.oid=a.attrelid inner join pg_catalog.pg_attrdef d on d.adrelid = a.attrelid AND d.adnum = a.attnum AND a.atthasdef LEFT JOIN pg_catalog.pg_namespace ns ON ns.oid = c.relnamespace WHERE pg_catalog.pg_table_is_visible(c.oid) and a.attnum > 0 AND NOT a.attisdropped and attt…

Getting JBoss Scheduler working

When using the @Service annotation together with the scheduler has given me no end of trouble so I'd like to share my working configuration.

It took me a while to get the objectName right. If your not using @Service(objectName='name') but instead using @Service(name='name') then the final object name is not the same as what they imply at EJB Extensions Help.
Instead I'd recommend going into the JMX console of the running server and searching for it manually, listed under 'jboss.j2ee' for the name you've specified AND type=ManagementInterface.

As well as defining the @Service, you'll also need to define the @Management.

@Management(SampleServiceMBean.class) @Service(name = SampleServiceMBean.SERVICE_NAME) public class SampleServiceMBean implements SampleService { public final static String SERVICE_NAME = "SampleServiceMBean"; public void process(ObjectName name, Date date) {"process {} {}", name, date); }

Disabling RichFaces FacesBeanValidator

If you use the rich:ajaxValidator, for example:
<rich:ajaxValidator event="onblur" /> It automatically adds a FacesBeanValidator to the components list of validators. If you don't have javax.validation or Hibernate Validator setup then you'll get the following exception:
2010-01-07 00:29:19,889 [http-8443-1] WARN org.richfaces.validator.ObjectValidator - Hibernate Validator could not be instantiated, use stub instead javax.validation.ValidationException: Unable to find a default provider at javax.validation.Validation$GenericBootstrapImpl.configure( at javax.validation.Validation.buildDefaultValidatorFactory( at org.richfaces.validator.BeanValidator.( at org.richfaces.validator.ObjectValidator.createInstance( at org.richfaces.validator.ObjectValidator.getInstance( at org.richfaces.validator.FacesBeanValidator.validate( …