Mr.style 8 de nov. de 2011
finotti 8 de nov. de 2011
Vc deve criar a classe ViewScope e declará-la no applicationContext.
Aqui tem um exemplo
furacao123 8 de nov. de 2011
Não estou conseguindo encontrar nada nesse blog, nem traduzindo a pagina de turco para portugues…
xandi_m5 8 de nov. de 2011
Off-topic
Desculpa mais alguem poderia ver meu topico :
Preciso resolver esse problema urgente para poder continuar meu estudo.
furacao123 8 de nov. de 2011
Entao ja tentei implementar essa view do spring mas continuou a mesma coisa, acabei optando por deixar o JSF2 responsavel pelos MB atraves do @ManagedBean e o @ManagedProperty que faz a injecao dos services do Spring no meu MB, quando tentei utilizar o view ocorreu o mesmo problema de Serialize
finotti 8 de nov. de 2011
Nesse exemplo que passei o spring é “responsável” pelos managed beans. Talvez vc tenha que usar dessa forma pra funcionar junto com o Spring Security
furacao123 8 de nov. de 2011
Entao eu implementei dessa forma mas tb nao funcionou, segue o meu template...
< ?xml version=" 1.0" encoding=" ISO-8859-1" ?>
< !DOCTYPE html>
< html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.prime.com.tr/ui">
< h:head>
< ui:insert name="titulo">
< title> #{msg['aplicacao.titulo']}< /title>
< /ui:insert>
< ui:insert name="cabecalho">
< link href="${ facesContext . externalContext . requestContextPath } /style/jquery-ui-1.8.16.custom.css" type="text/css" rel="stylesheet" />
< link href="${ facesContext . externalContext . requestContextPath } /style/listaNFe.css" type="text/css" rel="stylesheet" />
< link href="${ facesContext . externalContext . requestContextPath } /style/listaEmpresa.css" type="text/css" rel="stylesheet" />
< link href="${ facesContext . externalContext . requestContextPath } /style/default.css" type="text/css" rel="stylesheet" />
< ui:insert name="javascript" />
< ui:insert name="css" />
< /ui:insert>
< /h:head>
< h:body>
< p:growl id="growlMessage" showDetail="true" />
< ui:insert name="body">
< h:form prependId="false">
< p:layout fullPage="true">
< p:layoutUnit position="top" height="52">
< p:panel id="pnlTopo" styleClass="topo">
< ui:insert name="login">
< ui:include src="usuarioLogado.xhtml"/>
< /ui:insert>
< /p:panel>
< /p:layoutUnit>
< p:layoutUnit position="center" closable="false">
< ui:insert name="menu"/>
<br/>
< p:outputPanel id="pnlCorpo">
< ui:insert name="corpo">
< ui:include src="#{menuController.menuSelected}"/>
< /ui:insert>
< /p:outputPanel>
< /p:layoutUnit>
< p:layoutUnit position="bottom" height="75">
< ui:include src="rodape.xhtml"/>
< /p:layoutUnit>
< /p:layout>
< /h:form>
< ui:include src="dialogAlterarSenha.xhtml" />
< p:outputPanel id="pnlDialog" rendered="#{menuController.hasDialog}">
< ui:insert name="dialog">
< ui:include src="#{menuController.dialogSelected}"/>
< /ui:insert>
< /p:outputPanel>
< /ui:insert>
< /h:body>
< /html>
MenuController
@ManagedBean ( name =& quot ; menuController & quot ;)
@SessionScoped
//@Component("menuController")
//@Scope("session")
public class MenuController implements Serializable {
private String menuSelected ;
private String dialogSelected ;
private boolean hasDialog ;
@PostConstruct
public void init () {
menuSelected = & quot ;.. / pages / nfe / listaNFe . xhtml & quot ;;
dialogSelected = & quot ;.. / pages / nfe / dialogNFe . xhtml & quot ;;
hasDialog = true ;
}
@PreDestroy
public void destroy () {
}
public void menuNFe ( ActionEvent event ) {
menuSelected = & quot ;.. / pages / nfe / listaNFe . xhtml & quot ;;
hasDialog = true ;
dialogSelected = & quot ;.. / pages / nfe / dialogNFe . xhtml & quot ;;
}
public void menuEmpresa ( ActionEvent event ) {
menuSelected = & quot ;.. / pages / empresa / listaEmpresa . xhtml & quot ;;
hasDialog = true ;
dialogSelected = & quot ;.. / pages / empresa / dialogEmpresa . xhtml & quot ;;
}
public void menuUsuario ( ActionEvent event ) {
menuSelected = & quot ;.. / pages / usuario / listaUsuario . xhtml & quot ;;
hasDialog = true ;
dialogSelected = & quot ;.. / pages / usuario / dlgUsuario . xhtml & quot ;;
}
public boolean getHasDialog () {
return hasDialog ;
}
public void setHasDialog ( boolean hasDialog ) {
this . hasDialog = hasDialog ;
}
public String getMenuSelected () {
return menuSelected ;
}
public String getDialogSelected () {
return dialogSelected ;
}
}
menu.xhtml
& lt ;? xml version =& quot ; 1 . 0 & quot ; encoding =& quot ; ISO-8859-1 & quot ;?& gt ;
& lt ;! DOCTYPE html & gt ;
& lt ; html xmlns = "http://www.w3.org/1999/xhtml"
xmlns : p = "http://primefaces.prime.com.tr/ui"
xmlns : sec = "http://www.springframework.org/security/facelets/tags"
xmlns : h = "http://java.sun.com/jsf/html" & gt ;
& lt ; p : menubar autoSubmenuDisplay = "true" & gt ;
& lt ; p : submenu label = "Cadastro" icon = "ui-icon ui-icon-pencil" & gt ;
& lt ; p : menuitem value = "Empresa" actionListener = "#{menuController.menuEmpresa}"
update = "pnlCorpo pnlDialog" icon = "ui-icon ui-icon-triangle-1-e" /& gt ;
& lt ;! -- & lt ; p : menuitem value = "Usuário" action = "/pages/usuario/corpoUsuario?faces-redirect=true"
ajax = "single" icon = "ui-icon ui-icon-triangle-1-e" /& gt ; -- & gt ;
& lt ; p : menuitem value = "Usuário" actionListener = "#{menuController.menuUsuario}"
update = "pnlCorpo pnlDialog" icon = "ui-icon ui-icon-triangle-1-e" /& gt ;
& lt ;/ p : submenu & gt ;
& lt ; p : menuitem value = "NFe" actionListener = "#{menuController.menuNFe}"
update = "pnlCorpo pnlDialog" icon = "ui-icon ui-icon-document" /& gt ;
& lt ; p : submenu label = "Configurações" icon = "ui-icon ui-icon-gear" & gt ;
& lt ;/ p : submenu & gt ;
& lt ; p : submenu label = "Ajuda" icon = "ui-icon ui-icon-help" & gt ;
& lt ;/ p : submenu & gt ;
& lt ; p : menuitem value = "Sair" action = "#{loginController.logout}" icon = "ui-icon ui-icon-close" /& gt ;
& lt ;/ p : menubar & gt ;
& lt ;/ html & gt ;
UsuarioController
@ ManagedBean ( name = "usuarioController" )
@ ViewScoped
//@Component("usuarioController")
//@Scope("session")
public class UsuarioController implements Serializable {
// <editor-fold defaultstate="collapsed" desc="Atributos">
@ ManagedProperty ( name = "usuarioService" , value = "#{usuarioService}" )
private UsuarioService usuarioService ;
private List & lt ; Usuario & gt ; usuarioList ;
private List & lt ; Role & gt ; roleList ;
private Usuario selectedUsuario ;
//</editor-fold>
// @Autowired
// public UsuarioController(UsuarioService usuarioService) {
// this.usuarioService = usuarioService;
// }
@ PostConstruct
public void init () {
setUsuarioList ( usuarioService . getByAtivo ( true ));
}
@ PreDestroy
public void destroy () {
}
// <editor-fold defaultstate="collapsed" desc="GET / SET">
public List & lt ; Role & gt ; getRoleList () {
return roleList ;
}
public void setRoleList ( List & lt ; Role & gt ; roleList ) {
this . roleList = roleList ;
}
public Usuario getSelectedUsuario () {
return selectedUsuario ;
}
public void setSelectedUsuario ( Usuario selectedUsuario ) {
this . selectedUsuario = selectedUsuario ;
}
public List & lt ; Usuario & gt ; getUsuarioList () {
return usuarioList ;
}
public void setUsuarioList ( List & lt ; Usuario & gt ; usuarioList ) {
this . usuarioList = usuarioList ;
}
public void setUsuarioService ( UsuarioService usuarioService ) {
this . usuarioService = usuarioService ;
}
//</editor-fold>
}
Acontece o seguinte quando inicio a aplicação carrega uma tabela, clico para visualizar um item da tabela e me mostra um dialog com os dados tudo ok, mas depois que faço isso navego no menu para o usuario por exxemplo, ele popula a tabela tudo certo mas quando clico em editar um registro da tabela me abre o dialog sem nenhum dado como se nao disparace o metodo setSelectedUsuario
furacao123 8 de nov. de 2011
Ja estou chegando a conclusao que o problema nao esta no scope e sim como estou manipulando os componentes do primefaces os updates no pnlCorpo e dialog, mas oq ue estou fazendo errado?
thiaguten 16 de set. de 2014
Olá furacao123,
não tenho certeza da solução e também talvez seja tarde demais para você, mas aqui vai uma possível solução que vi em um comentário feito pelo Rafael Pontes em um site americano dizendo o seguinte:
I think the best solution for @ViewScoped beans with Spring or even to avoid NotSerializableException is using the annotation @Scope(proxyMode=ScopedProxyMode.TARGET_CLASS, value="session") This way Spring will create a proxied bean which will call original every time a method is called.
Doing this you still can inject beans with a narrower scope into a broader one.
Site: http://www.beyondjava.net/blog/integrate-jsf-2-spring-3-nicely/
Site2: http://blog.primefaces.org/?p=702
Site3: https://jira.spring.io/browse/SPR-6543
alexfe 16 de set. de 2014
Vamos lá senhores contrua a seguinte classe
public class ViewScope implements Scope {
@SuppressWarnings ( "unchecked" )
public Object get ( String name , ObjectFactory objectFactory ) {
Map < String , Object > viewMap = FacesContext . getCurrentInstance (). getViewRoot (). getViewMap ();
if ( viewMap . containsKey ( name )) {
return viewMap . get ( name );
} else {
Object object = objectFactory . getObject ();
viewMap . put ( name , object );
return object ;
}
}
public Object remove ( String name ) {
return FacesContext . getCurrentInstance (). getViewRoot (). getViewMap (). remove ( name );
}
public String getConversationId () {
return null ;
}
public void registerDestructionCallback ( String name , Runnable callback ) {
//Not supported
}
public Object resolveContextualObject ( String key ) {
return null ;
}
}
Declare no spring
<bean class= "org.springframework.beans.factory.config.CustomScopeConfigurer" >
<property name= "scopes" >
<map>
<entry key= "view" >
<bean class= "br.com.exemplojsf2.web.util.ViewScope" />
</entry>
</map>
</property>
</bean>
Aqui está o pulo do gato vc tem que apontar o managed para o scopo de view controlado pelo spring ok.
@ ManagedBean ( name = "menuController" )
@ Scope ( "view" )
public class MenuController implements Serializable { *** }
E quando a serialização SIM por favor serialize tudo sempre.
RussMic 9 de jun. de 2015
Aqui vai a fonte de onde nosso amigo alexafe acima tirou a informação:
Esse cara é fera demais, e só poderia ser, neh, afinal é o criador do PrimeFaces.
Vale a pena investir tempo lendo seus posts.