writing the correct url input

Splash Forums PrettyFaces Users writing the correct url input

This topic contains 1 reply, has 2 voices, and was last updated by  Christian Kaltepoth 5 years, 2 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #18627

    abidz05
    Participant

    Hi All,

    I have the following configuration

    <url-mapping id=”viewItem”>

    <pattern value=”/store/#{mik: invCtrl.mik}/#{iid }” />

    <view-id value=”/welcome.jsf”/>

    </url-mapping>

    and the following pretty link

    <pretty:link mappingId=”viewItem”>

    View Car

    <f:param value=”#{invCtrl.modelId}”/>

    <f:param value=”#{invCtrl.makeId}”/>

    </pretty:link>

    The url that is generated from that is:

    http://www.someweb.com/store/2/3

    where the numbers are the ids of the make and model of a car.

    I would like the url to be displayed as

    http://www.someweb.com/store/toyota/corolla

    any idea how to do that.

    thanks

    #22835

    Sure, you can do that. Typically developers are using database IDs to reference an object from the database in the URL like you did before. This is usually a very nice way to do it because you can simply use the ID from the URL to load the corresponding object from the database.

    If you want to have names in the URL this will become a little bit harder. If your model object has something like a name you could use that instead. But you have to make sure that names are unique so that you can always find the correct model object in the database when only having the name and not the ID any more.

    If cannot make sure that the name is unique, you should add something like a “URL key” property to your object which is guaranteed to be unique (containing “toyota” for example).

    Another option would be to use both the ID and the name of the entity in the URL. Something like:

    http://www.someweb.com/store/2/toyota/3/corolla

    That would allow you to use the ID to load the correct object from the database and you have a pretty name of the entity in the URL. You would use the ID to load the object from the database and just ignore the name

    That’ something Amazon does in a similar way. Look at this URL:

    http://www.amazon.com/Whats-New-Java-7-ebook/dp/B005XSS8VC/

    The text “Whats-New-Java-7-ebook” is for SEO reasons only. In fact you can also use this URL:

    http://www.amazon.com/Bla-Bla-Bla/dp/B005XSS8VC/

    So the unique ID for the item is “B005XSS8VC”.

    Hope this helps

    Christian

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

Comments are closed.