You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Ron Piterman <rp...@gmx.net> on 2005/08/23 12:58:38 UTC

creating a link around a part of a sentance

Hi,
Maybe someone has a cool component or a solution to the following problem:

Say there is a resource: "Did you forget your password?"
And I wish to add a link only on the words "forgot your password"

Or: "I read and agree with the *Conditions*" , where "conditions" is a link.

Doing this on simple text is no problem, but on a resource? did anyone 
face this problem (successfully...) ?

Cheers,
Ron


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: creating a link around a part of a sentance

Posted by Ron Piterman <rp...@gmx.net>.
solution:

resource format :

Have you forgotten your {@lib:passwordForgotten}password{/@} or your 
{@lib:nickForgotten}nick{/@}?


===================================================================
package net.tutim.tapestry.components.nestedlink;

import org.apache.tapestry.AbstractComponent;
import org.apache.tapestry.IMarkupWriter;
import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.engine.IEngineService;
import org.apache.tapestry.engine.ILink;
import org.apache.tapestry.util.RegexpMatch;
import org.apache.tapestry.util.RegexpMatcher;

public abstract class NestedPageLink extends AbstractComponent {
	
	public abstract String getMessage();
	public abstract IEngineService getPageService();

	@Override
	protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle) {
		
		String message = getMessage();
		
		RegexpMatcher matcher = new RegexpMatcher();
		RegexpMatch[] links = 
matcher.getMatches("\\{@([^>]*)\\}([^\\{]*)\\{/@\\}", message);
		
		for (RegexpMatch match : links ) {
			writer.print(message.substring(0, message.indexOf(match.getInput())));
			writeLink(writer, cycle, match.getGroup(1), match.getGroup(2) );
			message = message.substring( message.indexOf("{/@}") + 4);
		}
		
		writer.print(message);
		
	}
	
	private void writeLink(IMarkupWriter w, IRequestCycle cycle, String 
page, String linkText) {
		
		ILink link = getPageService().getLink(cycle, false, page);
		
		w.begin("a");
		w.attribute("href", link.getURL());
		renderInformalParameters(w,cycle);
		
		w.print(linkText);
		
		w.end();
	}
}

==================================================================================

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE component-specification PUBLIC
   "-//Apache Software Foundation//Tapestry Specification 4.0//EN"
   "http://jakarta.apache.org/tapestry/dtd/Tapestry_4_0.dtd">
<component-specification allow-body="no" 
class="net.tutim.tapestry.components.nestedlink.NestedPageLink"
	 allow-informal-parameters="yes">
	
	<parameter name="message" required="yes"/>
	
	<inject property="pageService" object="engine-service:page"/>

</component-specification>


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: creating a link around a part of a sentance

Posted by Ron Piterman <rp...@gmx.net>.
I am already there.
It will look like:

"I have read the {@lib:conditions} conditions {/@} and the 
{@lib:privacy} privacy statement {/@} and agree with it."

and generate page links on the right places...

