Syntax within a Seam page.xml to output current date? - jsf

Is it possible to something like the following to assign the 'occurredAt' attribute with a call using Seam's extended support for SEAM EL (seam 2.2)?
<navigation>
<rule if-outcome="search">
<out name="occurredAt" scope="event" value="#{new java.util.Date()}"/>
<redirect view-id="/ui/search.xhtml"/>
</rule>
</navigation>

seam has built-in #{currentDate} factory method, so you can write;
<navigation>
<rule if-outcome="search">
<redirect view-id="/ui/search.xhtml">
<param name="occurredAt" value="#{currentDate}"/>
</redirect>
</rule>
</navigation>
and you can access occuredAt parameter from search.xhtml

Related

IIS: Rewrite / Redirect [duplicate]

I do my best to scan the forum for help to make a web.config to do a Rewrite of this kind of url
domain.com/default.asp?id=3&language=2
My hope is that this can be
domain.com/en/service
where language=2 is "en"
and id=3 is page "Service" (this name exist in a mySQL)
I can only find example that do it vice versa...
Like this
<rewrite>
<rules>
<rule name="enquiry" stopProcessing="true">
<match url="^enquiry$" />
<action type="Rewrite" url="/page.asp" />
</rule>
</rules>
</rewrite>
I would like it to be something like this... I know this isn't correct, but maybe explains my problem.
<rewrite>
<rules>
<rule name="enquiry" stopProcessing="true">
<match url="^default.asp?id=3&language=2$" />
<action type="Rewrite" url="/en/serice" />
</rule>
</rules>
</rewrite>
If you want to use regular expressions you could do something like this
<rule name="RewriteUserFriendlyURL1" stopProcessing="true">
<match url="^([^/]+)/([^/]+)/?$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="default.asp?language={R:1}&id={R:2}" />
</rule>
This would rewrite "domain.com/en/service" as "domain.com/default.asp?language=en&id=Service", or "domain.com/2/3" as "domain.com/default.asp?language=2&id=3"
To change the 2 to en and the 3 to service, along with all the other options though I think you would need a separate rule for each permutation, or have some sort of logic within your asp pages to read your querystring variables and send the corresponding values to your SQL queries. Note also that the parameters in the friendly url appear in the same order and the querystring variables in the rewritten URL, although this shouldn't really be an issue. If someone tries to access the page with the original "unfriendly" url they will find what they are looking for, whichever way round they enter the querystring variables.
Please note, I didn't actually hand code the rule above, I generated it with the URL Rewrite module in IIS manager - it makes life a lot easier
Also note, as discussed with my namesake in the other answer, this only applies to IIS7 and above
I have done this in Classic ASP using custom error pages and this seems to be the best way unless you use some sort of third party component installed on the server.
To do this, in IIS (or web.config) you need to set up 404 errors to go to a specific custom error Classic ASP page (eg. 404.asp).
In this custom error page you first need to check to see if the URL is valid. If it is you can Server.Transfer to the correct page, return a 200 response code, and parse the URL there to convert the URL to the values needed for the database lookup, etc. If it's not a valid URL then you show a custom error page and return a 404 response code.
The code to check for a valid URL and to retrieve the URL parameters will vary greatly depending on your URL structure. But to find the URL requested on the custom 404 error page you have to look at the querystring, which will be something like "404;http://domain.com:80/en/service/".
Here's some sample code that gets the parameters from the requested URL:
Dim strUrl, intPos, strPath, strRoutes
strUrl = Request.ServerVariables("QUERY_STRING")
If Left(strUrl, 4) = "404;" Then
intPos = InStr(strUrl, "://")
strPath = Mid(strUrl, InStr(intPos, strUrl, "/") + 1)
If strPath <> "" Then
If Right(strPath, 1) = "/" Then strPath = Left(strPath, Len(strPath) - 1)
End If
strRoutes = Split(strPath, "/")
'Here you can check what parameters were passed in the url
'eg. strRoutes(0) will be "en", and strRoutes(1) will be "service"
End If
And here's how you can setup custom error pages in the web.config (rather than in IIS):
<?xml version="1.0"?>
<configuration>
<system.webServer>
<httpErrors errorMode="Custom" existingResponse="Replace">
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" subStatusCode="-1" responseMode="ExecuteURL" path="/404.asp" />
</httpErrors>
</system.webServer>
</configuration>

IIS URL Rewrite with ColdFusion keeps duplicates string

