sexta-feira, 27 de agosto de 2010

Mostrar tags HTML no seu blog ou site

Se você escrever alguma tag HTML no seu blog ou site ela não vai aparecer, ao invés disso será renderizado o elemento correspondente. Existem algumas técnicas para se fazer essa budega visível. Uma delas é colocar o código dentro de uma textarea:



Bom ai é só usar uma folha de estilo para deixar bonitinho e tudo certo. Garimpando na net é possível encontrar alguns scripts para fazer isso, mas eu prefiro as soluções simples e leves. Uma outra maneira é substituir as letras < e > pelos códigos & l t ; e & g t ;, retirando os espaços claro.

<p>Viu? Assim, oh!</p>

Como substituir tudo é um pouco penoso tem esse Encode/Decode basta por o código la e clicar em encode que um novo código será gerado automaticamente. Existem quem escreva num editor e tire uma screen para depois postar, mas é meio trabalhoso demais. Já para quem usa Windows Live Writter é mais simples ainda, basta digitar que ele encoda sem precisar fazer nada.

Se você escrever alguma tag HTML no seu blog ou site ela não vai aparecer, ao invés disso será renderizado o elemento correspondente. Existem algumas técnicas para se fazer essa budega visível. Uma delas é colocar o código dentro de uma textarea:



Bom ai é só usar uma folha de estilo para deixar bonitinho e tudo certo. Garimpando na net é possível encontrar alguns scripts para fazer isso, mas eu prefiro as soluções simples e leves. Uma outra maneira é substituir as letras < e > pelos códigos & l t ; e & g t ;, retirando os espaços claro.

<p>Viu? Assim, oh!</p>

Como substituir tudo é um pouco penoso tem esse Encode/Decode basta por o código la e clicar em encode que um novo código será gerado automaticamente. Existem quem escreva num editor e tire uma screen para depois postar, mas é meio trabalhoso demais. Já para quem usa Windows Live Writter é mais simples ainda, basta digitar que ele encoda sem precisar fazer nada.

Popup no commandLink

Pessoal ....

Um jeito facil de chamar relatorios em pdf .. sei la ... alguma coisa assim dentro de uma popup 8-)

Precisei disso esses dias ... consegui fazer e estou passando p vcs !!

<h:commandlink action="stringDaAction" value="#{msg['labeldocommandlink']}" onclick="javascript:window.open('','stringDaAction','height=600px,width=850px,toolbar=no,scrollbars=yes,resizable=no,menubar=no')" target="stringDaAction"/>

Bjunda !

sexta-feira, 20 de agosto de 2010

Trabalhando com ExtendedDataTable e DataProvider

Bom pessoal .. estava trabalhando num projeto novo e me deparei com um problema do cão .. "ExtendedDataTable" ... parece bom mas da um trabalho .... JESUSSSSSSSs .. mas blz ... tive q fazer ai umas POGs para funcionar .. mas ta blz .. estou passando o conhecimento para quem precisa ai ... vai um exemplo de como implementar o tal do DataProvider .... VLW q q coisa avisem !!
 public abstract class CustomDataProvider implements DataProvider{  
  private static final long serialVersionUID = 4469974447038357692L;  
  public List dados;  
  public CustomDataProvider(List dados) {  
  this.setDados(dados);  
  }  
  public T getItemByKey(Object arg0) {  
  for (Object c : this.getDados()) {  
   if (arg0.equals(getKey((T)c))) {  
   return (T) c;  
   }  
  }  
  return null;  
  }  
  public abstract Object getKey(T arg0);  
  public List getItemsByRange(int arg0, int arg1) {  
  return getDados().subList(arg0, arg1);  
  }  
  public int getRowCount() {  
  return getDados().size();  
  }  
  public List getDados() {  
  return dados;  
  }  
  private void setDados(List dados) {  
  this.dados = dados;  
  }  
 }  
}

