<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[Heck's  Blog]]></title> 
<link>https://www.heckjj.com/index.php</link> 
<description><![CDATA[一瞬间的决定，往往可以改变很多，事实上，让自己成功的往往不是知识，是精神！ 如果你总是为自己找借口，那只好让成功推迟。执行力，今天！]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[Heck's  Blog]]></copyright>
<item>
<link>https://www.heckjj.com/jsf-ahead-method-transmit-para/</link>
<title><![CDATA[JSF向方法传递参数]]></title> 
<author>Heck &lt;@hecks.tk&gt;</author>
<category><![CDATA[编程杂谈]]></category>
<pubDate>Mon, 20 Sep 2010 18:29:34 +0000</pubDate> 
<guid>https://www.heckjj.com/jsf-ahead-method-transmit-para/</guid> 
<description>
<![CDATA[ 
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: 微软雅黑;">我们在jsf中你其实并不能通过h:commandButton或 者h:commandLink向一个带参数的方法中传递参数，但是你也可以使用f:param来达到这一目的。比如对于下面的代码：</span><br/><textarea name="code" class="java" rows="15" cols="100"><h:commandButton value="Submit"
action="#&#123;MyAction.actionMethod&#125;">
<f:param name="myParam" value="#&#123;AnotherBean.value&#125;"/>
</h:commandButton></textarea><br/><span style="font-family: 微软雅黑;">你不能够这样定义MyAction中的actionMethod：<br/><span style="color: #4169E1;"><br/>public String actionMethod(String myParam)</span><br/><br/>JSF不会把相应的参数传递给方法。但是你可以申明一个无参数的方法并通过request得到f:param中的值：</span><br/><textarea name="code" class="java" rows="15" cols="100">
public String actionMethod()&#123;
&nbsp;&nbsp;&nbsp;&nbsp;FacesContext context = FacesContext.getCurrentInstance();
&nbsp;&nbsp;&nbsp;&nbsp;HttpServletRequest myRequest = (HttpServletRequest)context.getExternalContext().getRequest();HttpSession mySession = myRequest.getSession();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;String myParam = myRequest.getParameter("myParam");&nbsp;&nbsp;
//.....
&#125;
</textarea><br/><span style="font-family: 微软雅黑;">另外，需要提醒你的是，如果你使用了<span style="color: #FF0000;">JBoss Seam</span>，你就完全可以使用带参数的方法了。</span><br/>Tags - <a href="https://www.heckjj.com/tags/h%253Acommandlink/" rel="tag">h:commandlink</a> , <a href="https://www.heckjj.com/tags/f%253Aparam/" rel="tag">f:param</a> , <a href="https://www.heckjj.com/tags/h%253Acommandbutton/" rel="tag">h:commandbutton</a> , <a href="https://www.heckjj.com/tags/jsf/" rel="tag">jsf</a>
]]>
</description>
</item><item>
<link>https://www.heckjj.com/jsf-ahead-method-transmit-para/#blogcomment</link>
<title><![CDATA[[评论] JSF向方法传递参数]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>https://www.heckjj.com/jsf-ahead-method-transmit-para/#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>