|
View:
New views
16 Messages
—
Rating Filter:
Alert me
|
|
|
XML output with FaceletsHi.
I've recently switched to Facelets. Astounished, how smoothly it works. I'd like to move to Facelets from JSP completely. Two missing fragments for me now are redirects and changing content type. The first problem concerns redirects from pages. For instance, I'd like all users who access /myapp to be automatically redirected to /myapp/pi/start.html. Ideally, there should be an index.xhtml in /myapp, redirecting to the target page. What would a solution look like with Facelets. A similar issue: on the certain page, I'd like to output some XML data with my bean. How could I set the correct content of the response type with Facelets? Bye. /lexi --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... |
|
|
Re: XML output with FaceletsOn 3/2/06, Aleksei Valikov <valikov@...> wrote:
> The first problem concerns redirects from pages. For instance, I'd like > all users who access /myapp to be automatically redirected to > /myapp/pi/start.html. Ideally, there should be an index.xhtml in /myapp, > redirecting to the target page. What would a solution look like with > Facelets. I have successfully done redirects using this index.jsp file. <%@ page session="false" contentType="text/html;charset=utf-8"%> <% response.sendRedirect("faces/pages/announcement/EditAnnouncements.xhtml"); %> I have these entries in my web.xml file. <!-- Welcome files --> <welcome-file-list> <welcome-file>index.jsp</welcome-file> <welcome-file>index.html</welcome-file> </welcome-file-list> --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... |
|
|
Re: XML output with FaceletsHi.
>>The first problem concerns redirects from pages. For instance, I'd like >>all users who access /myapp to be automatically redirected to >>/myapp/pi/start.html. Ideally, there should be an index.xhtml in /myapp, >>redirecting to the target page. What would a solution look like with >>Facelets. > > I have successfully done redirects using this index.jsp file. > > <%@ page session="false" contentType="text/html;charset=utf-8"%> > <% > response.sendRedirect("faces/pages/announcement/EditAnnouncements.xhtml"); > %> > > I have these entries in my web.xml file. > > <!-- Welcome files --> > <welcome-file-list> > <welcome-file>index.jsp</welcome-file> > <welcome-file>index.html</welcome-file> > </welcome-file-list> Yes, JSPs will certainly work. I'd like to drop JSPs as a whole - so that we only have (X)(H)TML templates from Facelets. Bye. /lexi --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... |
|
|
Re: XML output with Facelets>The first problem concerns redirects from pages. For instance, I'd like
>all users who access /myapp to be automatically redirected to >/myapp/pi/start.html. Ideally, there should be an index.xhtml in /myapp, >redirecting to the target page. What would a solution look like with >Facelets. I suppose you should write a filter that will do this redirect. Because as i know, if you put <welcome-file>...</welcome-file> into web.xml, every webserver checks for presense of specified file. And it doesn't work with JSF because there are no files with *.jsf extension. --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... |
|
|
Re: XML output with FaceletsI've resorted to javascript redirects because they force a page reload
and url update. This is to get around the fact that myfaces doesn't output the dummylinkform if certain conditions aren't met. <body> <script>window.location = '/main/home.jsf'</script> </body> or <body> <script>window.location = "#{requestScope['origRequestUri']}"</script> </body> On 3/2/06, Mike Kienenberger <mkienenb@...> wrote: > On 3/2/06, Aleksei Valikov <valikov@...> wrote: > > The first problem concerns redirects from pages. For instance, I'd like > > all users who access /myapp to be automatically redirected to > > /myapp/pi/start.html. Ideally, there should be an index.xhtml in /myapp, > > redirecting to the target page. What would a solution look like with > > Facelets. > > I have successfully done redirects using this index.jsp file. > > <%@ page session="false" contentType="text/html;charset=utf-8"%> > <% > response.sendRedirect("faces/pages/announcement/EditAnnouncements.xhtml"); > %> > > I have these entries in my web.xml file. > > <!-- Welcome files --> > <welcome-file-list> > <welcome-file>index.jsp</welcome-file> > <welcome-file>index.html</welcome-file> > </welcome-file-list> > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscribe@... > For additional commands, e-mail: users-help@... > > --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... |
|
|
|
|
|
Re: XML output with FaceletsOn 3/2/06, Aleksei Valikov <valikov@...> wrote:
> Yes, JSPs will certainly work. I'd like to drop JSPs as a whole - so > that we only have (X)(H)TML templates from Facelets. Well, you're going to have to have "something" to redirect it. I don't think you can just stick an xhtml file in the welcome list, but I'm no servlet expert. So whether it's a 2-line jsp or a 2-line html file, I don't see that it really makes a lot of difference. Remember, the point of using facelets over jsp is to make your life easier. I don't see a lot of practical reasons to avoid an index.jsp file to initialize your application start page. It makes your life easier to do so. That said, I'm enough of an anti-jsp snob that I'll gladly replace my index.jsp file with an index.html file if you post an equivalent one :) I wouldn't install a filter to do it -- that makes my job harder not easier. -Mike --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... |
|
|
Re: XML output with Facelets>>The first problem concerns redirects from pages. For instance, I'd like
>>all users who access /myapp to be automatically redirected to >>/myapp/pi/start.html. Ideally, there should be an index.xhtml in /myapp, >>redirecting to the target page. What would a solution look like with >>Facelets. > > I suppose you should write a filter that will do this redirect. Filter is a too heavy solution, I'm simply looking for the constrution analogous to JSP's c:redirect. Bye. /lexi --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... |
|
|
Re: XML output with Facelets>Filter is a too heavy solution, I'm simply looking for the constrution
>analogous to JSP's c:redirect. Filter will be more user/searcher friendly because they won't need to make a redirect. Nobody calls Apache mod_rewrite a heavy solution, right? This will be something like that. BTW, if your webserver is behind Apache, you can use mod_rewrite. I do understand that index.jsp/index.html page is the simplest solution but it isn't the friendliest one. --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... |
|
|
RE: XML output with FaceletsMy favorite solution is to have a custom navigation handler (I never liked the navigation rules mechanism). It's simple, and you can do lots of nice things there, such as tweaking URLs to whatever you like. > I don't think you can just stick an xhtml file in the welcome > list, but I'm no servlet expert. Here you go: <context-param> <param-name>facelets.VIEW_MAPPINGS</param-name> <param-value>*.xhtml</param-value> </context-param> ... <servlet> <servlet-name>faces</servlet-name> <servlet-class>javax.faces.webapp.FacesServlet</servlet-clas s> <load-on-startup>1</load-on-startup> </servlet> ... <servlet-mapping> <servlet-name>faces</servlet-name> <url-pattern>/faces/*</url-pattern> </servlet-mapping> ... <welcome-file-list> <welcome-file>faces/MyWelcomeJsfFaceletsPage.xhtml</welcome- file> </welcome-file-list> Frank Felix > -----Original Message----- > From: Mike Kienenberger [mailto:mkienenb@...] > Sent: Thursday, March 02, 2006 6:15 PM > To: users@... > Subject: Re: XML output with Facelets > > On 3/2/06, Aleksei Valikov <valikov@...> wrote: > > Yes, JSPs will certainly work. I'd like to drop JSPs as a > whole - so > > that we only have (X)(H)TML templates from Facelets. > > Well, you're going to have to have "something" to redirect it. > I don't think you can just stick an xhtml file in the welcome > list, but I'm no servlet expert. > So whether it's a 2-line jsp or a 2-line html file, I don't see that > it really makes a lot of difference. Remember, the point of using > facelets over jsp is to make your life easier. I don't see a lot of > practical reasons to avoid an index.jsp file to initialize your > application start page. It makes your life easier to do so. > > That said, I'm enough of an anti-jsp snob that I'll gladly > replace my index.jsp file with an index.html file if you post > an equivalent one > :) I wouldn't install a filter to do it -- that makes my job harder > not easier. > > -Mike > > ------------------------------------------------------------ --------- > To unsubscribe, e-mail: users-unsubscribe@... > For additional commands, e-mail: users-help@... > --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... |
|
|
Re: XML output with FaceletsOn 2-Mar-06, at 12:15 PM, Mike Kienenberger wrote:
> On 3/2/06, Aleksei Valikov <valikov@...> wrote: >> Yes, JSPs will certainly work. I'd like to drop JSPs as a whole - so >> that we only have (X)(H)TML templates from Facelets. > > Well, you're going to have to have "something" to redirect it. > I don't think you can just stick an xhtml file in the welcome list, > but I'm no servlet expert. You can stick anything in the welcome list, the only requirement is that there must be a concrete physical resource (i.e. a file) for the container to read. The container will look at the set of files in the context root, see if any of them matches the welcome list and, if so, dispatch the request to the corresponding URL -- which may, in turn, invoke a servlet rather than serving the actual file. > So whether it's a 2-line jsp or a 2-line html file, I don't see that > it really makes a lot of difference. Remember, the point of using > facelets over jsp is to make your life easier. I don't see a lot of > practical reasons to avoid an index.jsp file to initialize your > application start page. It makes your life easier to do so. Since JSP is required to be available in every servlet container anyway, there's not much reason not to use a JSP to meet this requirement. The main advantage over the other options (see below) is that you can do a server-side redirect (forward) rather than a client- side redirect, while still keeping things simple. > That said, I'm enough of an anti-jsp snob that I'll gladly replace my > index.jsp file with an index.html file if you post an equivalent one > :) I wouldn't install a filter to do it -- that makes my job harder > not easier. There are several options. Just using an index.jsp to do a forward or redirect is probably the simplest and most portable, but here are some of the other options, in rough order of complexity: - use an index.(x)html with META-refresh to make the browser redirect - use an index.(x)html with Javascript-based redirect - use a custom ViewHandler to do a redirect for viewId == '/' - use a phase listener to do the same thing - install a filter to do it There may be other options I'm not thinking of too :-) -- Laurie Harper Open Source advocate, Java geek: http://www.holoweb.net/laurie Founder, Zotech Software: http://www.zotechsoftware.com/ --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... |
|
|
Re: XML output with FaceletsLaurie,
Thanks for the in-depth explanations! It was very helpful to me. I'm still confused over the differences between using an xhtml (JSF-mapped) file and an index.jsp, though. Your message indicates that the optimal solution is a jsp as it's the only server-side redirect. However, if the xhtml file is directly processed by the faces servlet, wouldn't that completely avoid the need to redirect? On 3/2/06, Laurie Harper <laurie@...> wrote: > On 2-Mar-06, at 12:15 PM, Mike Kienenberger wrote: > > On 3/2/06, Aleksei Valikov <valikov@...> wrote: > >> Yes, JSPs will certainly work. I'd like to drop JSPs as a whole - so > >> that we only have (X)(H)TML templates from Facelets. > > > > Well, you're going to have to have "something" to redirect it. > > I don't think you can just stick an xhtml file in the welcome list, > > but I'm no servlet expert. > > You can stick anything in the welcome list, the only requirement is > that there must be a concrete physical resource (i.e. a file) for the > container to read. The container will look at the set of files in the > context root, see if any of them matches the welcome list and, if so, > dispatch the request to the corresponding URL -- which may, in turn, > invoke a servlet rather than serving the actual file. > > > So whether it's a 2-line jsp or a 2-line html file, I don't see that > > it really makes a lot of difference. Remember, the point of using > > facelets over jsp is to make your life easier. I don't see a lot of > > practical reasons to avoid an index.jsp file to initialize your > > application start page. It makes your life easier to do so. > > Since JSP is required to be available in every servlet container > anyway, there's not much reason not to use a JSP to meet this > requirement. The main advantage over the other options (see below) is > that you can do a server-side redirect (forward) rather than a client- > side redirect, while still keeping things simple. > > > That said, I'm enough of an anti-jsp snob that I'll gladly replace my > > index.jsp file with an index.html file if you post an equivalent one > > :) I wouldn't install a filter to do it -- that makes my job harder > > not easier. > > There are several options. Just using an index.jsp to do a forward or > redirect is probably the simplest and most portable, but here are > some of the other options, in rough order of complexity: > > - use an index.(x)html with META-refresh to make the browser redirect > - use an index.(x)html with Javascript-based redirect > - use a custom ViewHandler to do a redirect for viewId == '/' > - use a phase listener to do the same thing > - install a filter to do it > > There may be other options I'm not thinking of too :-) > -- > Laurie Harper > Open Source advocate, Java geek: http://www.holoweb.net/laurie > Founder, Zotech Software: http://www.zotechsoftware.com/ > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscribe@... > For additional commands, e-mail: users-help@... > > --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... |
|
|
Re: XML output with FaceletsYes, it would; all of this discussion is in the context of "my main
entry point is at '.../foo.faces, but I want '/' to work as well." If you can just put a Faces view (be it JSP, Facelet (X)HTML, or whatever) in /index.something, you can simply add index.something to the welcome file list and avoid all of this. In other words, what this really comes down to is that there's no way in JSF to create a logical mapping between view IDs and physical view definitions. There's an implicit mapping, view.faces -> view.jsp and you have very little flexibility other than choosing between URL prefix/suffix mapping, what the prefix/suffix is, and what the view extension is (.jsp by default). L. On 2-Mar-06, at 4:57 PM, Mike Kienenberger wrote: > Laurie, > > Thanks for the in-depth explanations! > > It was very helpful to me. I'm still confused over the differences > between using an xhtml (JSF-mapped) file and an index.jsp, though. > Your message indicates that the optimal solution is a jsp as it's the > only server-side redirect. However, if the xhtml file is directly > processed by the faces servlet, wouldn't that completely avoid the > need to redirect? > > On 3/2/06, Laurie Harper <laurie@...> wrote: >> On 2-Mar-06, at 12:15 PM, Mike Kienenberger wrote: >>> On 3/2/06, Aleksei Valikov <valikov@...> wrote: >>>> Yes, JSPs will certainly work. I'd like to drop JSPs as a whole >>>> - so >>>> that we only have (X)(H)TML templates from Facelets. >>> >>> Well, you're going to have to have "something" to redirect it. >>> I don't think you can just stick an xhtml file in the welcome list, >>> but I'm no servlet expert. >> >> You can stick anything in the welcome list, the only requirement is >> that there must be a concrete physical resource (i.e. a file) for the >> container to read. The container will look at the set of files in the >> context root, see if any of them matches the welcome list and, if so, >> dispatch the request to the corresponding URL -- which may, in turn, >> invoke a servlet rather than serving the actual file. >> >>> So whether it's a 2-line jsp or a 2-line html file, I don't see that >>> it really makes a lot of difference. Remember, the point of using >>> facelets over jsp is to make your life easier. I don't see a >>> lot of >>> practical reasons to avoid an index.jsp file to initialize your >>> application start page. It makes your life easier to do so. >> >> Since JSP is required to be available in every servlet container >> anyway, there's not much reason not to use a JSP to meet this >> requirement. The main advantage over the other options (see below) is >> that you can do a server-side redirect (forward) rather than a >> client- >> side redirect, while still keeping things simple. >> >>> That said, I'm enough of an anti-jsp snob that I'll gladly >>> replace my >>> index.jsp file with an index.html file if you post an equivalent one >>> :) I wouldn't install a filter to do it -- that makes my job >>> harder >>> not easier. >> >> There are several options. Just using an index.jsp to do a forward or >> redirect is probably the simplest and most portable, but here are >> some of the other options, in rough order of complexity: >> >> - use an index.(x)html with META-refresh to make the browser redirect >> - use an index.(x)html with Javascript-based redirect >> - use a custom ViewHandler to do a redirect for viewId == '/' >> - use a phase listener to do the same thing >> - install a filter to do it >> >> There may be other options I'm not thinking of too :-) >> -- >> Laurie Harper >> Open Source advocate, Java geek: http://www.holoweb.net/laurie >> Founder, Zotech Software: http://www.zotechsoftware.com/ >> >> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: users-unsubscribe@... >> For additional commands, e-mail: users-help@... >> >> > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscribe@... > For additional commands, e-mail: users-help@... > -- Laurie Harper Open Source advocate, Java geek: http://www.holoweb.net/laurie Founder, Zotech Software: http://www.zotechsoftware.com/ --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... |
|
|
Re: XML output with FaceletsHi.
>>Filter is a too heavy solution, I'm simply looking for the constrution >>analogous to JSP's c:redirect. > > Filter will be more user/searcher friendly because they won't need to make a redirect. I don't think redirects are "unfriendly". I really want people to get redirected to the target page cause it's a logical thing to do for the scenario. > Nobody calls Apache mod_rewrite a heavy solution, right? I do. > This will be something like that. > BTW, if your webserver is behind Apache, you can use mod_rewrite. > > I do understand that index.jsp/index.html page is the simplest solution but it isn't the friendliest one. Disagree. Bye. /lexi --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... |
|
|
Re: XML output with FaceletsHi.
> There are several options. Just using an index.jsp to do a forward or > redirect is probably the simplest and most portable, but here are some > of the other options, in rough order of complexity: > > - use an index.(x)html with META-refresh to make the browser redirect > - use an index.(x)html with Javascript-based redirect > - use a custom ViewHandler to do a redirect for viewId == '/' > - use a phase listener to do the same thing > - install a filter to do it > > There may be other options I'm not thinking of too :-) I've written RedirectHandler and ParamHandler (attached) - could somewone take a look at them? However I still have problems with changing the content type. Bye. /lexi <?xml version="1.0"?> <!DOCTYPE facelet-taglib PUBLIC "-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN" "http://java.sun.com/dtd/facelet-taglib_1_0.dtd"> <facelet-taglib> <namespace>http://java.sun.com/jstl/core</namespace> <tag> <tag-name>redirect</tag-name> <handler-class>de.disy.commons.facelets.tag.jstl.core.RedirectHandler</handler-class> </tag> <tag> <tag-name>param</tag-name> <handler-class>de.disy.commons.facelets.tag.jstl.core.ParamHandler</handler-class> </tag> </facelet-taglib> package de.disy.commons.facelets.tag.jstl.core; import java.io.IOException; import javax.el.ELException; import javax.faces.FacesException; import javax.faces.component.UIComponent; import com.sun.facelets.FaceletContext; import com.sun.facelets.FaceletException; import com.sun.facelets.tag.TagAttribute; import com.sun.facelets.tag.TagConfig; import com.sun.facelets.tag.TagHandler; public class ParamHandler extends TagHandler{ private final TagAttribute name; private final TagAttribute value; public ParamHandler(TagConfig config) { super(config); name = getRequiredAttribute("name"); value = getRequiredAttribute("value"); } public void apply(FaceletContext ctx, UIComponent parent) throws IOException, FacesException, FaceletException, ELException { this.nextHandler.apply(ctx, parent); } public String getName(FaceletContext ctx) { return name.getValue(ctx); } public String getValue(FaceletContext ctx) { return value.getValue(ctx); } } package de.disy.commons.facelets.tag.jstl.core; import java.io.IOException; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import javax.el.ELException; import javax.faces.FacesException; import javax.faces.component.UIComponent; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.sun.facelets.FaceletContext; import com.sun.facelets.FaceletException; import com.sun.facelets.tag.TagAttribute; import com.sun.facelets.tag.TagConfig; import com.sun.facelets.tag.TagHandler; public class RedirectHandler extends TagHandler { private final TagAttribute urlAttribute; private final TagAttribute contextAttribute; private final ParamHandler[] paramHandlers; public RedirectHandler(TagConfig config) { super(config); urlAttribute = getRequiredAttribute("url"); contextAttribute = getAttribute("context"); final List paramHandlersList = new ArrayList(); final Iterator itr = this.findNextByType(ParamHandler.class); while (itr.hasNext()) { paramHandlersList.add(itr.next()); } this.paramHandlers = (ParamHandler[]) paramHandlersList .toArray(new ParamHandler[paramHandlersList.size()]); } public void apply(FaceletContext ctx, UIComponent parent) throws IOException, FacesException, FaceletException, ELException { final String url = urlAttribute.getValue(ctx); final String context = contextAttribute == null ? null : contextAttribute.getValue(ctx); final HttpServletRequest request = (HttpServletRequest) ctx .getFacesContext() .getExternalContext() .getRequest(); final String resolvedURL = resolveUrl(url, context, request); final String aggregatedURL = aggregateParams(resolvedURL, ctx, paramHandlers); final HttpServletResponse response = (HttpServletResponse) ctx .getFacesContext() .getExternalContext() .getResponse(); final String target = !isAbsoluteUrl(aggregatedURL) ? response.encodeRedirectURL(aggregatedURL) : aggregatedURL; response.sendRedirect(target); } public static final String VALID_SCHEME_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+.-"; public static boolean isAbsoluteUrl(String url) { if (url == null) return false; int colonPos; if ((colonPos = url.indexOf(":")) == -1) return false; for (int i = 0; i < colonPos; i++) if (VALID_SCHEME_CHARS.indexOf(url.charAt(i)) == -1) return false; return true; } public static String resolveUrl(String url, String context, HttpServletRequest request) throws FaceletException { if (isAbsoluteUrl(url)) { return url; } else { if (context == null) { if (url.startsWith("/")) return (request.getContextPath() + url); else return url; } else { if (!context.startsWith("/") || !url.startsWith("/")) { throw new FaceletException( "If context is provided, both [url] and [context] must start with a \"/\"."); } if (context.equals("/")) { return url; } else { return (context + url); } } } } public static String aggregateParams( String url, final FaceletContext ctx, ParamHandler[] paramHandlers) { final StringBuffer newParams = new StringBuffer(); for (int i = 0; i < paramHandlers.length; i++) { final ParamHandler paramHandler = paramHandlers[i]; final String name = paramHandler.getName(ctx); final String value = paramHandler.getValue(ctx); newParams.append(name + "=" + value); if (i < (paramHandlers.length - 1)) newParams.append("&"); } if (newParams.length() > 0) { int questionMark = url.indexOf('?'); if (questionMark == -1) { return (url + "?" + newParams); } else { final StringBuffer workingUrl = new StringBuffer(url); workingUrl.insert(questionMark + 1, (newParams + "&")); return workingUrl.toString(); } } else { return url; } } } --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... |
|
|
|
| Free embeddable forum powered by Nabble | Forum Help |