Can flowScope entries be accessed from JSPs? ("Property ... not found on type org.springframework.webflow.core.collection.LocalAttributeMap") - el

I'm learning Spring and webflow and I'm having trouble with something which seems like it should be simple. My flow is capturing a query string parameter and stashing it in a flow-scoped variable when the flow begins. I'm trying to echo it on the first view-state. Errors ensue.
Here's the flow definition:
<?xml version="1.0" encoding="UTF-8"?>
<flow xmlns="http://www.springframework.org/schema/webflow"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/webflow
http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd">
<on-start>
<set name="flowScope.foo" value="requestParameters.fubar" />
</on-start>
<view-state id="step1" view="../jsp/step1.jsp">
<transition on="next" to="step2" />
</view-state>
<view-state id="step2" view="../jsp/step2.jsp">
<transition on="next" to="step3" />
<transition on="prev" to="step1" />
</view-state>
<view-state id="step3" view="../jsp/step3.jsp">
<transition on="prev" to="step2" />
<transition on="next" to="done" />
</view-state>
<end-state id="done" view="endView" />
<end-state id="cancelled" view="../jsp/cancelledView.jsp" />
<global-transitions>
<transition on="cancel" to="cancelled" />
</global-transitions>
</flow>
step1.jsp:
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%# taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%# taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%# taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Step 1</title>
</head>
<body>
This is step 1
<h1>flowRequestContext.flowScope: ${flowRequestContext.flowScope}</h1>
<h1>flowRequestContext.flowScope["foo"]: ${flowRequestContext.flowScope["foo"]}</h1>
<h2>${flowScope}</h2>
<c:if test="${empty flowScope}">
<h1>FLOW SCOPE IS EMPTY!</h1>
</c:if>
<c:if test="${!empty flowScope}">
<h1>FLOW SCOPE IS *NOT* EMPTY!</h1>
</c:if>
<c:if test="${empty flowRequestContext.flowScope}">
<h1>flowRequestContext.FLOW SCOPE IS EMPTY!</h1>
</c:if>
<c:if test="${!empty flowRequestContext.flowScope}">
<h1>flowRequestContext.FLOW SCOPE IS *NOT* EMPTY!</h1>
</c:if>
<form:form id="myForm">
<input type="submit" id="next" name="_eventId_next" value="Next" />
<input type="submit" name="_eventId_cancel" value="Cancel" />
</form:form>
</body>
</html>
Resulting error:
javax.el.PropertyNotFoundException: Property 'foo' not found on type org.springframework.webflow.core.collection.LocalAttributeMap
javax.el.BeanELResolver$BeanProperties.get(BeanELResolver.java:223)
javax.el.BeanELResolver$BeanProperties.access$400(BeanELResolver.java:200)
javax.el.BeanELResolver.property(BeanELResolver.java:311)
javax.el.BeanELResolver.getValue(BeanELResolver.java:85)
javax.el.CompositeELResolver.getValue(CompositeELResolver.java:67)
org.apache.el.parser.AstValue.getValue(AstValue.java:169)
org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:189)
...
If I omit the attempt to access the key "foo" the page renders with the following output (where the query string is ?fubar=baz):
This is step 1
flowRequestContext.flowScope: map['foo' -> 'baz', 'viewScope' -> map[[empty]]]
FLOW SCOPE IS EMPTY!
flowRequestContext.FLOW SCOPE IS *NOT* EMPTY!
It looks like the identifier flowRequestContext.flowScope does refer to a map, and it looks like it does contain the key and value I would expect... but if I try to access it like a map in EL it doesn't cooperate.

just use ${foo} everything in your flowscope should be accessible with $

Related

Include view parameters in h:link

I have a problem when adding view parameters to a <h:link includeViewParams="true" /> - they are not added to the rendered link. I am using Mojarra 2.3.9.
Template /WEB-INF/templates/main.xhtml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:head>
<!-- Some headers -->
</h:head>
<h:body>
<f:view>
<ui:insert name="metaContent" />
<div class="container-fluid" id="mainContent">
<ui:insert name="mainContent" />
</div>
</f:view>
</h:body>
</html>
Template being used on page test.xhtml
<!DOCTYPE html>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:o="http://omnifaces.org/ui"
template="/WEB-INF/templates/main.xhtml">
<ui:define name="metaContent">
<f:metadata>
<f:viewParam name="id" value="#{myBean.obj}" required="true">
<f:validator validatorId="myIdVvalidator" />
<f:converter converterId="myConverter" />
</f:viewParam>
</f:metadata>
</ui:define>
<ui:define name="mainContent">
<!-- Simply reference current page -->
<h:link outcome="test.xhtml" includeViewParams="true">
My link
</h:link>
</ui:define>
</ui:composition>
Update
If I remove the attribute value of f:viewParam as well as the f:converterand f:validator child elements, the link is rendered as expected. Why can this cause a problem? The Bean myBean is #RequestScoped

