java - 使用 JavaScript 传递属性值

标签 java jquery jsp struts2 ognl

我是 struts 2 的新手。我有一个 jsp 页面,它将发送列 ID 到另一个 jsp 页面,该页面将其发送到操作类,在操作类中我将获取用户输入的注释并将其返回到我的第二个 jsp 页面,以将其作为弹出窗口显示给用户。问题是我的 javascript 不接受该列的值。

//THIS IS WHERE THE PROBLEM IS IN THE JAVA SCRIPT
    <display:column title="Commentaire" sortable="true" sortProperty="Commentaire" class="alerte_td_commentaire">                                                       
    <s:if test="#attr.row.Commentaire != null && #attr.row.Commentaire != ''">                          
    <a href='#' onclick='javascript:var xx = (%{#attr.row.id}).val(); CommenatireToGet(xx);'><img src='/img/icons/ico_comment.png'></a>                                     
    </s:if>                                 
    </display:column>

//THIS IS MY SECOND JSP PAGE
function CommenatireToGet(value){
    $('#divShowCommAcqui').dialog('option', 'position', 'center');
    $('#divShowCommAcqui').dialog('open');

    var path = buildURL("/valorisation/ajax/CommenatireToGet.do");
    $.getJSON(
        path,
        {idAlerte:value},
        function(json){
            $('#commentaireAqui').val=getElementbyId(json.hello);
        }   
    )
};
//THIS IS MY ACTION CLASS
public String getComment() throws ServiceException{
        jsonData = new LinkedHashMap<String, Object>();
        idAlerte= (Integer) getActionSession("idAlerte");
        Alerte alerte =svc.retrieve(idAlerte);
        if (alerte !=null){
            jsonData.put("hello",alerte.getCommentaire());
        }

        return SUCCESS;
    }

//THIS IS MY STRUS TAG
<action name="CommenatireToGet" class="ihm.valorisation.AlerteAction" method="getComment">
            <result name="success" type="json">
                <param name="root">jsonData</param>
            </result>                       
        </action>

最佳答案

您不能在 JSP 中的任何位置使用 OGNL 表达式,只能在 Stuts2 标记的属性中使用,甚至不能在全部属性中使用。所以,改变一下

<a href='#' onclick='javascript:var xx = (%{#attr.row.id}).val(); CommenatireToGet(xx);'><img src='/img/icons/ico_comment.png'></a>

<a href='#' onclick='CommenatireToGet(<s:property value="%{#attr.row.id}"/>);'><img src='/img/icons/ico_comment.png'></a>

关于java - 使用 JavaScript 传递属性值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17988700/

相关文章:

java - 在不改变页面的情况下提取和处理textarea值形式

java - 如何从csv文件中读取自定义格式的时间?

java - 如何获取我使用的服务包的符号名称?

java - 为什么 java 设计者强制要求 if obj1.equals(obj2) then obj1.hashCode() MUST Be == obj2.hashCode()

java - 如何使用 Wix 创建 Java 应用程序的快捷方式

javascript - 定义新的图标可折叠 JQuery

javascript - css-如何在图像网格上放置文本和按钮?

javascript - jquery在ie8中更改attr href更改文本

spring - org.apache.jasper.JasperException :/WEB-INF/views/home. jsp(行 : [25], 列:[1])找不到属性的设置方法:[commandName]

java - 如何在jsp页面中垂直显示值列表