比较 JSP 中的两个 valuestack 字符串值 - struts2 [英] comparing two valuestack string values in JSP - struts2

查看:32
本文介绍了比较 JSP 中的两个 valuestack 字符串值 - struts2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

提前感谢您的时间.

如果单选按钮有保存的值,我需要预先选择它.我基本上需要比较 valuestack 中的 2 个字符串来确定这一点.

I need to preselect a radio button if it has a saved value. I basically need to compare 2 strings in the valuestack to determine this.

(我目前无法使用 <s:radio,因为我需要根据表单中的其他输入元素附加一些业务规则).

(I can't use <s:radio at the moment because of some business rules I need to attach based on other input elements in the form).

我尝试将 保存在 s:iterate 中的值如下对.

I tried to do <s:set the value of the saved id inside s:iterate like below and then compare them like below but obviously I didnt get it right.

<s:set var="savedId" value="%{flag.problemId}"/> 
              <s:iterator value="problemIdList"> 
                    <s:set var="currentId" value='<s:property value="id"/>' />                   
                        <s:if test="%{#currentId.equals(#savedId)}" >
                                <input checked="checked" type="radio" name="problemId" id="problemId" value='<s:property value="id"/>'/> <s:property value="description"/> <br/>
                        </s:if>
                <s:else>
                    <input type="radio" name="problemId" id="problemId" value='<s:property value="id"/>'/> <s:property value="description"/> <br/>
                </s:else>                       
             </s:iterator>

基本上我需要比较两个字符串,我的代码如下.我知道我无法与下面的 equals() 进行比较 - 有什么想法吗?

Basically I need to compare the two strings, my code is below. I know I can't compare with equals() like I have below - any ideas?

非常感谢!

<s:set var="savedId" value="%{flag.problemId}"/>  <s:iterator value="problemIdList">                                 
<s:if test=' <s:property value="id"/>.equals(<s:property value="savedId"/>) '>
    <input checked="checked" type="radio" name="problemId" id="problemId" value='<s:property value="id"/>'/>            <s:property value="description"/> <br/>
</s:if>
<s:else>
    <input type="radio" type="radio" name="problemId" id="problemId" value='<s:property value="id"/>'/>                     <s:property value="description"/> <br/>
</s:else>                       

问候,VeeCan

推荐答案

您是否尝试过:

<s:if test='id.equals(savedId)'>

如果id"是一个字符串,OGNL 将允许你使用 String 的方法.

If "id" is a string OGNL will allow you to use methods of String.

这篇关于比较 JSP 中的两个 valuestack 字符串值 - struts2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