Modo de usar : Bater 2 ovos com aveia de manha ... ops ...  errei ...

  XXXXX = new ExtendedTableDataModel(  
   new CustomDataProvider(dsItens){  
    public Object getKey(TipoObjetoDaLista item) {  
    return item.getCodCliente(); // Exemplo !  
    }  
   });  

segunda-feira, 16 de agosto de 2010

Resetar senha e usuário do SVN (Usando TortoiseSVN)

1) No Windows Explorer clicar no botão direito.

2) Clicar em TortoiseSvn.

3) Clicar em Settings.

4) Clicar em Saved Data.

5) Clicar clear na opção Authentication Data.

(Fonte www.guj.com.br)

Operações com arquivos

 import java.io.File;  
 import java.io.FileInputStream;  
 import java.io.IOException;  
 import java.io.OutputStream;  
 import javax.faces.context.ExternalContext;  
 import javax.faces.context.FacesContext;  
 import javax.servlet.http.HttpServletResponse;  
 public class OperacoesArquivos {  
   public static synchronized void downloadFile(String filename, String fileLocation, String mimeType,  
                          FacesContext facesContext) {  
     String path = fileLocation; // Localizacao do arquivo  
     String fullFileName = path + filename;  
     File file = new File(path); // Objeto arquivo mesmo :)  
     OperacoesArquivos.downloadFile(filename, file, facesContext, mimeType);  
   }  
   public static synchronized void downloadFile(String filename,File arquivo,FacesContext facesContext,String mimeType){  
     ExternalContext context = facesContext.getExternalContext(); // Context  
     HttpServletResponse response = (HttpServletResponse) context.getResponse();  
     try {  
       FileInputStream in = new FileInputStream(arquivo);  
       OutputStream out = response.getOutputStream();  
       byte[] buf = new byte[(int)arquivo.length()];  
       if (buf.length > 0){       
         int count;       
         while ((count = in.read(buf)) >= 0) {  
           out.write(buf, 0, count);  
         }  
       }  
       in.close();  
       out.flush();  
       out.close();  
       facesContext.responseComplete();  
     } catch (IOException ex) {  
       System.out.println("Error in downloadFile: " + ex.getMessage());  
       ex.printStackTrace();  
     }  
     response.setHeader("Content-Disposition", "attachment;filename=\"" + filename + "\""); //aki eu seto o header e o nome q vai aparecer na hr do donwload  
     response.setContentLength((int) arquivo.length()); // O tamanho do arquivo  
     response.setContentType(mimeType); // e obviamente o tipo  
   }  
 }  

JSFUtil Utilitario para manipular paginas em jsf

