Thursday, May 21, 2009

OAS JVM settings

OAS_HOME/j2ee/oc4j_opmn.xml hasJVM settings for OAS.

OAS configuration

We have a VM host1 which installs OAS. Then it is replicated as host2. To start OAS on host2, we need to change some configuration.
  1. Make sure the host name is host2 with "ipconfig /all".
  2. Change the host name to new one in OAS_HOME/config/ias.properties, OAS_HOME/opmn/conf/opmn.xml
Now start OAS and try login to http://host2/em. If you are redirected to http://host1/em, it is probably OAS thinks this is a cluster installation. You will get the error message said
"You have been logged off and redirected to the canonical server name."
In this case, you need to change OAS_HOME/Apache/Apache/conf/httpd.conf and set
UseCanonicalName Off

Tuesday, May 19, 2009

Spring mvc bind select

Here is an example to use spring:bind to bind HTML select. Note the hidden input at the end is very important to spring bind.


<spring:bind path="labelChanges.details">
<select id="detailFilter" name="${status.expression}" multiple="multiple" class="searchFilter">
<c:forEach var="item" items="${labelChangeMitigationDetails}">
<c:forEach items="${status.value}" var="currentItem">
<c:if test="${currentItem == item.value}">
<c:set var="selected" value="true"/>
</c:if>
</c:forEach>

<option value="${item.value}"
<c:if test="${selected}">selected="selected"</c:if>>
<c:out value="${item.key}" />
</option>

<c:remove var="selected"/>
</c:forEach>
</select>
</spring:bind>
<input type="hidden" name="_details" value="1"/>


Another options is to use form:select


<form:select id="statusFilter" cssClass="searchFilter"
path="statuses"
items="${labelChangeStatuses}"
itemValue="lcStatusRefSeq"
itemLabel="lcStatusName"
multiple="true" />
</td>

Friday, May 15, 2009

How to further filter "this" in jquery?

Suppose this is the HTML.

You can use $('div') to get it. You can refer to it by "this". What if you want to get "img"? How do you apply selector on "this"?

The jQuery constructor accepts a 2nd parameter which can be used to override the context of the selection.
$("img", this);

Wednesday, May 13, 2009

form submission url

When you load the form, the url is "myaction.htm?id=123". You want to keep the url when the form is submitted. All you need to do is to define form action as "action=myaction.htm?id=123". Note that you cannot have another "id" field in the form. If you use Spring bind, it might lead to binding errors.

Return ModelAndView in Spring mvc onSubmit()

You need to return ModelAndView In Spring's SimpleFormController onSubmit() method. There are a few options here.

1. Redirect to another page
return new ModelAndView(new RedirectView("anotherPage.htm");

2. Return to the same form
return new ModelAndView(getSuccessView());

As long as you return "new" ModelAndView, you will have to go through formBackingObject() method.

3. Return to the same form but bypass formBackingObject() method
return showForm(request, errors, getSuccessView());
showForm() method calls and carries all reference data.


Tuesday, May 12, 2009

jquery starts with selector

"^=" is the operator for "starts with" in jquery. For example, the following finds all inputs whose names starts with "abc".

$("input:[name^='abc']")


Find all checked checkbox input with the css class name "non-draft=status"

$('input:checkbox.non-draft-status:checked')

Find all of td's children whose class is "data4Sort". Note children() only gives you the immediate children while find() goes deeper.

$('td').find('.data4Sort')

Spring bind collection to checkbox

Here is an example in JSP to bind a collection as checkboxes with spring form:checkbox.

<c:forEach varStatus="status" var="product" items="${command.products}">
<form:checkbox path="products[${status.index}].productId" value="${product.id}" />
</c:foreach>

Note the command will always have the collection "products". However, the selected ones - the ones with checkbox checked, will have valid "id" values. This is the way to tell which ones are selected.

Friday, May 8, 2009

Customize Hibernate Mapping Strategy

You can use Hibernate reverse engineering tools to create mapping files and Java classes. However, the default mapping may not always fit your need. For example, it maps table primary key to BigDecimal and uses "assigned" generator. You can add customization in hibernate.reveng.xml to change that. Here is an example of how to map PK to Integer with sequence generator. You can also define "type-mapping" for global type mappings.

Tuesday, May 5, 2009

Hql with collections and named parameters

An example of how you can use hql to query collections and names parameters. The bold part is for collections. The find() method is from Spring HibernateTemplate.

String query = "select cp from CaseProduct cp, LcLabelChange lc "
+ " where cp.puid=? "
+ " and lc member of cp.labelChanges "
+ " and lc.lcMitigation.caseIngredient.caseIngredientSeq=?";
Object[] params = new Object[]{puid, caseIngredientId};
List list = find(query, params);

Hibernate mapping for trigger populated columns

Suppose you have table columns whose values are populated by triggers. For example, createdBy, updatedBy, createdDate, & updatedDate. The following Hibernate mapping indicates that these columns are managed by database. The mapping is also "trigger friendly" - Hibernate will retrieve the values automatically. There is no need for an extra explicit SELECT.