ציטוט Adam Greene:
> The only other solution I can think of is to indicate that a certain 
> character marks the beginning and end of the part to be wrapped with a 
> link. example:   Click *Here*
> 
> Then write a component that takes three parameters, the first being the 
> message, the second being the page to go to, and the third being the 
> delimiter and then within the component, locate the delimiters, split 
> the string and wrap the text.  It will take a bit of acrobatics, but 
> would be doable.
> 
> ----- Original Message ----- From: "Ron Piterman" <rp...@gmx.net>
> To: <ta...@jakarta.apache.org>
> Sent: Tuesday, August 23, 2005 1:03 PM
> Subject: Re: creating a link around a part of a sentance
> 
> 
>> Yes, thats a possibility, but I find splitting the resource not so 
>> nice: in some languages this will need 3 resources.
>> Translation is also not straight forward then.
>>
>> I guess I will need to hack something.. :(
>>
>>
>> ציטוט Geoff Longman:
>>
>>> If you're willing to give up the <span key> and split the resource
>>> entry you could do this.
>>>
>>> <span jwcid="@NestedMessage" resource="DID_YOU">
>>>    <span jwcid="@PageLink" page="FindPassword"><span
>>> key="FORGET_PASSWORD"/></span>
>>> <span>
>>>
>>> Where DID_YOU_FORGET=Did you {0}?
>>> FORGET_PASSWORD=forget your password
>>>
>>> NestedMessage would be a custom component that renders it's body into
>>> newly created (and not nested I think) writer, then it calls
>>> format("DID_YOU", contents of the writer).
>>>
>>> I think this would work although I've never tried anything like it.
>>>
>>> Geoff
>>>
>>>
>>> On 8/23/05, Ron Piterman <rp...@gmx.net> wrote:
>>>
>>>> Hi,
>>>> Maybe someone has a cool component or a solution to the following 
>>>> problem:
>>>>
>>>> Say there is a resource: "Did you forget your password?"
>>>> And I wish to add a link only on the words "forgot your password"
>>>>
>>>> Or: "I read and agree with the *Conditions*" , where "conditions" is 
>>>> a link.
>>>>
>>>> Doing this on simple text is no problem, but on a resource? did anyone
>>>> face this problem (successfully...) ?
>>>>
>>>> Cheers,
>>>> Ron
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>>>> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>>>>
>>>>
>>>
>>>
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>>
>>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: creating a link around a part of a sentance

Posted by Adam Greene <ag...@iq-2000.com>.
The only other solution I can think of is to indicate that a certain 
character marks the beginning and end of the part to be wrapped with a link. 
example:   Click *Here*

Then write a component that takes three parameters, the first being the 
message, the second being the page to go to, and the third being the 
delimiter and then within the component, locate the delimiters, split the 
string and wrap the text.  It will take a bit of acrobatics, but would be 
doable.

----- Original Message ----- 
From: "Ron Piterman" <rp...@gmx.net>
To: <ta...@jakarta.apache.org>
Sent: Tuesday, August 23, 2005 1:03 PM
Subject: Re: creating a link around a part of a sentance


> Yes, thats a possibility, but I find splitting the resource not so nice: 
> in some languages this will need 3 resources.
> Translation is also not straight forward then.
>
> I guess I will need to hack something.. :(
>
>
> ציטוט Geoff Longman:
>> If you're willing to give up the <span key> and split the resource
>> entry you could do this.
>>
>> <span jwcid="@NestedMessage" resource="DID_YOU">
>>    <span jwcid="@PageLink" page="FindPassword"><span
>> key="FORGET_PASSWORD"/></span>
>> <span>
>>
>> Where DID_YOU_FORGET=Did you {0}?
>> FORGET_PASSWORD=forget your password
>>
>> NestedMessage would be a custom component that renders it's body into
>> newly created (and not nested I think) writer, then it calls
>> format("DID_YOU", contents of the writer).
>>
>> I think this would work although I've never tried anything like it.
>>
>> Geoff
>>
>>
>> On 8/23/05, Ron Piterman <rp...@gmx.net> wrote:
>>
>>>Hi,
>>>Maybe someone has a cool component or a solution to the following 
>>>problem:
>>>
>>>Say there is a resource: "Did you forget your password?"
>>>And I wish to add a link only on the words "forgot your password"
>>>
>>>Or: "I read and agree with the *Conditions*" , where "conditions" is a 
>>>link.
>>>
>>>Doing this on simple text is no problem, but on a resource? did anyone
>>>face this problem (successfully...) ?
>>>
>>>Cheers,
>>>Ron
>>>
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>>>For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>>>
>>>
>>
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: creating a link around a part of a sentance

Posted by Ron Piterman <rp...@gmx.net>.
Yes, thats a possibility, but I find splitting the resource not so nice: 
in some languages this will need 3 resources.
Translation is also not straight forward then.

I guess I will need to hack something.. :(


ציטוט Geoff Longman:
> If you're willing to give up the <span key> and split the resource
> entry you could do this.
> 
> <span jwcid="@NestedMessage" resource="DID_YOU">
>    <span jwcid="@PageLink" page="FindPassword"><span
> key="FORGET_PASSWORD"/></span>
> <span>
> 
> Where 
> DID_YOU_FORGET=Did you {0}?
> FORGET_PASSWORD=forget your password
> 
> NestedMessage would be a custom component that renders it's body into
> newly created (and not nested I think) writer, then it calls
> format("DID_YOU", contents of the writer).
> 
> I think this would work although I've never tried anything like it.
> 
> Geoff
> 
> 
> On 8/23/05, Ron Piterman <rp...@gmx.net> wrote:
> 
>>Hi,
>>Maybe someone has a cool component or a solution to the following problem:
>>
>>Say there is a resource: "Did you forget your password?"
>>And I wish to add a link only on the words "forgot your password"
>>
>>Or: "I read and agree with the *Conditions*" , where "conditions" is a link.
>>
>>Doing this on simple text is no problem, but on a resource? did anyone
>>face this problem (successfully...) ?
>>
>>Cheers,
>>Ron
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>>
>>
> 
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: creating a link around a part of a sentance

Posted by Geoff Longman <gl...@gmail.com>.
If you're willing to give up the <span key> and split the resource
entry you could do this.

<span jwcid="@NestedMessage" resource="DID_YOU">
   <span jwcid="@PageLink" page="FindPassword"><span
key="FORGET_PASSWORD"/></span>
<span>

Where 
DID_YOU_FORGET=Did you {0}?
FORGET_PASSWORD=forget your password

NestedMessage would be a custom component that renders it's body into
newly created (and not nested I think) writer, then it calls
format("DID_YOU", contents of the writer).

I think this would work although I've never tried anything like it.

Geoff


On 8/23/05, Ron Piterman <rp...@gmx.net> wrote:
> Hi,
> Maybe someone has a cool component or a solution to the following problem:
> 
> Say there is a resource: "Did you forget your password?"
> And I wish to add a link only on the words "forgot your password"
> 
> Or: "I read and agree with the *Conditions*" , where "conditions" is a link.
> 
> Doing this on simple text is no problem, but on a resource? did anyone
> face this problem (successfully...) ?
> 
> Cheers,
> Ron
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> 
> 


-- 
The Spindle guy.           http://spindle.sf.net
Get help with Spindle:   
http://lists.sourceforge.net/mailman/listinfo/spindle-user
Announcement Feed:    
http://www.jroller.com/rss/glongman?catname=/Announcements
Feature Updates:            http://spindle.sf.net/updates

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org