I have set up a URL rewrite which works fine when I manually set or type in the URL. But when I use a link in the page within a <cfoutput> tag for example, the link duplicates the string.
I'm using ColdFusion 2016 with IIS 10
For example the URL is
www.site.com/results.cfm?lang=1&categoryid=2&budegtid=all&typeid=all&propertyid=316
and I want it outputted like
www.site.com/properties/en/all/all/all/316
it works but what seems to be happing when I set the link using...
<cfoutput> using the query...
<cfif getProps.recordcount>
<cfoutput query = "getProps" startrow="#url.start#" maxrows="#perpage#">
View
</cfoutput>
the result in the link on the page outputs as www.site.com/properties/en/all/all/all/316/properties/en/all/all/all/316
I have web/config set up as
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<directoryBrowse enabled="false" />
<urlCompression doStaticCompression="true" doDynamicCompression="true" />
<rewrite>
<rules>
<rule name="Property list URL rewrite">
<match url="^property/([_0-9a-z-]+)/([_0-9a-z-]+)/budget-range-([_0-9a-z-]+)/([_0-9a-z-]+)/([_0-9a-z-]+)" />
<action type="Rewrite" url="resultsproperty.cfm?lang={R:1}&categoryid={R:2}&budegtid={R:3}&typeid={R:4}&propertyid={R:5}" appendQueryString="false" />
</rule>
</rules>
</rewrite>
<httpErrors errorMode="Detailed" />
</system.webServer>
</configuration>
The ColdFusion cfquery is as follows...
<cfquery name="getProps" datasource="#session.odbcname#">
SELECT *
FROM properties P
INNER JOIN areas A
ON A.area_id = P.property_areaid
INNER JOIN categories C
ON C.category_id = P.property_propcategoryid
INNER JOIN price R
ON R.price_id = P.property_regularity
INNER JOIN types T
ON T.type_id = P.property_proptypeid
WHERE P.property_status != 'Off Market'
<cfif url.ref is not "all">
AND
(
property_ref like <cfqueryparam cfsqltype="cf_sql_varchar" value="%#url.ref#%">
OR property_refid like <cfqueryparam cfsqltype="cf_sql_varchar" value="%#url.ref#%">
OR property_town like <cfqueryparam cfsqltype="cf_sql_varchar" value="%#url.ref#%">
)
</cfif>
ORDER BY P.property_refid
It seems to be pulling in the actual URL first and then adding on the rewrite.
Any help much appreciated.
You need to start the href with a forward slash to indicate it is from root. The href is resolved/interpretted in the browser. Not starting with a forward slash tells the browser that the url is relative to the current path.
If you are at http://example.com/admin/ and have an href logout for example it will be resolved as http://example.com/admin/logout. However if you have an href /logout it will resolve to 'http://example.com/logout.
As your own answer stated, forcing an absolute path works and can be preferred sometimes but sometimes not. Make sure you understand the underlying issue.
Solved! by pre setting the URL root in the coldfusion application file i.e. <cfset request.root = 'http://www.example.com/'> and then reference the #request.root# var within the link, it uses the link correctly and dose not duplicate the url. So this is a cold fusion issue rather than a URL ReWrite issue.

Can you use URL_Rewrite rewritemaps to modify ServerVariables in IIS?

So I'm having an issue and not sure if it's even possible.
Here's the scenario. We utilize an F5 loadbalancer with an i-Rule set to send us a header (HTTP_IV-USER) value based on an access token.
We want to query that header, see if it matches a value we have setup in a rewritemap and then change it accordingly.
I haven't seen anyone doing this with servervariables. It makes sense on how to do it in regards to changing an URL... but we'd like to change a header variable.
Basically we're taking the value from the Token, which is a number, and then matching that number to a username in active directory.
Thanks for the help!
Of course, we can use rewritemap to check and replace the value. You could modify the rule below to achieve your requirement.
<rewriteMaps>
<rewriteMap name="StaticMap">
<add key="aaaaaaaaa" value="bbbbbbbb" />
</rewriteMap>
</rewriteMaps>
<outboundRules>
<rule name="rewritemaprule">
<match serverVariable="HTTP_IV-USER" pattern="(.*)" />
<conditions>
<add input="{StaticMap:{HTTP_IV-USER}}" pattern="(.+)" />
</conditions>
<action type="Rewrite" value="{C:1}" />
</rule>
</outboundRules>

Home page to be rendered according to user type

