gpt4 book ai didi

java - 使用 JavaScript 传递属性值

转载 作者:太空宇宙 更新时间:2023-11-04 07:29:22 25 4
gpt4 key购买 nike

我是 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com