Navigating with p: selectOneMenu

I use one menu to navigate in different parts of my site:

<p:selectOneMenu value="#{navigator.outcome}">                      
    <f:selectItem itemLabel="Select page..." />
    <f:selectItem itemValue="page1" itemLabel="Page 1" />
    <f:selectItem itemValue="page2" itemLabel="Page 2" />
    <f:selectItem itemValue="page3" itemLabel="Page 3" />
    <p:ajax event="change" listener="#{navigator.navigate}" />
</p:selectOneMenu>

Is there a more SEO friendly way to do this? I am worried that JavaScript links will not be respected.

+5
source share
3 answers

Use the user-generated content with <p:column>using <h:link>.

Bean:

private List<Page> pages;

@PostConstruct
public void init() {
    pages = new ArrayList<Page>();
    pages.add(new Page("Page 1", "/page1.xhtml"));
    pages.add(new Page("Page 2", "/page2.xhtml"));
    pages.add(new Page("Page 3", "/page3.xhtml"));
}

View:

<p:selectOneMenu var="page">
    <f:selectItems value="#{bean.pages}" var="page" itemLabel="#{page.title}" />
    <p:column>
        <h:link value="#{page.title}" outcome="#{page.viewId}" />
    </p:column>
</p:selectOneMenu>

Please note that this does not work with List<SelectItem>individual elements <f:selectItem>. You really need to provide List<Entity>(where Entityis Pagein the example above).

It generates <table>with full-featured and workaround (and interactive!) <a>Elements.

See also:

+6

, :

<p:selectOneMenu value="#{navigator.outcome}">                      
    <f:selectItem itemLabel="Select page..." />
    <f:selectItem itemValue="page1" itemLabel="Page 1" />
    <f:selectItem itemValue="page2" itemLabel="Page 2" />
    <f:selectItem itemValue="page3" itemLabel="Page 3" />
    <p:ajax event="change" listener="#{navigator.navigate}" />
</p:selectOneMenu>

public void navigate() {
    FacesContext context = FacesContext.getCurrentInstance();
    NavigationHandler navigationHandler = context.getApplication()
            .getNavigationHandler();
    navigationHandler.handleNavigation(context, null, outcome
            + "?faces-redirect=true");
}
+2

, . , , SEO.

, submit, :

<h:form>
    <h:selectOneMenu value="#{bean.currentPage}" converter="pageConverter" onchange="submit()">
        <f:selectItems value="#{bean.pages}" var="page" itemLabel="#{page.name}" />
    </h:selectOneMenu>
    <h:commandButton value="submit" action="#{bean.handleNavigation}" style="display:none"/>
</h:form>

@FacesConverter("pageConverter")

bean (@ManagedBean Bean)

private List<Page> pages;
private Page selectedPage;

public String handleNavigation(){
    //do some job before navigation
    return (selectedPage == null) ? null : selectedPage.getUrl();
}

class Page {
    private String name;//title in links
    private String url;//JSF view-id
}

Dropbox :

<h:form>
    <h:selectOneMenu value="#{bean.currentPage}" converter="pageConverter">
        <f:selectItems value="#{bean.pages}" var="page" itemLabel="#{page.name}" />
    </h:selectOneMenu>
    <h:commandButton value="Navigate" action="#{bean.performNavigation}"}/>
</h:form>

, .

<h:link> s

<h:link> s:

<ul>
    <ui:repeat var="page" value="#{bean.pages}>
        <li>
            <h:link value="#{page.name}" outcome="#{page.url}" />
        </li>
    </ui:repeat>
</ul>

.

SEO

SEO , . URL- Page, , www.site.com/contact-us , www.site.com/contact.xhtml.

IMHO - Prettyfaces, , . URL- ( URL- JSF).

SEO , seoUrl Page, Prettyfaces, URL-, SEO (.. www.site.com/contact-us) JSF view-id ( .. www.site.com/contact.xhtml) -.

- URL

SEO- , Google, URL:

  • URL- - ( Google);
  • , URL . - , URL- ( , italics mine);
  • URL- ( Google);
  • ;
  • URL-.

SEO:

:

  • , URL- www.site.com/contact-us.xhtml, 6 - www.site.com/contact-us ;
  • , , /pages/articles/general/how-to-do-jsf.xhtml, www.site.com/articles/how-to-do-jsf , , ;
  • , , (jsf-bp.xhtml) (article23.xhtml), URL- www.site.com/article/jsf-best-practices-for-beginners;
  • , .xhtml, .jsf .., (, , ) , ( , ), , www.site.com/product.xhtml?id=12345, , (, , ) , URL- , , www.site.com/products/jsf-book-for-advanced-users. , , ;
  • (?id=12345) (/jsf-book-for-advanced-users);
  • URL- . www.site.com/products/jsf-book-for-advanced-users: URL , /jsf-book-for-advanced-users . , www.site.com/product.xhtml?name=jsf-book-for-advanced-users www.site.com/catalogue.xhtml ? , URL-;
  • , , SEO, ( ), , , stackoverflow.com.

I do not claim that the sources I refer to are indisputable or extremely authoritative, or their input requirements should apply to every web application, etc., but I believe that the well-structured, user-friendly sites that exist for a long time in production, as a rule, follow these rules.

+1
source

All Articles