Java regular expression, replace slashes
In my ui I had this line:
<f:param name="fullPath" value="#{model.folderObject.folder.fullPath}"/>
So, fullPath contains “\Electronic Project Folders\AJW-148\AMASS-2005-000181-A\CIF Replacement 234-2005X546A\CCA, AMASS CIM”
I needed to replace singe slash with double slashes
FacesContext context = FacesContext.getCurrentInstance();
Map<String, String> params = context.getExternalContext().getRequestParameterMap();
String fullPath = URLDecoder.decode(params.get("fullPath"));
String fullPath2 = fullPath.replaceAll("\\\\", "\\\\" );
Thanks to Jason Lee.
Read query string from backing bean – 2 ways
I needed to read a parameter from query string in JSF backing bean. http://atowus/epf?packageId=17169
Here how it works:
FacesContext context = FacesContext.getCurrentInstance();
Map<String, String> params = context.getExternalContext().getRequestParameterMap();
String pID = params.get("packageId");
Now pID should have the value 17169
OR:
In faces-config.xml:
<managed-bean>
<description>Backing bean for tree example. </description>
<managed-bean-name>tree</managed-bean-name>
<managed-bean-class>gov.faa.amc.nas.epf.TreeBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
<managed-property>
<property-name>packageId</property-name>
<value>#{param.packageId}</value> <!--JSF injects query string value from request parameter -->
</managed-property>
</managed-bean>
In TreeBean.java, I have a instance variable and getter and setter
private String packageId;
Caution: Bean scope has to be request otherwise you get a nasty error like this.
javax.faces.FacesException: Problem in renderResponse: Unable to create managed
bean tree. The following problems were found:
- The scope of the object referenced by expression #{param.packageId}, request, is shorter than the
referring managed beans (tree) scope of session note
-
Archives
- November 2009 (1)
- July 2009 (1)
- June 2009 (5)
- May 2009 (2)
- April 2009 (4)
- March 2009 (2)
- January 2009 (3)
- December 2008 (1)
- November 2008 (2)
- October 2008 (1)
- September 2008 (3)
- August 2008 (2)
-
Categories
-
RSS
Entries RSS
Comments RSS