ExpressionEngine Index page repeats its' code over and over until all pages' contents have loaded

Been working on wrapping my head around expression engine now. And I'm using the Structure add-on as well. This is my first attempt of building my own template.
The problem I'm having is on the index page when you initially land on the site. It will repeat the entire html over and over until its' loaded every pages' content. It only does this on the index page. If you click on any other page it works as its supposed to.
Heres my code:
<!DOCTYPE html>
<html>
{exp:channel:entries channel="pages"}
<head>
<meta charset="UTF-8">
{!-- add="filename|filename2" --}
{embed="Pages/styles"}
{embed="Pages/scripts"}
<title>{title}</title>
</head>
<body>
<header>
<img src="img/logo.png" />
<nav>
{exp:structure:nav css_id="none" start_from="/" show_depth="2"}{/exp:structure:nav}
</nav>
</header>
<main>
<nav>
{exp:structure:breadcrumb inc_home="no" here_as_title="yes"}{/exp:structure:breadcrumb}
</nav>
{if structure:child_ids != '' OR structure:parent:entry_id != '0'}
<aside>
{exp:structure:nav css_id="none" show_depth="2" start_from="/{segment_1}" show_overview="yes" rename_overview="{structure:top:title}"}{/exp:structure:nav}
</aside>
{/if}
<article>
<h1>{title}</h1>
{page_contents}
</article>
</main>
<footer>
<nav>
{exp:structure:nav css_id="none" start_from="/" max_depth="1"}{/exp:structure:nav}
</nav>
<address>
<p>1234 Address St<br />
City Name, STATE 12345<br />
Phonee: 123 456 7890<br />
Email Us</p>
</address>
</footer>
</body>
{/exp:channel:entries}
</html>
And here is the link to the site: (no styling, just building and testing for now) http://www.oneoffs.co
It's not the prettiest solution but you could simply add entry_id to the loop which would limit it to only the homepage.
{exp:channel:entries channel="pages" entry_id="1"}
..
{/exp:channel:entries}
or
{exp:channel:entries channel="pages" {if segment_1 == ''}entry_id="1"{/if}}
..
{/exp:channel:entries}
...which only adds the entry_id if you're on your homepage (assumption that segment_1 is blank).

How to prevent auto character encoding in .NET

Using VB.NET in Visual Studio 2010, I have two files:
"test2.aspx" and "test2.aspx.vb".
The aspx file is basically as follows:
<%# Page Language="VB" AutoEventWireup="false" CodeFile="test2.aspx.vb" Inherits="App_test2" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta id="meta1" runat="server" name="description" />
</head>
<body>
<textarea id="text1" runat="server" />
</body>
</html>
The vb file is basically like this:
meta1.Attributes("charset") = "UTF-8"
meta1.Attributes("content") = "I'm a description tag"
text1.InnerText = "&'<>"
This all displays as expected in the browser, but the source code when the page is rendered looks like this:
<html>
<head>
<meta id="meta1" name="description" content="I'm a description tag" charset="UTF-8"></meta>
</head>
<body>
<textarea name="text1" id="text2">&'<></textarea>
</body>
</html>
Is there something I can do so the source code doesn't escape characters like "&", "'", "<", and ">" ?
You don't. If it didn't convert those characters, the browser would incorrectly interpret them as commands instead of data. It shouldn't be an issue for you because it is always converted back to the character data in code. text2.Text would contain the values you want, not the escaped data.

"Could not find action or result" in Struts

