-
1. Re: Refreshing context variable originally initialized via commandButton submission
monkeyden Jan 11, 2011 12:14 PM (in response to femibyte)Unless you're using a long running conversation, which you would have to do explicitly, you are in the default/implied conversation which (I believe) is EVENT scope. Suffice to say, it's too short for your purposes. In the initial backing bean, you probably want to do:
@Out(ScopeType.SESSION) private String env;
and in your subsequent pages, use:
@In private String env;
Without seeing code, I can't venture a guess as to why it seems to be working as desired on the first pass.
-
2. Re: Refreshing context variable originally initialized via commandButton submission
femibyte Jan 11, 2011 3:27 PM (in response to femibyte)My code looks like this:
Backing bean for welcome page:
@Name("welcomeBean")
@Scope(CONVERSATION)
public class WelcomeBean implements Welcome,Serializable {
private final static Log logger=LogFactory.getLog(WelcomeBean.class);
@Out(required=false)
private String env;
@NotNull @Lob
public String getEnv() {
return env;
}
@Begin
public void setEnv(String env) {
logger.info("Setting ENV=" + env);
this.env=env;
}
public String submit() {
logger.info("Obtained ENV=" + env);
return "/namespaces.seam";
}Backing bean for subsequent page:
@Name("namespaceManager")
@Stateful
public class NamespaceManagerBean implements Serializable, NamespaceManager
{
private final static Log logger = LogFactory.getLog(NamespaceManagerBean.class);
@In private String env;
@DataModel
private List<Namespace> namespaceList;
@Out(required=false)
private List<String> commandList;
@Factory("commandList")
public void initCommandList()
{
commandList=new ArrayList<String>();
commandList.add("getAllKeys");
commandList.add("getMatchingKeys");
commandList.add("removeNamespace");
}
@DataModelSelection
@Out(required=false, scope = CONVERSATION)
public Namespace namespace;
@Out(value="cacheManager", required=true)
private CoherenceCacheManager cacheManager;
@Factory("cacheManager")
public void getCacheConnection() throws Exception
{
cacheManager=new CoherenceCacheManager();
logger.info("ENV=" + env);
cacheManager.connectToCache(env);
}
@Factory("namespaceList")
public void findNamespaces()
{
if (cacheManager==null)
{
logger.info("cacheManager is null");
try {
getCacheConnection();
}
catch(Exception e)
{
e.printStackTrace();
}
}
String[] nsList=cacheManager.getAllNamespaces();
namespaceList=new ArrayList<Namespace>();
for(int i=0;i<nsList.length;i++)
{
Namespace ns=new Namespace();
ns.setTitle(nsList[i]);
namespaceList.add(ns);
}
}
public String select()
{
if (namespace!=null) namespace.setRead(true);
return "/cacheEntries.seam";
}
The env variable is submitted via this jsp:
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://jboss.com/products/seam/taglib" prefix="s" %>
<html>
<head>
<title>Coherence Cache Management</title>
</head>
<body>
<f:view>
<h:form>
<h2>Coherence Cache Management</h2>
<h4>Select Environment</h4>
<h:selectOneMenu value="#{welcomeBean.env}">
<f:selectItem itemLabel="LocalDev" itemValue="LocalDev"/>
<f:selectItem itemLabel="Dev" itemValue="Dev"/>
<f:selectItem itemLabel="QA" itemValue="QA"/>
</h:selectOneMenu>
<br><br><br>
<h:commandButton value="Submit" action="#{welcomeBean.submit}">
</h:commandButton>
</h:form>
</f:view>
</body>
</html>I need the env variable to be refreshed on the following page upon the 2nd submission via the jsp with a differnt value.
Thanks for your help in advance.
-
3. Re: Refreshing context variable originally initialized via commandButton submission
femibyte Jan 11, 2011 3:46 PM (in response to femibyte)Can someone let me know how to edit the post above? I mistakenly didn't do a preview before submitting it and would like to re-format it.
-
4. Re: Refreshing context variable originally initialized via commandButton submission
femibyte Jan 11, 2011 7:10 PM (in response to femibyte)Better formatting of the code posted above.
Backing bean for welcome page:
@Name("welcomeBean") @Scope(CONVERSATION) public class WelcomeBean implements Welcome,Serializable { private final static Log logger = LogFactory.getLog(WelcomeBean.class); @Out(required=false) private String env; @NotNull @Lob public String getEnv() { return env; } @Begin public void setEnv(String env) { logger.info("Setting ENV=" + env); this.env=env; } public String submit() { logger.info("Obtained ENV=" + env); return "/namespaces.seam";// + "?env=" + env; } }
Backing bean for subsequent page:
@Name("namespaceManager") @Stateful public class NamespaceManagerBean implements Serializable, NamespaceManager { private final static Log logger = LogFactory.getLog(NamespaceManagerBean.class); @In private String env; @DataModel private List<Namespace> namespaceList; @Out(required=false) private List<String> commandList; @Factory("commandList") public void initCommandList() { commandList=new ArrayList<String>(); commandList.add("getAllKeys"); commandList.add("getMatchingKeys"); commandList.add("removeNamespace"); } @DataModelSelection @Out(required=false, scope = CONVERSATION) public Namespace namespace; @Out(value="cacheManager", required=true) private CacheManager cacheManager; // @Begin(join=true) @Factory("cacheManager") public void getCacheConnection() throws Exception { cacheManager=new CacheManager(); logger.info("ENV=" + env); cacheManager.connectToCache(env); } @Factory("namespaceList") public void findNamespaces() { if (cacheManager==null) { logger.info("cacheManager is null"); try { getCacheConnection(); } catch(Exception e) { e.printStackTrace(); } } String[] nsList=cacheManager.getAllNamespaces(); namespaceList=new ArrayList<Namespace>(); for(int i=0;i<nsList.length;i++) { Namespace ns=new Namespace(); ns.setTitle(nsList[i]); namespaceList.add(ns); } } public String select() { if (namespace!=null) namespace.setRead(true); return "/cacheEntries.seam"; } @Remove @Destroy public void destroy() { env=null; } }
The env variable is submitted via this jsp:
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %> <%@ taglib uri="http://jboss.com/products/seam/taglib" prefix="s" %> <html> <head> <title>Coherence Cache Management</title> </head> <body> <f:view> <h:form> <h2>Cache Management</h2> <h4>Select Environment</h4> <h:selectOneMenu value="#{welcomeBean.env}"> <f:selectItem itemLabel="LocalDev" itemValue="LocalDev"/> <f:selectItem itemLabel="Dev" itemValue="Dev"/> <f:selectItem itemLabel="QA" itemValue="QA"/> </h:selectOneMenu> <br><br><br> <h:commandButton value="Submit" action="#{welcomeBean.submit}"> </h:commandButton> </h:form> </f:view> </body> </html>
I need the env variable to be refreshed on the following page upon the 2nd submission via the jsp with a differnt value.
Thanks for your help in advance.