27 septiembre 2009

Deploying custom resources

creamos un nuevo action:

public void action1_(){
ResourceBundle bundle = SeamResourceBundle.getBundle();
String sql = bundle.getString("sql1");

log.info("sql: " + sql);
statusMessages.add("sql: " + sql);
}

y ponemos el sql.properties en el directorio src/hot:

sql1=select h from Hotel h where h.name like '%#{exampleHotel.name}%'







from http://seamframework.org/Community/IncludingAResourceBundleNotCalledMessages


<core:resource-loader>
<core:bundle-names>
<value>mycompany_messages</value>
</core:bundle-names>
</core:resource-loader>




from seam reference 2.1.1-GA.pdf


29.10. Deploying custom resources (externalizar SQL's)


Se trata de crear un componente que se cargue en el arranque de la aplicación, y contenga un set de properties con las sql's de la aplicación, y que se pueda desplegar en caliente por si se actualiza el fichero de properties.

21 septiembre 2009

24.2.1. Using the Hibernate API

24.2.1. Using the Hibernate API

To use the Hibernate API to manage the database objects, we inject a Hibernate Session in-
stead of an EntityManager into the ManagerPojo class. The API methods in the Hibernate
Session is roughly equivalent to methods in the EntityManager; they have only slightly dif-
ferent method names. This is the Hibernate version of the ManagerPojo class:

@Name("manager")
@Scope (APPLICATION)
public class ManagerPojo {
@In (required=false) @Out (required=false)
private Person person;
@In (create=true)
private Session helloSession;
Long pid;
@DataModel
private List fans;
@DataModelSelection
private Person selectedFan;
public String sayHello () {
helloSession.save (person);
return "fans";
}
@Factory("fans")
public void findFans () {
fans = helloSession.createQuery(
"select p from Person p")
.list();
}
public void setPid (Long pid) {
this.pid = pid;
if (pid != null) {
person = (Person)
helloSession.get(Person.class, pid);
} else {
person = new Person ();
}
}
public Long getPid () {
return pid;
}
public String delete () {
Person toDelete =
(Person) helloSession.merge (selectedFan);
helloSession.delete( toDelete );
findFans ();
return null;
}
public String update () {
return "fans";
}
}

Display Error Messages on the Web Form

10.4. Display Error Messages on the Web Form



s:decorate>
f:facet name="beforeInvalidField">
h:graphicimage src="anotherError.gif">
/h:graphicimage>
f:facet name="afterInvalidField">
s:message styleclass="anotherError">
/s:message>
f:facet name="aroundInvalidField">
s:span styleclass="error">
/s:span>
h:inputtext value="#{person.name}">
/h:inputtext>/f:facet>/f:facet>/f:facet>/s:decorate>

exception management in pages.xml

14.4., “Use pages.xml for System
Exceptions”



from booking example:



pages.xml


You must be logged in to use this feature





Session expired, please log in again

Annotate exceptios

From the book 'JBoss Seam Simplicity and Power Beyond Java EE':

14.3 Annotate Exceptions

@ApplicationException(rollback=true)
@Redirect(viewId="/inventoryError.xhtml")
public class InventoryException
extends Exception {
public InventoryException () { }
}
14.4. Use pages.xml for System Exceptions

SVN hooks for hudson builds

En el directorio hooks del repositorio renombramos/copiamos post-commit.bat (o .exe)

en el fichero post-commit.bat escribimos:

python C:\svnrepos\notify_hudson.py




escribir este script en un fichero llamado notify_hudson.py:


import urllib, urllib2, time

url = 'http://localhost:8080/hudson/job/seam4hudson/build?token=build&cause=svncommit+texto'

values = {'token' : 'build', #write ur specific key/value pair
'key2' : 'value2',
'key3' : 'value3',
}

try:
# data = urllib.urlencode(values)
req = urllib2.Request(url)
response = urllib2.urlopen(req)
the_page = response.read()
print the_page
except Exception, detail:
print "Err ", detail




script sacado de http://love-python.blogspot.com/2008/04/get-content-html-source-of-url-by-http.html