功能“ "必须在未指定默认命名空间时使用前缀 [英] The function " " must be used with a prefix when a default namespace is not specified
问题描述
我们正在对表单变量进行一些奇怪的处理。无论如何,我已经设法从请求中获取变量,所以我可以做一些数据库的东西。现在我想回发到所以选择框可以用原始选项填充。
we are doing some weird handling of our form variables. Anyway I have managed to get the variables from the request so i can do some database stuff. Now i want to post back to the from so the select boxes are can be populated with the original selections.
以下是选择字段的示例:
Here is an example of a select field:
JSP:
Condition Code:
<select size="1" name="filterCriteria('CONDITION_CODE').values">
<option value=""> </option>
<c:forEach var="bean" items="${conditions}">
<option value="'${bean.code}'"<c:if test="${bean.code == form.filterCriteria('CONDITION_CODE').values}"> selected="selected"</c:if>>${bean.code}: ${bean.description}</option>
</c:forEach>
</select>
<input type="hidden" name="filterCriteria('CONDITION_CODE').fieldName" value="CONDITION_CODE"/>
<input type="hidden" name="filterCriteria('CONDITION_CODE').operation" value="="/>
正如您所见,该名称是以下形式的函数: name = filterCriteria('CONDITION_CODE')。值
As you can see the name is a function in the form: name="filterCriteria('CONDITION_CODE').values
以下是表格:
private String[] fieldNames;
private Map<String, FilterCriteriaForm> filters =
new HashMap<String, FilterCriteriaForm>();
public String[] getFieldNames() { return this.fieldNames; }
public Map<String, FilterCriteriaForm> getFilters() { return this.filters; }
public FilterCriteriaForm getFilterCriteria(String fieldName)
throws ServletException
{
FilterCriteriaForm filter = (FilterCriteriaForm)filters.get(fieldName);
if (filter == null)
{
filter = new DetFilterCriteriaForm( requestAction );
filters.put( fieldName, filter );
}
return filter;
}
public void setFilters(Map<String, FilterCriteriaForm> val) { this.filters = val; }
}
无论如何,通常我会在jsp上执行类似这样的操作来设置字段表格中的内容:< c:if test =$ {bean.code == form.filterCriteria('CONDITION_CODE')。values}> selected =selected< / c:if>
Anyway normally I do something like this on the jsp to set the field back to what is in the form: "<c:if test="${bean.code == form.filterCriteria('CONDITION_CODE').values}"> selected="selected"</c:if>
当我这样做时...我收到此错误:
When I do this...I get this error:
当未指定默认命名空间时,函数filterCriteria必须与前缀一起使用
The function filterCriteria must be used with a prefix when a default namespace is not specified
编辑:
Condition Code: <select size="1" name="filterCriteria('CONDITION_CODE').values">
<c:set var="condition" value="filterCriteria('CONDITION_CODE').values" />
<option value=""> </option>
<c:forEach var="bean" items="${conditions}">
<option value="'${bean.code}'" <c:if test="${bean.code == param[condition]}">selected="selected"</c:if>>${bean.code}: ${bean.description}</option>
</c:forEach>
</select>
<input type="hidden" name="filterCriteria('CONDITION_CODE').fieldName" value="CONDITION_CODE"/>
<input type="hidden" name="filterCriteria('CONDITION_CODE').operation" value="="/>
<br/></br>
这就是工作......我再次仔细看了一下表格......拿出来单引号并使用getFilters():
THIS IS WHAT WORKED....I looked at the form again closer...took out the single quotes and used the getFilters():
<select size="1" name="filterCriteria(CONDITION_CODE).values">
<option value=""> </option>
<c:forEach var="bean" items="${conditions}">
<c:set var="code" value="'${bean.code}'" />
<option value="${code}" <c:if test='${code == form.filters["CONDITION_CODE"].values[0]}'>selected="selected"</c:if>>${bean.code}: ${bean.description}</option>
</c:forEach>
</select>
推荐答案
为什么要提供表单和输入元素无效的名称那样的?
Why are you giving your form and input elements invalid names like that?
无论如何,你的具体的问题是你不是要比普通字符串,而是比较EL对象。就像你现在一样,它需要一个bean $ {form}
,方法 filterCriteria(String)
返回一些对象它有一个 getValues()
方法。那不是你想要的。你希望它是一个普通的字符串。
Anyway, your concrete problem is that you're not comparing to a plain string, but to an EL object. As you have now, it expects a bean ${form}
with a method filterCriteria(String)
which returns some object which has a getValues()
method. That's not what you want. You want it to be a plain string.
修复如下,你需要引用它:
Fix it as follows, you need to quote it:
<c:if test="${bean.code == 'form.filterCriteria(\'CONDITION_CODE\').values'}">
但这不会让你达到功能要求。看起来你将Java / JSP与JavaScript混淆并期望它们同步运行。事实并非如此,Java / JSP在Web服务器中运行并生成HTML。 JavaScript是HTML的一部分,仅在webbrowser中运行。 表单
变量仅在JavaScript中可用,而不在JSTL标记中。
But this won't let you achieve the functional requirement. It look like that you're confusing Java/JSP with JavaScript and expecting them to run in sync. This is not true, Java/JSP runs in webserver and generates HTML. JavaScript is part of HTML and runs in webbrowser only. The form
variable is only available in JavaScript, not in a JSTL tag.
你实际上需要通过 $ {param}
将提交的值作为请求参数获取。所有输入元素的值都可以通过请求参数映射中的名称获得。它看起来如下:
You actually need to grab the submitted value as a request parameter by ${param}
. The values of all input elements are avaiable by their name in the request parameter map. It would look like follows:
<c:if test="${bean.code == param['filterCriteria(\'CONDITION_CODE\').values']}">
我只是不保证是否可行,我从未使用过无效字符的名字,你也许需要对奇数字符进行URL编码。如果您根据 HTML规范。
I only don't guarantee if that would work, I have never used names with invalid characters, you perhaps need to URL-encode the odd characters. It would be much easier if you give your form and input elements a valid name which matches the rules as per HTML specification.
<select name="condition">
<option value=""> </option>
<c:forEach items="${conditions}" var="condition">
<option value="${condition.code}" ${condition.code == param.condition ? 'selected' : ''}>${condition.code}: ${condition.description}</option>
</c:forEach>
</select>
(请注意,您在<选项中的值无效值>
,那些单引号不属于那里,我已将它们删除了)
(note that you had an invalid value in <option value>
, those singlequotes doesn't belong there, I've removed them)
更新:根据评论,您在访问EL中的非法参数名称时似乎有EL语法错误问题。转义字符 \
似乎被EL解析器完全吞没。你最好的选择可能是用< c:set>
代替它:
Update: as per the comments, you seem to have a EL syntax error problem when accessing the illegal parameter name in EL. The escape characters \
seems to be completely swallowed by the EL parser. Your best bet is probably to alias it with <c:set>
:
<c:set var="condition" value="filterCriteria('CONDITION_CODE').values" />
...
<c:if test="${bean.code == param[condition]}">
更新2 :那些围绕期权价值的单一报价似乎是绝对必要的。在这种情况下,您需要在其上添加另一个别名。完整代码如下所示:
Update 2: those singlequotes around the option value seem to be absolutely necessary. In that case, you need to add another alias on that. The full code would look like this:
<select size="1" name="filterCriteria('CONDITION_CODE').values">
<c:set var="condition" value="filterCriteria('CONDITION_CODE').values" />
<option value=""> </option>
<c:forEach var="bean" items="${conditions}">
<c:set var="code" value="'${bean.code}'" />
<option value="${code}" <c:if test="${code == param[condition]}">selected="selected"</c:if>>${bean.code}: ${bean.description}</option>
</c:forEach>
</select>
这篇关于功能“ "必须在未指定默认命名空间时使用前缀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!