Struts2 %{}的使用

1.

public class UserAction extends BaseAction{

    public String showText() {
        return "w"+"hich";
    }

}


<s:property value="%{showText()}"/>


页面显示:which


2.

<s:url var="pagerActionPath" value="/page/admin/basic/user_list"></s:url>


在Stack Context中的request中能找到pagerActionPath的键值对


因此我可以

通过el来访问: ${requestScope.pagerActionPath }

通过#request来访问: <s:property value="#request.pagerActionPath"/>

通过%{}来访问: <s:property value="%{pagerActionPath}"/> (比较抽象)

官网:Another way to refer to a property placed on the Value Stack.

但是我在值栈中并没有pagerActionPath,它是存在于Stack Context,就是Action Context 中!

难道%{}就是先去value stack中找,如果找不到就到Stack Context中的 request中查找?


3.

这种情况下,我们想让文本框有默认值,因此只是想字符串,因此这么干,也可以这么干:value="'ca'"

<s:textfield key="state.label"
 name="state"
 value="%{'ca'}"
 />

如果这么干: value="ca",则调用value stack中的key为ca的值


4.

如果multiple="true",是可以的,s2自动计算字符串,让它转换成boolean类型

但是推荐自己搞定:%{true}


<s:select key="state.label"
 name="state"
 multiple="%{true}"
/>


估计有点乱,应该是这样



猜你喜欢

转载自macrotea.iteye.com/blog/1019029