It's my blog!

Multiple COUNT select from same table

I fixed the issue in this way:

SELECT R.id_request,
    (SELECT COUNT(*) FROM Flow F 
        WHERE F.id_request = R.id_request AND processStatus = 1) AS flowTotal,
    (SELECT COUNT(*) FROM Flow F 
        WHERE F.id_request = R.id_request AND processStatus = 2) AS flowApproved
FROM Request R

Dynamic for with Spring MVC using a HashMap

Sometime you need to dynamically generate a form without knowing how many fields it will be required (i.e. when your form is driven by a configuration or by some properties). The problem is to draw the form and, return the values to the Controller, and recognize the couples Field name / Field value after the submit..

You can easily get solve this problem just adding HashMap which will hold the key-value pair data to the DataModel.

Supposing your configuration says: you have to draw two fields and these are the name, you UI will be something like*:

<c:forEach items="${newRequest.fields}" var="field">
	<f:input type="text" path="rawFields['${field.field_id}']" class="form-control validate[groupRequired[mandatoryField]]" /> (R)
</c:forEach>

When you submit the form, the values and the key for the dynamic fields will be filled.

* newRequest is the DataModel you are passing and fields is the list of Fields that user will fill with data, like that:

public class Request {
 
	/** Request type */
	private int templateRequest;
 
	// ***** Input field ***** 
	List<RequestField> fields = new ArrayList<RequestField>();
 
	private HashMap<String, Object> rawFields = new HashMap<String, Object>();
 
	[Setters and getters]
 
}

Apply jQuery datepicker to multiple instances

To add multiple instance of jQuery datepicker (or timepicker), it is possible to use class instead of the ID to initialize the widget in particular when the form is generated from the backend and the exact number of field is not known.

The html code will be:

<input type="text" class="datepicker" id="date1" />
<input type="text" class="datepicker" id="date2" />
<input type="text" class="datepicker" id="date3" />

The jQuery script will be:

$('.datepicker').each(function(){
    $(this).datepicker();
});

Remember to include jquery and jquery-ui scripts to the page.

Leadership

The milestone of the leadership: Feb 5, 1995

Feb 5, 1995

Disaster recovery

A disaster recovery plan (DRP) is a documented process or set of procedures to recover and protect a business IT infrastructure in the event of a disaster.

l

Background

What do you actually mean with “Unfortunately, your background isn’t exactly what our client is looking for at this time”? It’s IT not old style industry!

On the Nature of Software

I never think about this:

Software is remarkable stuff. Sometimes, perhaps because we work with it all the time, we forget just how remarkable it is.
Very little else in human experience is as malleable, allowing us free rein to exercise our ingenuity and inventiveness almost without limits. Also, with a very few exceptions that we’ll cover later, software is deterministic—the next state is completely determined by the current state, and (crucially) we have com- plete access to all of that state whenever we want it.
Compared to traditional engineering, we are spoiled. What do you think a Formula One engineer would give to be able to instantaneously stop an engine when it’s rotating at 19,000 revolutions per minute and examine every aspect of it in minute detail? To see the precise state of each component while under pressure and stress, for example, or to dynamically record the shape and position of the flame front within the combustion chambers during ignition?
It is exactly this kind of trick that we are able to perform with our software, which is why the empirical approach is particularly powerful when debugging. [from book Debug It!]

« Older posts

Copyright © 2014 It's my blog!

Theme by Anders NorenUp ↑