使用javascript传递属性值
我是struts 2的新手。我有一个jsp页面,它会将一个列ID发送到另一个jsp页面,而另一个jsp页面会将它发送到action类,在那里我会得到用户输入的注释,并将其返回到我的第二个jsp页面,将其作为弹出窗口显示给用户。问题是我的javascript不接受列的值使用javascript传递属性值,java,jquery,jsp,struts2,ognl,Java,Jquery,Jsp,Struts2,Ognl,我是struts 2的新手。我有一个jsp页面,它会将一个列ID发送到另一个jsp页面,而另一个jsp页面会将它发送到action类,在那里我会得到用户输入的注释,并将其返回到我的第二个jsp页面,将其作为弹出窗口显示给用户。问题是我的javascript不接受列的值 //THIS IS WHERE THE PROBLEM IS IN THE JAVA SCRIPT <display:column title="Commentaire" sortable="true" sortPr
//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>
//这就是JAVA脚本中的问题所在
//这是我的第二个JSP页面
函数ComminatiRetoGet(值){
$('#divshowcomacqui')。对话框('option','position','center');
$('#divshowcomacqui')。对话框('open');
var path=buildURL(“/valorisation/ajax/communitietoget.do”);
$.getJSON(
路径
{idAlerte:value},
函数(json){
$('#commentaireAqui').val=getElementbyId(json.hello);
}
)
};
//这是我的动作课
公共字符串getComment()引发ServiceException{
jsonData=newlinkedhashmap();
idAlerte=(整数)getActionSession(“idAlerte”);
Alerte-Alerte=svc.retrieve(idAlerte);
如果(警报!=null){
put(“hello”,alerte.getCommentaire());
}
回归成功;
}
//这是我的STRUS标签
杰森达
您不能在JSP中的任何地方使用OGNL表达式,只能在Stuts2标记的属性中使用,即使不是所有属性。所以,改变
<a href='#' onclick='javascript:var xx = (%{#attr.row.id}).val(); CommenatireToGet(xx);'><img src='/img/icons/ico_comment.png'></a>
到
您不能在JSP中的任何地方使用OGNL表达式,只能在Stuts2标记的属性中使用,即使不是所有属性。所以,改变
<a href='#' onclick='javascript:var xx = (%{#attr.row.id}).val(); CommenatireToGet(xx);'><img src='/img/icons/ico_comment.png'></a>
到
谢谢,在使用您的代码并删除.val()之后,它工作得很好@john Yes,我专注于OGNL,忘记了javascript,更正了。您能告诉我为什么在第二个JSP页面中,我无法将Json值传递给我的$(“#commentaireAqui”)。在我的动作类中,代码是jsonData.put(“hello”,alerte.getCommentaire());作品精美,hello值正确;但是当我返回到第二个并开始执行时,我无法将我的json从action类的值更改为$(“#commentaireAqui”)?@john您不应该使用getElementById来获取作为json对象返回的值。@RomanC我曾多次尝试在html标记中直接使用%{},但都不起作用,所以我总是在s:property value中使用它,知道它为什么不起作用吗?谢谢,在使用了您的代码并删除了.val()@john是的,我专注于OGNL,忘记了javascript,更正了。您能告诉我为什么在我的第二个JSP页面中,我不能将Json值传递给我的$(“#commentaireAqui”)。在我的动作类中,代码是jsonData.put(“hello”,alerte.getCommentaire());作品精美,hello值正确;但是当我返回到第二个并开始执行时,我无法将我的json从action类的值更改为$(“#commentaireAqui”)?@john您不应该使用getElementById来获取作为json对象返回的值。@RomanC我曾多次尝试在html标记中直接使用%{},但都不起作用,所以我总是要在s中使用它:属性值,知道它为什么不起作用。