Bom pessoal .. deps de um LONGO tempo sem mexer em jsf .. estou voltando à ativa no jsf... mtas novidades mas .. não posso deixar de usar as coisas q eu ja implementei .. então la vai um utilitário para manipular jsf .. Abraços


 import java.util.Map;  
 import javax.faces.FactoryFinder;  
 import javax.faces.application.Application;  
 import javax.faces.application.ApplicationFactory;  
 import javax.faces.application.FacesMessage;  
 import javax.faces.context.ExternalContext;  
 import javax.faces.context.FacesContext;  
 import javax.faces.el.ValueBinding;  
 import javax.faces.webapp.UIComponentTag;  
 import javax.servlet.ServletContext;  
 import javax.servlet.http.HttpServletRequest;  
 import javax.servlet.http.HttpServletResponse;  
 import javax.servlet.http.HttpSession;  
 /**  
  *  
  * @author Caio Paulucci  
  */  
 public class JSFHelper {  
   public static ExternalContext getExternalContext() {  
     FacesContext facesContext = FacesContext.getCurrentInstance();  
     return facesContext.getExternalContext();  
   }  
   public static String getRequestParameter(String parameterName) {  
     Map paramMap = getExternalContext().getRequestParameterMap();  
     return (String) paramMap.get(parameterName);  
   }  
   public static Object getRequestAttribute(String attributeName) {  
     Map attrMap = getExternalContext().getRequestMap();  
     return attrMap.get(attributeName);  
   }  
   public static Object getSessionAttribute(String attributeName) {  
     Map attrMap = getExternalContext().getSessionMap();  
     return attrMap.get(attributeName);  
   }  
   public static void setSessionAttribute(String attributeName, Object attribute) {  
     Map attrMap = getExternalContext().getSessionMap();  
     attrMap.put(attributeName, attribute);  
   }  
   public static Object getApplicationAttribute(String attributeName) {  
     Map attrMap = getExternalContext().getApplicationMap();  
     return attrMap.get(attributeName);  
   }  
   public static void addGlobalMessage(String message) {  
     FacesMessage facesMessage = new FacesMessage(message);  
     FacesContext.getCurrentInstance().addMessage(null, facesMessage);  
   }  
   public static FacesContext getFacesContext(){  
     return FacesContext.getCurrentInstance();  
   }  
   /**  
    * Get servlet context.  
    *  
    * @return the servlet context  
    */  
   public static ServletContext getServletContext() {  
     return (ServletContext) FacesContext.getCurrentInstance()  
                       .getExternalContext().getContext();  
   }  
   /**  
    * Get managed bean based on the bean name.  
    *  
    * @param beanName the bean name  
    * @return the managed bean associated with the bean name  
    */  
   public static Object getManagedBean(String beanName) {  
     Object o =  
       getValueBinding(getJsfEl(beanName)).getValue(FacesContext.getCurrentInstance());  
     return o;  
   }  
   /**  
    * Remove the managed bean based on the bean name.  
    *  
    * @param beanName the bean name of the managed bean to be removed  
    */  
   public static void resetManagedBean(String beanName) {  
     getValueBinding(getJsfEl(beanName)).setValue(FacesContext.getCurrentInstance(),  
                            null);  
   }  
   /**  
    * Store the managed bean inside the session scope.  
    *  
    * @param beanName the name of the managed bean to be stored  
    * @param managedBean the managed bean to be stored  
    */  
   @SuppressWarnings("unchecked")  
  public static void setManagedBeanInSession(String beanName,  
                         Object managedBean) {  
     FacesContext.getCurrentInstance().getExternalContext().getSessionMap()  
           .put(beanName, managedBean);  
   }  
   /**  
    * Get parameter value from request scope.  
    *  
    * @param name the name of the parameter  
    * @return the parameter value  
    */  
   public static Map getRequestParameters() {  
     return FacesContext.getCurrentInstance().getExternalContext()  
                   .getRequestParameterMap();  
   }  
   /**  
    * Add information message.  
    *  
    * @param msg the information message  
    */  
   public static void addInfoMessage(String msg) {  
     addInfoMessage(null, msg);  
   }  
   /**  
    * Add information message to a sepcific client.  
    *  
    * @param clientId the client id  
    * @param msg the information message  
    */  
   public static void addInfoMessage(String clientId, String msg) {  
     FacesContext.getCurrentInstance().addMessage(clientId,  
                            new FacesMessage(FacesMessage.SEVERITY_INFO,  
                                    msg, msg));  
   }  
   /**  
    * Add error message.  
    *  
    * @param msg the error message  
    */  
   public static void addErrorMessage(String msg) {  
     addErrorMessage(null, msg);  
   }  
   /**  
    * Add error message to a sepcific client.  
    *  
    * @param clientId the client id  
    * @param msg the error message  
    */  
   public static void addErrorMessage(String clientId, String msg) {  
     FacesContext.getCurrentInstance().addMessage(clientId,  
                            new FacesMessage(FacesMessage.SEVERITY_ERROR,  
                                    msg, msg));  
   }  
   /**  
    * Evaluate the integer value of a JSF expression.  
    *  
    * @param el the JSF expression  
    * @return the integer value associated with the JSF expression  
    */  
   public static Integer evalInt(String el) {  
     if (el == null) {  
       return null;  
     }  
     if (UIComponentTag.isValueReference(el)) {  
       Object value = getElValue(el);  
       if (value == null) {  
         return null;  
       } else if (value instanceof Integer) {  
         return (Integer) value;  
       } else {  
         return new Integer(value.toString());  
       }  
     } else {  
       return new Integer(el);  
     }  
   }  
   private static Application getApplication() {  
     ApplicationFactory appFactory =  
       (ApplicationFactory) FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);  
     return appFactory.getApplication();  
   }  
   private static ValueBinding getValueBinding(String el) {  
     return getApplication().createValueBinding(el);  
   }  
   public static HttpServletRequest getRequest() {  
     return (HttpServletRequest) FacesContext.getCurrentInstance()  
                         .getExternalContext()  
                         .getRequest();  
   }  
   public static HttpServletResponse getResponse() {  
     return (HttpServletResponse) FacesContext.getCurrentInstance()  
                         .getExternalContext()  
                         .getResponse();  
   }  
   public static HttpSession getSession() {  
     return (HttpSession) FacesContext.getCurrentInstance()  
                         .getExternalContext()  
                         .getSession(false);  
   }  
   private static Object getElValue(String el) {  
     return getValueBinding(el).getValue(FacesContext.getCurrentInstance());  
   }  
   private static String getJsfEl(String value) {  
     return "#{" + value + "}";  
   }  
 }  