I use the following code to redirect to my home page on login... now i want to go a step further and add a logic where it redirects to different page based on user type.
for eg: if a user type is employee then i should redirect to employeehome.xhtml and so on ... is this possible ?
<page xmlns="http://jboss.com/products/seam/pages"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://jboss.com/products/seam/pages http://jboss.com/products/seam/pages-2.2.xsd">
<navigation from-action="#{identity.login}">
<rule if="#{identity.loggedIn}">
<redirect view-id="/Home.xhtml" />
</rule>
</navigation>
I suppose you have a login.xhtml page from which the user logs in.
Then you can create a login.page.xml page containing some navigation rules. For example:
<navigation from-action='#{identity.login}'>
<rule if="#{identity.loggedIn and s:hasRole('management')}">
<redirect view-id="/management/home.xhtml"/>
</rule>
<rule if="#{identity.loggedIn and s:hasRole('upload')}">
<redirect view-id="/secure/upload.xhtml"/>
</rule>
<rule if="#{identity.loggedIn and (s:hasRole('sss') or s:hasRole('sssmgmnt'))}">
<redirect view-id="/secure/sss/home.xhtml"/>
</rule>
<rule if="#{identity.loggedIn}">
<redirect view-id="/secure/home.xhtml"/>
</rule>
</navigation>
next, you can restrict the pages, so only users with the right role can go there. In my pages.xml, I have the following lines:
<page view-id="/secure/upload.xhtml" login-required="true">
<restrict>#{s:hasRole('upload')}</restrict>
</page>

Seam page navigation with includes

I'm using seam page navigation rules. and did not experience any problem with adding rules which redirect from one page to another.
But since I designed my page views using those redirection simply don't happen anymore for those pages.
Tried to define the rule to the view that gets included, then to the view that includes the others (which to me was making more sense) but none work.
Is there anything special about page navigation in seam using included view-id ?
main.xhtml:
<h:outputLabel value="Details:"/>`
<a4j:include viewId="contacts.xhtml" id="contactsDetails"/>`
<page view-id="/*" login-required="true">
<navigation>
<rule if="#{myBean.readyToSee}">
<redirect view-id="/see-contat.xhtml"/>
</rule>
</navigation>
</page>
I'm using jsf, xhtml as my page views.
Thanks
Its difficult for me to answer this question because I simply don't understand it. However I will try to guess what you are asking.
You have a page ie: /somePage.xhtml and inside that page you include some other pages.
I tend to write all my page navigation in pages.xml. I like having everything in one place, because it makes things cleaner and easier to maintain.
You can use wildcards also in the pages.xml file.
So you can do something like this.
<page login-required="true" view-id="/admin/*">
<restrict>#{s:hasRole('orgadmin') or s:hasRole('sysadmin')}</restrict>
<navigation from-action="#{userAdmin.editUser}">
<redirect view-id="/admin/create_user.xhtml" />
</navigation>
<navigation from-action="#{applicationProcessAdmin.saveScheme}">
<rule if-outcome="failure">
<redirect view-id="/admin/processes.xhtml" />
</rule>
</navigation>
</page>
In the above example, I am using a wildcard to say that all navigation that happens from /admin/* that uses some specific action, should redirect to some page i have.
You can also be very specific with the pages
<page login-required="true" view-id="/officer/admin/contacts.xhtml">
<begin-conversation join="true" />
<navigation from-action="#{officerAdmin.saveContact}">
<redirect/>
</navigation>
</page>
If this doesn't help you, you need to clarify your question better.
Update
Try changing your
<page view-id="/*" login-required="true">
<navigation>
<rule if="#{myBean.readyToSee}">
<redirect view-id="/see-contat.xhtml"/>
</rule>
</navigation>
</page>
To this instead
<page view-id="/*" login-required="true">
<navigation from-action="#{myBean.readyToSee}">
<rule if="#{myBean.readyToSee}">
<redirect view-id="/see-contat.xhtml"/>
</rule>
</navigation>
</page>
UPDATE 2
Does all your navigation fail? Or is it only some?
Try removing the /* on page view and replace with just *
If you do this will work:
#Name("myBean")
public class MyBean {
public String doSomething() {
return "success";
}
}
Now from your xhtml (Does not matter which include page it is from)
<!-- Depending on what button you are using, <h:form> is mandatory -->
<h:form>
<h:commandButton value="TEST" action="#{myBean.doSomething}" />
</h:form>
And in your pages xml
<page view-id="*">
<navigation from-action="#{myBean.doSomething}">
<rule if-outcome="success">
<redirect view-id="/test.xhtml" />
</rule>
</navigation>
</page>
The above will work. If it does not, the error is somewhere else in your code.

Resources