Medir tiempo de ejecución de un método en java


public static void main(String[] args)
{
long tiempoInicio = System.currentTimeMillis();
ejecutarProceso(); // aqui se llama al método al cual se le quiere calcular el tiempo de ejecución
long totalTiempo = System.currentTimeMillis() - tiempoInicio;
System.out.println("El tiempo del proceso total es :" + totalTiempo + " miliseg");
}

By Miguel Ruiz on miércoles, 15 de diciembre de 2010 | | A comment?

Obtener contenido de una web por java

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;


public class Test {
public static void main(String[] args) throws Exception {
URL u = new URL("https://forja.rediris.es/");
URLConnection conn = u.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(
conn.getInputStream()));
String inputLine;

while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
}
}

By Miguel Ruiz on martes, 14 de diciembre de 2010 | | A comment?

Vertical < hr > (Linea vertical)

Una linea en horizontal se hace con < hr >, pero para hacer una linea en vertical se puede usar:

< style="display:inline;border-collapse:collapse;border:0"><><>< style="padding:0">< src="http://www.blogger.com/transparent.gif" width="2" height="600" style="background:black">
< /td>< /tr>< /tbody>< /table>

By Miguel Ruiz on lunes, 22 de noviembre de 2010 | A comment?

Validar un input en JSF

Este es un ejemplo de como validar que un email es correcto. Aunque sólo se mira si se ha escrito el símbolo @, se pueden utilizar también expresiones regulares.

En la página xhtml o jspx:


< div id="loginForm">
< h:form id="registerInput">
< h:panelGrid width="375px" bgcolor="#e6edfd" columns="2" border="0">
< h:commandLink action="#{usuario.haceClickEnLogin}">Login/Registro< /h:commandLink>
< /h:panelGrid>
< h:message id="errorEmail" for="error" errorStyle="color:red"/ >
< /h:form>
< /div>



En el BackBean (Sabiendo que tenemos un atributo String email; con su get y set):

public void validaEmail(FacesContext context,
UIComponent toValidate,
Object value) {
String emailIntroducido = (String) value;

if (!emailIntroducido.contains("@")) {
FacesMessage message = new FacesMessage();

message.setSeverity(FacesMessage.SEVERITY_ERROR);
message.setSummary("Email no valido");
message.setDetail("Email no valido");
context.addMessage("registerInput:error", message);
}

}

By Miguel Ruiz on sábado, 6 de noviembre de 2010 | | A comment?

Mandar parámetros por JSF

Ejemplo de cómo mandar parámetros de un JSF (xhtml) a un BackBean:



En la página xhtml o jspx:

< h:commandLink actionListener="#{inventoryList.filtrar}" >
< f:attribute name="filtro" value="#{inventoryList.filtro}"/>
< span>Filtrar< /span>
< /h:commandLink>

En el back bean (invertoryList):

public void filtrar(ActionEvent event) {
String filtro = (String) event.getComponent().getAttributes().get("filtro");
}

By Miguel Ruiz | | A comment?