I'm currently creating a web application using the jquery+struts plugin. It also uses hibernate. I have two web pages already, the other one works perfectly fine but when I created another one, it threw an error saying that the action cannot be found. The error is:
ERROR (org.apache.struts2.dispatcher.Dispatcher:38) - Could not find action or result
/mims_agchem/index.action
No result defined for action com.agchem.mims.actions.Index and result success
at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:375)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:277)
at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:263)
at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
These are my codes:
struts.xml
<struts>
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="true" />
<package name="admin" namespace="/admin" extends="hibernate-default,json-default,struts-default">
<interceptors>
<interceptor-stack name="showcaseStack">
<interceptor-ref name="defaultStackHibernate"/>
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="showcaseStack"/>
<action name="*" class="com.agchem.mims.actions.admin.{1}">
<result>/jsp/admin/{1}.jsp</result>
<result name="redirect" type="redirect">${redirectUrl}</result>
</action>
</package>
<package name="general" namespace="/" extends="hibernate-default,json-default,struts-default">
<interceptors>
<interceptor-stack name="showcaseStack">
<interceptor-ref name="defaultStackHibernate"/>
</interceptor-stack>
</interceptors>
<action name="index" class="com.agchem.mims.actions.Index">
<result name="success">/jsp/index.jsp</result>
<result name="redirect" type="redirect">${redirectUrl}</result>
</action>
</package>
Index.java
package com.agchem.mims.actions;
import com.opensymphony.xwork2.ActionSupport;
public class Index extends ActionSupport {
private static final long serialVersionUID = 1475579903320095412L;
#Override
public String execute() throws Exception {
return SUCCESS;
}
}
index.jsp
<?xml version="1.0" encoding="utf-8"?>
<%# taglib prefix="s" uri="/struts-tags"%>
<%# taglib prefix="sj" uri="/struts-jquery-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>AGCHEM MIMS</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="keywords" content="struts2,jquery, hibernate, plugin,showcase, grid" />
<meta http-equiv="description" content="Project Maintenance" />
<link href="../styles/main.css" rel="stylesheet" type="text/css" />
<link href="../styles/menu.css" rel="stylesheet" type="text/css" />
<sj:head
loadAtOnce="true"
compressed="false"
jquerytheme="mims"
customBasepath="../themes"
loadFromGoogle="false"
debug="true"
/>
<script type="text/javascript" src="../js/menu.js"></script>
</head>
<body>
<s:url id="adm201" action="ADM201"/>
<s:url id="adm210" action="ADM210"/>
<s:url id="adm301" action="ADM301"/>
<s:url id="adm310" action="ADM310"/>
<div id="menu">
<ul class="menu" style="width: 765px">
<li>
<sj:a href="../general/main_admin.html" targets="main">Home</sj:a>
</li>
<li class="current">
<sj:a href="#" class="parent">Project</sj:a>
<div>
<ul>
<li><sj:a href="%{adm201}" class="current" targets="main">Create New Project</sj:a></li>
<li><sj:a href="%{adm210}" targets="main">Search Projects</sj:a></li>
</ul>
</div>
</li>
<li>
<sj:a href="#" class="parent">User</sj:a>
<div>
<ul>
<li><sj:a href="%{adm301}" targets="main">Create New User</sj:a></li>
<li><sj:a href="%{adm310}" targets="main">Search Users</sj:a></li>
</ul>
</div>
</li>
</ul>
</div>
<sj:div id="main" href="%{adm201}">
<img id="indicator" src="../images/indicator.gif" alt="Loading..."/>
</sj:div>
</body>
</html>
Hope someone could explain and help me on my problem. Thanks a lot!
Regards,
Honey =)
The other page already worked. With just some refresh and restarts on the server, the page just worked fine. :) Weird though.. :)

How to refer to a control that exists within an Ajax Tab?

I have a problem with using a script that adds a NiceEdit toolbar to a text area when that text area is within an Ajax tab.
I want to know if I should refer to it in a different way than just the ID.
I mean the ID of that text area, I tried to take the text area outside the Tab Container, it works, but when I return it, it simply doesn't.
<%# Page Language="VB" ValidateRequest ="false" AutoEventWireup="false" CodeFile="tabbedNiceEditt.aspx.vb" Inherits="Client_tabbedNiceEditt" %>
<script src="../nicEdit/nicEdit.js" type="text/javascript"></script>
<script type="text/javascript">
bkLib.onDomLoaded(function() {
new nicEditor({buttonList : ['fontSize','fontFamily','fontFormat','bold','italic','underline','strikethrough','forecolor','bgcolor','removeformat'], iconsPath : '../nicEdit/nicEditorIcons.gif'}).panelInstance('txt');
});
</script>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
function pageLoad() {
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<cc1:TabContainer ID="TabContainer1" runat="server">
<cc1:TabPanel ID= "first" runat ="server" >
<ContentTemplate>
<b>Stuff Goes HERE</b>
<br />
<asp:TextBox ID = "txt" name = "txt" runat ="server" TextMode ="MultiLine" Height = "256" Width = "256">
</asp:TextBox>
<br />
<br />
<asp:Button id = "btn" runat ="server" Text = "click" />
</ContentTemplate>
</cc1:TabPanel>
<cc1:TabPanel ID = "second" runat ="server" >
<ContentTemplate>
<b>More Stuff for second tab</b>
</ContentTemplate>
</cc1:TabPanel>
</cc1:TabContainer>
</div>
</form>
</body>
</html>
txt is the server ID of your control, you have to use the client ID :
....panelInstance('<%= txt.ClientID %>');
Basically, the client ID is derived from the server ID and the naming container where your control is, to avoid any naming conflict. When your text area is not in the Ajax Tab, the client ID is the same as the server ID. When you put the text area in the Ajax Tab, it's client ID is different (you can check that by looking at the page source in your browser).
EDIT:
From Maen
I viewed the page in browser, checked
the ID in the page source, it was
"TabContainer1$first$txt", used it
instead of "txt" and the script was
like: panelInstance('<%=
txt.TabContainer1$first$txt %> I got
an error: BC30456: 'TabContainer1' is
not a member of
'System.Web.UI.WebControls.TextBox'.
That's not what I meant : you have to put panelInstance('<%= txt.ClientID %>') in your source code, and asp.net will convert that to panelInstance('TabContainer1$first$txt').
I told you to check the page source in the web browser just to see that the client Id was no longer "txt", but that it was constructed from the server ID and the naming container.