Missing Built-in Tag Libraries! Make sure they are included within the META-INF directory of Facelets' Jar

O Q FAZER JESUSSSSSSSSSS !!!

Easy ... baixar a versão mais recente do Facelets ! ... BABA !

Downloads : https://facelets.dev.java.net/servlets/ProjectDocumentList?folderID=3635&expandFolder=3635&folderID=0  

VLW PESSOAL !

Subir duas instancias no JBoss

 - Copiar o diretorio "default" para o nome da instancia desejada no caso : defaultnomeinstancia1 e defaultnomeinstancia2

--------------------- 1 Instancia -----------------------------------
1 - Edite o arquivo $JBOSS_HOME\server\defaultnomeinstancia1\conf\bindingservice.beans\META-INF\bindings-jboss-beans.xml
---------------------------------------------------------------------

--------------------- 2 Instancia -----------------------------------
2 - Edite o arquivo $JBOSS_HOME\server\defaultnomeinstancia2\conf\bindingservice.beans\META-INF\bindings-jboss-beans.xml
---------------------------------------------------------------------

* - No arquivo bindings-jboss-beans.xml já existe 3 conjuntos diferentes de
 portas ()
 pré-configurados (ports-default, ports-01, ports-02).


  Caso necessario *- Mudar o parametro : ${jboss.service.binding.set:ports-xx} para o ports que sera usado na configuração.
Caso necessario *- Tirar o das instancias q não serão usadas na configuração.

3 - Execute cada uma das instâncias com os comandos:
      "./run.sh -c default"
      "./run.sh -c defaultnomeinstancia"

Nota :

Uma instancia no local host
bin/run.sh --host=localhost -c=testes

Outra no servidor principal
bin/run.sh --host=ipdoservidor -c=defaultnomeinstancia

Você pode configurar ips virtuais em seu servidor e usar:
bin/run.sh --host=ip_1_doservidor --c=defaultnomeinstancia1
bin/run.sh --host=ip_2_doservidor --c=defaultnomeinstancia2
bin/run.sh --host=ip_3_doservidor --c=defaultnomeinstancia3
bin/run.sh --host=ip_4_doservidor --c=defaultnomeinstancia4

Nota 2 : Mesmo Ip c instancias diferentes :
bin/run.bat -b 0.0.0.0 -c defaultnomeinstancia1 -Djboss.service.binding.set=ports-01

OBS:

O Acesso :
default  - >http://127.0.0.1:8080/XXXXX/
ports-01 - >http://127.0.0.1:8180/XXXXX/
ports-02 - >http://127.0.0.1:8280/XXXXX/
ports-03 - >http://127.0.0.1:8380/XXXXX/

By GHZATOMIC